ambevar-dotfiles/.scripts/abs-wrapper

213 lines
4.7 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)
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.
${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.
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_FORCE=false
OPT_INSTALL=false
OPT_SOURCE=false
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)
2013-06-25 20:34:56 +02:00
OPT_BUILD=true ;;
c)
2013-06-25 19:10:52 +02:00
MAKEPKG_OPT="$MAKEPKG_OPT -c"
2013-06-25 20:34:56 +02:00
OPT_CLEAN=true ;;
f)
MAKEPKG_OPT="$MAKEPKG_OPT -f"
2013-06-25 20:07:22 +02:00
PACMAN_OPT=""
2013-06-25 20:34:56 +02:00
OPT_FORCE=true ;;
h)
_printhelp "$0"
exit 1 ;;
i)
2013-06-25 20:34:56 +02:00
OPT_INSTALL=true ;;
2013-06-25 20:07:22 +02:00
s)
2013-06-25 20:34:56 +02:00
OPT_SOURCE=true ;;
?)
_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
2013-06-25 20:34:56 +02:00
HAS_ABS=false
HAS_YAOURT=false
[ -n "$(command -v abs)" ] && HAS_ABS=true
[ -n "$(command -v yaourt)" ] && 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
2013-06-25 19:10:52 +02:00
. "/etc/abs.conf"
[ "$ABSROOT" = "" ] && ABSROOT="/var/abs/"
fi
################################################################################
2013-06-25 20:07:22 +02:00
abs_pkgbuild ()
{
pacman -Si $1 >/dev/null 2>&1
2013-06-25 20:34:56 +02:00
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
2013-06-25 20:07:22 +02:00
abs_source ()
{
(cd "$1" && \
2013-06-25 19:10:52 +02:00
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 read -r p; do
abs_pkgbuild $p
abs_build $p
abs_install $p
done <<EOF
${DEPLIST}
EOF
cd $1
}
2013-06-25 20:07:22 +02:00
abs_build ()
{
(cd "$1" && \
2013-06-25 20:07:22 +02:00
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" && \
2013-06-25 20:07:22 +02:00
echo "Removing src/ and pkg/ folders." && \
rm -rf "src" "pkg")
}
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
2013-06-25 20:07:22 +02:00
## Fetch PKGBUILD.
2013-06-25 20:34:56 +02:00
if [ ! -f "$i/PKGBUILD" ] || $OPT_FORCE; then
abs_pkgbuild "$i"
fi
2013-06-25 20:07:22 +02:00
## Skip because $i does not exist.
[ ! -d "$i" ] && continue
## Fetch source code.
2013-06-25 20:34:56 +02:00
if $OPT_SOURCE; then
2013-06-25 20:07:22 +02:00
abs_source "$i"
fi
## Build.
2013-06-25 20:34:56 +02:00
if $OPT_BUILD || ($OPT_INSTALL && [ ! -f $i/*.pkg.tar.xz ]); then
2013-06-25 20:07:22 +02:00
abs_build "$i"
fi
2013-06-25 20:07:22 +02:00
## Clean build folder.
2013-06-25 20:34:56 +02:00
if $OPT_CLEAN; 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.
2013-06-25 20:34:56 +02:00
if $OPT_INSTALL; then
abs_install "$@"
fi