Rework of the packaging script for Arch Linux to make it more flexible and reliable

pull/130/head
Shadowigor 6 years ago
parent 477eb9ea84
commit b2b5714469

@ -1,25 +1,113 @@
#!/bin/bash #!/bin/bash
git clone git+ssh://aur@aur.archlinux.org/osync.git osync.aur && HELPTEXT=\
cd "osync.aur" && "Usage: $0 [OPTIONS]\n"\
srcdir="." && "Automatically updates the osync version in the AUR.\n"\
source "PKGBUILD" && "\n"\
"-y, --yes Do not prompt before committing\n"\
"-n, --name=USERNAME Username to use with git in case no global username is set\n"\
"-e, --email=EMAIL Email address to use with git in case no global email is set"
url=$(echo -n ${source[0]} | sed 's/git+//g' | sed 's/#.*//g') && function cleanup {
branch=$(echo -n ${source[0]} | sed 's/.*#branch=//g') && echo "Cleanup..."
git clone -b $branch $url && cd ..
rm -rf osync.aur
}
# Get pkgver from current osync # Check getopt compatibility
pkgver=$(grep PROGRAM_VERSION= ./osync/osync.sh) getopt --test > /dev/null
pkgver=${pkgver##*=} if [[ $? -ne 4 ]]; then
echo $pkgver echo "You don't seem to have the GNU-enhanced getopt available. That shouldn't happen on a modern system with bash installed."
exit 38
fi
sed -i "s/pkgver=.*/pkgver=$(pkgver)/g" "PKGBUILD" && # Parse command line arguments
OPTIONS=hyn:e:
LONGOPTIONS=help,yes,name:,email:
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
exit 22
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
echo -e "$HELPTEXT"
exit 0
;;
-y|--yes)
yes="y"
shift
;;
-n|--name)
name="$2"
shift 2
;;
-e|--email)
email="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error" > /dev/stderr
exit 131
;;
esac
done
if [[ -z $name ]];then
name=$(git config --global user.name)
if [[ -z $name ]]; then
echo "Please specify a username for the git commit with the -n|--name option or set it globally with 'git config --global user.name USERNAME"
exit 22
fi
fi
if [[ -z $email ]];then
email=$(git config --global user.email)
if [[ -z $email ]]; then
echo "Please specify an e-mail for the git commit with the -e|--email option or set it globally with 'git config --global user.email EMAIL"
exit 22
fi
fi
### Main ###
echo "Cloning AUR package..."
if ! git clone -q git+ssh://aur@aur.archlinux.org/osync.git osync.aur || ! cd osync.aur; then
exit 1
fi
git config user.name "$name"
git config user.email "$email"
echo "Cloning most recent stable version of osync..." &&
git clone -qb stable https://github.com/deajan/osync.git > /dev/null &&
echo "Fetching version..." &&
cd osync &&
pkgversion="$(git describe --tags --long | sed 's/\([^-]*-\)g/r\1/;s/-/./g')" &&
cd .. &&
echo "Updating version..." &&
sed -i "s/pkgver=.*/pkgver=${pkgversion}/g" "PKGBUILD" &&
../mksrcinfo && ../mksrcinfo &&
rm -rf "osync" && rm -rf "osync" &&
git add . &&
git commit -m "Updated version" && [[ ! -z $yes ]] || (read -p "About to commit changes to AUR. Are you sure? (y/n) " -n 1 -r && echo "" &&
git push origin master && [[ $REPLY =~ ^[Yy]$ ]]) &&
cd .. &&
rm -rf "osync.aur" && echo "Committing changes to AUR..." &&
echo "Package updated successfully" git add PKGBUILD .SRCINFO &&
git commit -qm "Updated version to ${pkgversion}" &&
git push -q origin master &&
cleanup &&
echo "Package updated successfully to version ${pkgversion}" || cleanup
exit 0

Loading…
Cancel
Save