Skip to content

Instantly share code, notes, and snippets.

@AladW
Created April 30, 2016 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AladW/f25e024ce37024028b90c303ee6e7ebc to your computer and use it in GitHub Desktop.
Save AladW/f25e024ce37024028b90c303ee6e7ebc to your computer and use it in GitHub Desktop.
#!/bin/bash
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -e -o pipefail
argv0=vcsprepare
tmp=$(mktemp -d)
readonly argv0 tmp
# /!\ EXPERIMENTAL
findsrc() {
find "$@" -maxdepth 1 -type f -name .SRCINFO -print0
}
gensrc() {
xargs -0i awk '/^pkgbase/ {b = $3} /^\tsource/ {print b, $3}' {}
}
findvcs() {
declare -A vcs match
while IFS=':' read -r proto _ client; do
vcs[$proto]=$client
done < <(printf '%s\n' "${VCSCLIENTS[@]}")
while read -r pkg uri; do
proto=$(get_protocol "$uri")
proto=${proto/[+:]*}
if [[ ${vcs[$proto]} ]]; then
match[$pkg]=${vcs[$proto]}
fi
done < <(findsrc "$@" | gensrc)
for i in "${!match[@]}"; do
printf '%s %s\n' "$i" "${match[$i]}"
done
}
prepare() {
makepkg -do --noprepare >/dev/null
mksrcinfo
awk '/^\tpkgver/ {v = $3} /^\tpkgrel/ {r = $3} /^\tepoch/ {e = $3":"}
/^pkgname/ {n = $3; printf "%s %s%s-%s\n", n, e, v, r}
' .SRCINFO
}
trap 'rm -rf "$tmp"' EXIT
source /etc/makepkg.conf
source /usr/share/makepkg/util.sh
[[ -t 2 ]] && colorize
if ((!$#)); then
plain "usage: vcsprepare target [target ...]"
exit 1
fi
# XXX: Validate sudo for loop below
sudo -v
# 1. Retrieve "package client" strings from .SRCINFO
# 2. Install client if not available
# 3. Update VCS sources
# 4. Update .SRCINFO
# 5. Print "pkgname fullver"
while read -r pkg client; do
if ! pacman -T "$client" >/dev/null; then
sudo -n pacman -S --asdeps --noconfirm "$client"
fi
# XXX: Only works if targets are in PWD
# XXX: Continues on failure
( cd "$pkg"
prepare
) &
done < <(findvcs "$@") > "$tmp"/vcs_all
wait
grep -Fxvf <(aursift -U < "$tmp"/vcs_all) <(awk '{print $1}' "$tmp"/vcs_all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment