ambevar-dotfiles/.scripts/abs-wrapper

228 lines
4.6 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2013-06-25 19:10:52 +02:00
## User config
UPSTREAM_SOURCE="srcdir"
2013-06-25 19:10:52 +02:00
## End of user config
2015-01-09 19:21:40 +01:00
usage () {
cat <<EOF
Usage: ${1##*/} [OPTIONS] PACKAGES
WARNING: development version. Not reliable for AUR-dependency resolution.
2013-06-25 20:07:22 +02:00
This script can perform multiple operations:
1. Fetch PKGBUILD.
2. Fetch source code.
3. Build package.
4. Installing package.
5. Cleaning folder from build data.
Default operation is to fetch PKGBUILD for provided packages.
2013-06-25 19:10:52 +02:00
2013-06-25 20:07:22 +02:00
Operations or hierarchically dependant and check for existing data. E.g. if a
PKGBUILD is already there and you want to install the package, then it will
fetch source code first, then build and finally install.
2013-06-25 20:07:22 +02:00
It will fetch the PKGBUILD from the ABS-tree or yaourt, depending on what is
available.
2013-06-25 19:10:52 +02:00
Options:
2013-06-25 20:07:22 +02:00
-b: Build.
-c: Clean source folders from temp file (keep upstream source and package folder).
-C: Clean source folders from archives.
2013-06-25 20:07:22 +02:00
-f: Force operation (overwrite, rebuild, reinstall).
-h: Display this help.
2013-06-25 20:07:22 +02:00
-i: Install package.
-s: Fetch source code.
Example:
2013-06-25 20:07:22 +02:00
${1##*/} -icf \$(pacman -Qmq)
2013-06-25 20:34:56 +02:00
For all foreign installed packages, force fetch PKGBUILD, fetch source code
if not available, build if not already build, force installing and clean
build folder.
2013-06-25 20:34:56 +02:00
${1##*/} -sbicf nawk ncdu
For all foreign installed packages, fetch PKGBUILD and source code if not
available, force build if not already build, force installing and clean
build folder.
2013-06-25 20:34:56 +02:00
EOF
}
MAKEPKT_OPT=""
2013-06-25 20:07:22 +02:00
PACMAN_OPT="--needed"
2013-06-25 20:34:56 +02:00
OPT_BUILD=false
OPT_CLEAN=false
OPT_MRPROPER=false
2013-06-25 20:34:56 +02:00
OPT_FORCE=false
OPT_INSTALL=false
OPT_SOURCE=false
while getopts ":bcCfhis" opt; do
case $opt in
b)
OPT_BUILD=true ;;
c)
MAKEPKG_OPT="$MAKEPKG_OPT -c"
OPT_CLEAN=true ;;
C)
OPT_MRPROPER=true ;;
f)
MAKEPKG_OPT="$MAKEPKG_OPT -f"
PACMAN_OPT=""
OPT_FORCE=true ;;
h)
_usage "$0"
exit 1 ;;
i)
OPT_INSTALL=true ;;
s)
OPT_SOURCE=true ;;
\?)
echo 'HO'
_usage "$0"
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
usage "$0"
exit 1
fi
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
echo "Missing argument."
_usage "$0"
exit 1
fi
if ! command -v makepkg >/dev/null; then
echo "You need makepkg to run this script."
exit 1
fi
2013-06-25 20:34:56 +02:00
HAS_ABS=false
HAS_YAOURT=false
command -v abs >/dev/null && HAS_ABS=true
command -v yaourt >/dev/null && HAS_YAOURT=true
2013-06-25 20:34:56 +02:00
if ! $HAS_ABS && ! $HAS_YAOURT; then
echo "Please install either an ABS-tree or yaourt."
exit 1
fi
2013-06-25 20:34:56 +02:00
if $HAS_ABS && [ -f "/etc/abs.conf" ]; then
. "/etc/abs.conf"
[ "$ABSROOT" = "" ] && ABSROOT="/var/abs/"
2013-06-25 19:10:52 +02:00
fi
################################################################################
abs_pkgbuild () {
pacman -Si $1 >/dev/null 2>&1
if [ $? -eq 0 ] && $HAS_ABS && [ -d "$ABSROOT" ]; then
cp -r /var/abs/*/$1 .
else
yaourt -G "$1" --noconfirm
fi
2013-06-25 20:07:22 +02:00
}
2013-06-25 19:10:52 +02:00
abs_source () {
(cd "$1" && \
mkdir -p "$UPSTREAM_SOURCE" && \
SRCDEST="$UPSTREAM_SOURCE" makepkg -o)
}
## TODO: unused function. Add 'build all deps from source' parameter?
abs_builddeps () {
DEPLIST=$(awk -F"'" '/^(make)?depends *= *\(/,/\)/ {for (n=2 ; n<NF; n++) res=res $n " "} END {gsub(/ +/, " ", res); print res}' PKGBUILD)
(cd .. && abs-wrapper $DEPLIST)
}
abs_buildmissing () {
DEPLIST="$(makepkg -s 2>&1 | awk -F: '/target not found/ {print $3}')"
cd ..
while IFS= read -r p; do
abs_pkgbuild $p
abs_build $p
abs_install $p
done <<EOF
${DEPLIST}
EOF
cd $1
}
abs_build () {
(cd "$1" && \
mkdir -p "$UPSTREAM_SOURCE" && \
(makepkg -s || \
if [ $? -ne 0 ]; then abs_buildmissing $1; fi ) && \
SRCDEST="$UPSTREAM_SOURCE" makepkg -r $MAKEPKG_OPT --nocheck --noconfirm)
2013-06-25 20:07:22 +02:00
}
abs_clean () {
(cd "$1" && \
echo "Removing src/ and pkg/ folders." && \
rm -rf "src" "pkg")
2013-06-25 20:07:22 +02:00
}
abs_mrproper () {
(cd "$1" && \
echo "Removing archives." && \
rm -v *.tar.gz *.tar.xz *.tar.bz *.tar.bz2 *.tgz *.txz *.tbz *.tbz2 2>/dev/null)
}
abs_install () {
sudo sh -c '
(cd "$0" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz)
for i; do
(cd "$i" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz)
done
' "$@"
}
for i ; do
echo "==> Processing $i."
## Fetch PKGBUILD.
if [ ! -f "$i/PKGBUILD" ] || $OPT_FORCE; then
abs_pkgbuild "$i"
fi
## Skip because $i does not exist.
[ ! -d "$i" ] && continue
## Fetch source code.
if $OPT_SOURCE; then
abs_source "$i"
fi
## Build.
if $OPT_BUILD || ($OPT_INSTALL && [ ! -f $i/*.pkg.tar.xz ]); then
abs_build "$i"
fi
## Clean build folder.
if $OPT_CLEAN; then
abs_clean "$i"
fi
## Remove archives.
if $OPT_MRPROPER; then
abs_mrproper "$i"
fi
done
2013-06-25 20:07:22 +02:00
## Install packages. We put the install part outside the loop so that we prompt
## for password one time only.
2013-06-25 20:34:56 +02:00
if $OPT_INSTALL; then
abs_install "$@"
fi