Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
script for updating PKGBUILD for Syncthing on Chakra Linux
#!/usr/bin/bash
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
fi
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
fi
echo "enough args"
NEW="$1"
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
fi
echo "tested OLD vs NEW"
if [ "$NEW" = "-" ]; then
NEW="$OLD"
fi
# 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 https://stackoverflow.com/a/33416489, 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
done
# Make source tarball to upload to the CCR and local package file to install
echo "Making source tarball"
makepkg --source
echo "Making package file"
makepkg
# 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
You can’t perform that action at this time.