Last active
August 2, 2023 14:12
-
-
Save sfan5/c462d94d808954c2ed346876f6125696 to your computer and use it in GitHub Desktop.
Reimplements functionality of makepkg to a small degree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
finalpath=/var/tmp/final | |
msg () { | |
echo ":: $1" | |
} | |
noextract= | |
bfile=PKGBUILD | |
while [[ "$1" == "-"* ]]; do | |
case "$1" in | |
-e) noextract=1;; | |
-p) bfile=$2; shift;; | |
*) echo "don't support argument $1"; exit 1;; | |
esac | |
shift | |
done | |
if [ ! -f "$bfile" ]; then | |
if [ -z "$2" ]; then | |
echo "file not found (try pkgname + repo as args for download mode)" | |
exit 1 | |
fi | |
if [ "$2" == "aur" ]; then | |
msg "Downloading PKGBUILD for $1 from AUR" | |
git clone --depth=1 "https://aur.archlinux.org/$1.git" "$1" | |
elif [[ "$2" =~ ^(core|extra|multilib)$ ]]; then | |
msg "Downloading PKGBUILD for $1 (repo: $2)" | |
git clone --depth=1 "https://gitlab.archlinux.org/archlinux/packaging/packages/$1.git/" "$1" | |
else | |
exit 1 | |
fi | |
exit 0 | |
fi | |
source "$bfile" | |
msg "Fetching sources" | |
for src in ${source[@]}; do | |
[[ "$src" == *".sig" ]] && continue # meh | |
filename= | |
if [[ "$src" == *"::"* ]]; then # filename provided | |
filename="${src%%::*}" | |
src="${src#*::}" | |
fi | |
if [[ "$src" == "http://"* || "$src" == "https://"* || "$src" == "ftp://"* ]]; then | |
[ -z "$filename" ] && filename="${src##*/}" | |
[ ! -s "$filename" ] && wget "$src" -O "$filename" | |
elif [[ "$src" == "git://"* || "$src" == "git+"* ]]; then | |
checkout= | |
if [ "${src#*#commit=}" != "$src" ]; then | |
checkout="${src#*#commit=}" | |
elif [ "${src#*#branch=}" != "$src" ]; then | |
checkout="${src#*#branch=}" | |
fi | |
giturl="${src%%#*}" | |
giturl="${giturl#git+}" | |
if [ -z "$filename" ]; then | |
filename="${giturl##*/}" | |
filename="${filename%.git}" | |
fi | |
[ ! -d "$filename" ] && git clone "$giturl" "$filename" | |
[[ -z "$noextract" && -n "$checkout" ]] && { cd "$filename"; git checkout "$checkout"; } | |
elif [ -f "$src" ]; then | |
[ -z "$filename" ] && filename="$src" | |
[[ "$filename" != "$src" ]] && mv "$src" "$filename" | |
else | |
echo "Dunno how to download '$src', exiting" | |
exit 1 | |
fi | |
if [[ -z "$noextract" && "$filename" == *".tar."* ]]; then | |
tar -axf "$filename" | |
fi | |
done | |
srcdir=$PWD | |
mkdir -p pkg | |
pkgdir="$PWD/pkg" | |
if [[ -z "$noextract" && -n "$(type -t prepare)" ]]; then | |
msg "Preparing" | |
prepare | |
fi | |
msg "Building" | |
build | |
msg "Installing" | |
package | |
if [ -n "$finalpath" ]; then | |
cp -a "$pkgdir"/* "$finalpath" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment