ambevar-dotfiles/.scripts/abs-wrapper

176 lines
3.8 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
_printhelp ()
{
cat <<EOF
Usage: ${1##*/} [OPTIONS] PACKAGES
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 built package).
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)
Force fetching PKGBUILD and source code, force building, install and clean build folder for all foreign installed packages.
EOF
}
MAKEPKT_OPT=""
2013-06-25 20:07:22 +02:00
PACMAN_OPT="--needed"
2013-06-25 20:07:22 +02:00
OPT_BUILD=0
OPT_CLEAN=0
OPT_FORCE=0
OPT_INSTALL=0
2013-06-25 20:07:22 +02:00
OPT_SOURCE=0
2013-06-25 20:07:22 +02:00
while getopts ":bcfhis" opt; do
case $opt in
2013-06-25 20:07:22 +02:00
b)
OPT_BUILD=1 ;;
c)
2013-06-25 19:10:52 +02:00
MAKEPKG_OPT="$MAKEPKG_OPT -c"
OPT_CLEAN=1 ;;
f)
MAKEPKG_OPT="$MAKEPKG_OPT -f"
2013-06-25 20:07:22 +02:00
PACMAN_OPT=""
OPT_FORCE=1;;
h)
_printhelp "$0"
exit 1 ;;
i)
OPT_INSTALL=1 ;;
2013-06-25 20:07:22 +02:00
s)
OPT_SOURCE=1 ;;
?)
_printhelp "$0"
exit 1 ;;
:)
echo "Missing argument."
_printhelp "$0"
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
echo "Missing argument."
_printhelp "$0"
exit 1
fi
if [ -z "$(command -v makepkg)" ]; then
echo "You need makepkg to run this script."
exit 1
fi
HAS_ABS=0
HAS_YAOURT=0
[ -n "$(command -v abs)" ] && HAS_ABS=1
[ -n "$(command -v yaourt)" ] && HAS_YAOURT=1
if [ $HAS_ABS -eq 0 ] && [ $HAS_YAOURT -eq 0 ]; then
echo "Please install either an ABS-tree or yaourt."
exit 1
fi
2013-06-25 19:10:52 +02:00
if [ $HAS_ABS -eq 1 ] && [ -f "/etc/abs.conf" ]; then
. "/etc/abs.conf"
[ "$ABSROOT" = "" ] && ABSROOT="/var/abs/"
fi
################################################################################
2013-06-25 20:07:22 +02:00
abs_pkgbuild ()
{
pacman -Si $i >/dev/null 2>&1
2013-06-25 19:10:52 +02:00
if [ $? -eq 0 ] && [ $HAS_ABS -eq 1 ] && [ -d "$ABSROOT" ]; then
cp -r /var/abs/*/$i .
else
2013-06-25 19:10:52 +02:00
yaourt -G "$i" --noconfirm
fi
2013-06-25 19:10:52 +02:00
2013-06-25 20:07:22 +02:00
}
2013-06-25 19:10:52 +02:00
2013-06-25 20:07:22 +02:00
abs_source ()
{
2013-06-25 19:10:52 +02:00
(cd "$i" && \
mkdir -p "$UPSTREAM_SOURCE" && \
SRCDEST="$UPSTREAM_SOURCE" makepkg -o)
}
2013-06-25 20:07:22 +02:00
abs_build ()
{
(cd "$i" && \
mkdir -p "$UPSTREAM_SOURCE" && \
SRCDEST="$UPSTREAM_SOURCE" makepkg -rs $MAKEPKG_OPT --nocheck --noconfirm)
}
abs_clean ()
{
(cd "$i" && \
echo "Removing src/ and pkg/ folders." && \
rm -rf "src" "pkg")
}
for i ; do
2013-06-25 20:07:22 +02:00
## Fetch PKGBUILD.
if [ ! -f "$i/PKGBUILD" ] || [ $OPT_FORCE -eq 1 ]; then
2013-06-25 20:07:22 +02:00
abs_fetch "$i"
fi
2013-06-25 20:07:22 +02:00
## Skip because $i does not exist.
[ ! -d "$i" ] && continue
## Fetch source code.
if [ $OPT_SOURCE -eq 1 ]; then
abs_source "$i"
fi
## Build.
if [ $OPT_BUILD -eq 1 ]; then
abs_build "$i"
fi
2013-06-25 20:07:22 +02:00
## Clean build folder.
2013-06-25 19:10:52 +02:00
if [ $OPT_CLEAN -eq 1 ]; then
2013-06-25 20:07:22 +02:00
abs_clean "$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.
if [ $OPT_INSTALL -eq 1 ]; then
sudo sh -c '
2013-06-25 20:07:22 +02:00
(cd "$0" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz)
2013-06-25 19:10:52 +02:00
for i; do
2013-06-25 20:07:22 +02:00
(cd "$i" && pacman '$PACMAN_OPT' --noconfirm -U *.pkg.tar.xz)
done
' "$@"
fi