ambevar-dotfiles/.scripts/ubuilder

102 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
## TODO: add support for DLAGENT.
## TODO: add support for curl.
_printhelp()
{
cat<<EOF
Usage: ${1##*/} [OPTIONS] PKGBUILDs
Convert an Arch Linux PKGBUILD to a universal standalone bash script. (The
2013-09-10 20:00:31 +02:00
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.
2013-07-10 00:21:41 +02:00
Differences with makepkg
2013-09-10 20:00:31 +02:00
* Parameters may differ.
* The progress output may differ.
* Some features are not yet implemented (e.g. explicit source filename)
2013-08-26 14:09:56 +02:00
Options:
-h: Show this help.
-f: Overwrite existing builder.
-l: Install in usr/local/ instead of usr/.
2013-08-26 14:09:56 +02:00
EOF
}
OPT_LOCAL=false
OPT_OVERWRITE=false
while getopts ":flh" opt; do
case $opt in
h)
_printhelp "$0"
exit 1 ;;
l)
OPT_OVERWRITE=true ;;
l)
OPT_LOCAL=true ;;
?)
_printhelp "$0"
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
_printhelp "$0"
exit 1
fi
if ! command -v realpath >/dev/null; then
echo "You need 'realpath'"
exit
fi
for i ; do
if [ ! -f "$i" ]; then
echo "$i must be a PKGBUILD file."
continue
fi
OUTPATH="$(realpath "$i")"
OUTPATH="${OUTPATH%/*}"
PKGNAME="$(awk -F= '/^pkgname/{print $2}' "$i")"
UBUILD="${OUTPATH}/$PKGNAME.sh"
if [ -f "$UBUILD" ] && ! $OPT_OVERWRITE; then
echo "$UBUILD already exists."
continue
fi
cat<<"EOF" > "$UBUILD"
#!/bin/bash
if ! command -v realpath >/dev/null; then
echo "You need 'realpath'."
exit
fi
if ! command -v wget >/dev/null; then
echo "You need 'wget'."
exit
fi
################################################################################
EOF
if $OPT_LOCAL; then
sed -e 's|/usr|/usr/local|g' "$i" >> "$UBUILD"
else
cat "$i" >> "$UBUILD"
fi
cat "${0%/*}/.${0##*/}.in" >> "$UBUILD"
chmod +x "$UBUILD"
done