Skip to content

Instantly share code, notes, and snippets.

@sfan5 sfan5/makepkg.sh
Last active May 2, 2019

Embed
What would you like to do?
Reimplements functionality of makepkg to a small degree
#!/bin/bash -e
finalpath=/var/tmp/final
msg () {
echo ":: $1"
}
bfile=PKGBUILD
[ -n "$1" ] && bfile="$1"
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"
else
msg "Downloading PKGBUILD for $1 (repo: $2)"
mkdir -p "$1"
wget "https://git.archlinux.org/svntogit/$2.git/plain/trunk/PKGBUILD?h=packages/$1" -O "$1/PKGBUILD"
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##*/}"
[ ! -f "$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
if [ ! -d "$filename" ]; then
git clone "$giturl" "$filename"
[ -n "$checkout" ] && { cd "$filename"; git checkout "$checkout"; }
fi
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 [[ "$filename" == *".tar."* ]]; then
tar -axf "$filename"
fi
done
srcdir=$PWD
mkdir -p pkg
pkgdir="$PWD/pkg"
if [[ -n "$(type -t prepare)" && -z "$NOPREPARE" ]]; then
msg "Preparing"
prepare
fi
msg "Building"
build
msg "Installing"
package
if [ ! -z "$finalpath" ]; then
cp -r "$pkgdir"/* "$finalpath"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.