~vilhalmer/cod

7b40966f8a4b74c30f6f2077897855d73a8c0646 — Bill Doyle 3 years ago 8c35946
Seems to work!
2 files changed, 73 insertions(+), 0 deletions(-)

A codinstall
A codstub
A codinstall => codinstall +41 -0
@@ 0,0 1,41 @@
#!/bin/sh -e
# cod package installer

if [ "$1" = "-d" ]; then
    shift
    set -x
fi

if [ $# -eq 0 ]; then
    echo "nothing to do"
    exit 0
fi

CODPATH="${CODPATH:-/opt/cod}"
stub="$(which codstub)"

asp update "$@" || echo "Couldn't update, using cache"  # Sometimes svntogit is just broken.
for package in "$@"; do
    package_path="$CODPATH/packages/$package"
    if [ -d "$package_path" ]; then
        echo "$package already installed"
        continue
    fi

    repo_package="$(pacman -Ss "^$package$" | head -n1 | cut -f1 -d' ')"

    echo "Updating '$package' sources…"
    mkdir -p "$CODPATH/packages"
    cd "$CODPATH/packages"
    asp export "$repo_package"

    pushd "$package_path" > /dev/null
    makepkg --nobuild --syncdeps SRCPKGDEST=src
    ln -s "$stub" stub
    popd > /dev/null

    mkdir -p "$CODPATH/bin"
    pacman -Fql "$package" | grep -E 'usr/bin/.+$' | while read -r binary; do
        ln -vs "$CODPATH/packages/$package/stub" "$CODPATH/bin/$(basename "$binary")"
    done
done

A codstub => codstub +32 -0
@@ 0,0 1,32 @@
#!/bin/sh -e
# cod launcher stub

if [ -n "$CODDEBUG" ]; then
    set -x
fi

export CODPATH="${CODPATH:-/opt/cod}"
target="$(basename "$0")"
if [ "$target" = "codstub" ]; then
    echo "codstub is not intended to be run directly"
    exit 1
fi
real_package="$(dirname "$(readlink "$0")")" 2> /dev/null

if [ ! -d "$real_package" ]; then
    echo "Package $real_package is missing! Try reinstalling it with \`codinstall\`"
    exit 1
fi

pushd "$real_package" > /dev/null
if [ ! -d src ]; then
    echo "No source found, fetching…"
    makepkg --nobuild --syncdeps SRCPKGDEST=src
fi

(source ./PKGBUILD && cd src && build > ../build.stdout 2> ../build.stderr)

prog="$(find "$(pwd)/src" -executable -name "$target")"
popd > /dev/null

exec "$prog" "$@"