ambevar-dotfiles/.scripts/ubuilder

61 lines
1.3 KiB
Bash
Executable File

#!/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
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
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.
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"
cat "$1" | sed -e 's|--prefix=/usr|--prefix=/usr/local|g' \
-e 's|PREFIX=/usr|PREFIX=/usr/local|g' >> "$UBUILD"
cat "$(realpath "$0").in" >> "$UBUILD"
chmod +x "$UBUILD"