ambevar-dotfiles/.scripts/ubuilder

67 lines
1.4 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, they strongly rely
on arrays.) 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 may differ.
* The progress output may differ.
* Some features are not implemented (e.g. explicit source filename)
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"
if [ "$1" = "-l" ]; then
cat "$2" | sed -e 's|/usr|/usr/local|g' >> "$UBUILD"
else
cat "$1" >> "$UBUILD"
fi
cat "${0%/*}/.${0##*/}.in" >> "$UBUILD"
chmod +x "$UBUILD"