ambevar-dotfiles/.scripts/ubuilder

67 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
if [ $# -ne 1 ] || [ "$1" = "-h" ]; then
cat<<EOF
Usage: ${0##*/} PKGBUILD
Convert an Arch Linux PKGBUILD to a universal standalone bash script. (The
2013-07-10 00:21:41 +02:00
infamous 'bash' is assumed because PKGBUILD are bash scripts.) The resulting
script tries to resemble makepkg build process where it makes sense. There is no
2013-07-10 00:21:41 +02:00
dependency resolution because we cannot guess the package names of the target
system.
Differences with makepkg
* Parameters are not the same.
* The output may differ.
* The fakeroot environment lies directly in \$pkgdir, not in \$pkgdir/\$pkgname.
2013-08-26 14:09:56 +02:00
Options:
-l: install in usr/local/ instead of usr/
EOF
exit
fi
if [ -z "$(command -v realpath)" ]; then
echo "You need 'realpath'"
exit
fi
if [ ! -f "$1" ]; then
echo "$1 must be a PKGBUILD file."
exit
fi
OUTPATH="$(realpath "$1")"
OUTPATH="${OUTPATH%/*}"
UBUILD="${OUTPATH}/UBUILD.sh"
if [ -f "$UBUILD" ]; then
echo "$UBUILD already exists."
exit
fi
echo '#!/bin/bash
if [ -z "$(command -v realpath)" ];then
echo "You need 'realpath'."
exit
fi
if [ -z "$(command -v wget)" ];then
echo "You need 'wget'."
exit
fi
################################################################################
' > "$UBUILD"
2013-08-26 14:09:56 +02:00
if [ "$1" = "-l" ]; then
cat "$2" | sed -e 's|/usr|/usr/local|g' >> "$UBUILD"
else
cat "$1" >> "$UBUILD"
fi
cat "${0%/*}/.${0##*/}.in" >> "$UBUILD"
2013-07-10 00:21:41 +02:00
chmod +x "$UBUILD"