2013-07-08 14:14:41 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
## TODO: add support for DLAGENT.
|
|
|
|
## TODO: add support for curl.
|
|
|
|
|
|
|
|
_printhelp()
|
|
|
|
{
|
2013-07-08 14:14:41 +02:00
|
|
|
cat<<EOF
|
2013-10-23 11:42:50 +02:00
|
|
|
Usage: ${1##*/} [OPTIONS] PKGBUILDs
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-07-10 18:31:13 +02:00
|
|
|
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.
|
2013-10-23 11:42:50 +02:00
|
|
|
* Some features are not yet implemented (e.g. explicit source filename)
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-08-26 14:09:56 +02:00
|
|
|
Options:
|
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
-h: Show this help.
|
|
|
|
-f: Overwrite existing builder.
|
|
|
|
-l: Install in usr/local/ instead of usr/.
|
2013-08-26 14:09:56 +02:00
|
|
|
|
2013-07-08 14:14:41 +02:00
|
|
|
EOF
|
2013-10-23 11:42:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ;;
|
|
|
|
:)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1
|
2013-07-08 14:14:41 +02:00
|
|
|
fi
|
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
|
2013-10-27 19:50:23 +01:00
|
|
|
if ! command -v realpath >/dev/null; then
|
2013-07-08 14:14:41 +02:00
|
|
|
echo "You need 'realpath'"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
for i ; do
|
|
|
|
if [ ! -f "$i" ]; then
|
|
|
|
echo "$i must be a PKGBUILD file."
|
|
|
|
continue
|
|
|
|
fi
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
OUTPATH="$(realpath "$i")"
|
|
|
|
OUTPATH="${OUTPATH%/*}"
|
|
|
|
PKGNAME="$(awk -F= '/^pkgname/{print $2}' "$i")"
|
|
|
|
UBUILD="${OUTPATH}/$PKGNAME.sh"
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
if [ -f "$UBUILD" ] && ! $OPT_OVERWRITE; then
|
|
|
|
echo "$UBUILD already exists."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat<<"EOF" > "$UBUILD"
|
|
|
|
#!/bin/bash
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-10-27 19:50:23 +01:00
|
|
|
if ! command -v realpath >/dev/null; then
|
2013-07-08 14:14:41 +02:00
|
|
|
echo "You need 'realpath'."
|
|
|
|
exit
|
|
|
|
fi
|
2013-10-27 19:50:23 +01:00
|
|
|
if ! command -v wget >/dev/null; then
|
2013-07-08 14:14:41 +02:00
|
|
|
echo "You need 'wget'."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
################################################################################
|
2013-10-23 11:42:50 +02:00
|
|
|
EOF
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
if $OPT_LOCAL; then
|
|
|
|
sed -e 's|/usr|/usr/local|g' "$i" >> "$UBUILD"
|
|
|
|
else
|
|
|
|
cat "$i" >> "$UBUILD"
|
|
|
|
fi
|
2013-07-08 14:14:41 +02:00
|
|
|
|
2013-10-23 11:42:50 +02:00
|
|
|
cat "${0%/*}/.${0##*/}.in" >> "$UBUILD"
|
|
|
|
chmod +x "$UBUILD"
|
|
|
|
done
|