Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
script for updating PKGBUILD for Syncthing on Chakra Linux
echo "Flags: ($*)"
# Check that everything's okay to run this
if ! cd "$(dirname "$(readlink -f "$0")")/syncthing"; then
echo "Could not 'cd' to package's directory."
exit 1
echo "cd'd"
if [ "$#" != "1" ]; then
echo "$0 newversion"
echo "Updates the PKGBUILD to the new version, removes old downloads, and builds."
echo "With '-' as the new version, rebuild for the old version."
exit 1
echo "enough args"
echo "NEW=$NEW"
OLD="$(grep -E "pkgver=[0-9.]+" PKGBUILD | cut -c8-)"
echo "OLD=$OLD"
if [ "$OLD" = "$NEW" ]; then
echo "Already at version $OLD. Use '-' to keep the same version."
exit 1
echo "tested OLD vs NEW"
if [ "$NEW" = "-" ]; then
# Save old files, and recover new ones if previously saved.
echo "Shuffling current files as applicable..."
# We only care about the source; everything else is auto-generated.
mkdir -p old
mv -t ./old ./syncthing-source-v*.tar.gz # move all old sources to old
mv -t . "./old/syncthing-source-v$NEW.tar.gz" # and move current one to .
# Remove previously generated source and package files
rm ./*.src.tar.gz ./*.pkg.tar
# Switch PKGBUILD to new version
echo "Updating version in PKGBUILD..."
sed -r "s/^pkgver=$OLD\$/pkgver=$NEW/g" -i ./PKGBUILD
sed -r "s/[0-9a-f]{64,}/SKIP/g" -i ./PKGBUILD
# Download and update checksums for new version
echo "Getting sources..."
makepkg --nobuild
echo "Updating checksums..."
makepkg --geninteg | grep -Eo '[0-9a-f]{64,}' |
while read -r; do
# Per, this GNU sed
# command matches the find pattern ('SKIP') from line 0 or
# later, uses it in an "s/find/replace/" expression (while
# reusing the find pattern with "//"), and replaces it with
# the replace pattern ('$REPLY').
sed -r "0,/'SKIP'/ s//'$REPLY'/" -i ./PKGBUILD
# Make source tarball to upload to the CCR and local package file to install
echo "Making source tarball"
makepkg --source
echo "Making package file"
# Clean up packaging directories
rm -r ./pkg ./src
echo "Done! ^.^"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment