2012-01-09 16:01:48 -05:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# updpkgsums - update source checksums in-place in PKGBUILDs
|
|
|
|
#
|
2013-01-01 23:19:59 -05:00
|
|
|
# Copyright (C) 2012-2013 Dave Reisner <dreisner@archlinux.org>
|
2012-01-09 16:01:48 -05:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
declare -r myname='updpkgsums'
|
|
|
|
declare -r myver='@PACKAGE_VERSION@'
|
|
|
|
|
|
|
|
usage() {
|
2013-11-08 02:53:33 -05:00
|
|
|
printf "%s (pacman) v%s\n" "${myname}" "${myver}"
|
|
|
|
echo
|
|
|
|
printf "%s will perform an in place update of the checksums in the\n" "${myname}"
|
|
|
|
echo "path specified by [build file], defaulting to PKGBUILD in the current"
|
|
|
|
echo "working directory."
|
|
|
|
echo
|
2016-05-01 13:03:08 -04:00
|
|
|
printf "Usage: %s [options] [build file]\n" "${myname}"
|
2013-11-08 02:53:33 -05:00
|
|
|
echo
|
|
|
|
echo " -h, --help display this help message and exit"
|
|
|
|
echo " -V, --version display version information and exit"
|
2016-05-01 13:03:08 -04:00
|
|
|
echo
|
|
|
|
echo "These options can be passed to makepkg:"
|
|
|
|
echo " -m, --nocolor disable colorized output messages"
|
2012-01-09 16:01:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
version() {
|
|
|
|
printf "%s %s\n" "$myname" "$myver"
|
2013-01-01 23:19:59 -05:00
|
|
|
echo 'Copyright (C) 2012-2013 Dave Reisner <dreisner@archlinux.org>'
|
2012-01-09 16:01:48 -05:00
|
|
|
}
|
|
|
|
|
2014-12-14 13:45:06 -05:00
|
|
|
die() {
|
|
|
|
printf "==> ERROR: $1\n" "${@:2}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-05-01 13:03:08 -04:00
|
|
|
MAKEPKG_OPTS=()
|
|
|
|
buildfile='PKGBUILD'
|
|
|
|
|
|
|
|
while (( "$#" )); do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help) usage; exit ;;
|
|
|
|
-m|--nocolor) MAKEPKG_OPTS+=("$1"); shift ;;
|
|
|
|
-V|--version) version; exit ;;
|
|
|
|
*) buildfile="$1"; break 2 ;;
|
|
|
|
esac
|
|
|
|
done
|
2012-01-09 16:01:48 -05:00
|
|
|
|
|
|
|
if [[ ! -f $buildfile ]]; then
|
2014-12-14 13:45:06 -05:00
|
|
|
die "%s not found or is not a file" "$buildfile"
|
2012-01-09 16:01:48 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Resolve any symlinks to avoid replacing the symlink with a file. But, we
|
|
|
|
# have to do this portably -- readlink's flags are inconsistent across OSes.
|
|
|
|
while [[ -L $buildfile ]]; do
|
|
|
|
buildfile=$(readlink "$buildfile")
|
|
|
|
if [[ $buildfile = */* ]]; then
|
|
|
|
cd "${buildfile%/*}"
|
|
|
|
buildfile=${buildfile##*/}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# cd into the directory with the build file. This avoids creating random src/
|
|
|
|
# directories scattered about the filesystem, and avoids cases where we might
|
|
|
|
# not be able to write in the $PWD.
|
|
|
|
if [[ $buildfile = */* ]]; then
|
|
|
|
cd "${buildfile%/*}"
|
|
|
|
buildfile=${buildfile##*/}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check $PWD/ for permission to unlink the $buildfile and write a new one
|
|
|
|
if [[ ! -w . ]]; then
|
2014-12-14 13:45:06 -05:00
|
|
|
die "No write permission in '%s'" "$PWD"
|
2012-01-09 16:01:48 -05:00
|
|
|
fi
|
|
|
|
|
2014-12-14 13:45:06 -05:00
|
|
|
# Generate the new sums
|
2015-12-30 19:10:21 -05:00
|
|
|
export BUILDDIR=$(mktemp -d "${TMPDIR:-/tmp}/updpkgsums.XXXXXX")
|
|
|
|
newbuildfile=$(mktemp "${TMPDIR:-/tmp}/updpkgsums.XXXXXX")
|
2014-12-14 13:45:06 -05:00
|
|
|
|
|
|
|
trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT
|
2016-05-01 13:03:08 -04:00
|
|
|
newsums=$(makepkg -g -p "$buildfile" "${MAKEPKG_OPTS[@]}") || die 'Failed to generate new checksums'
|
2014-12-14 13:45:06 -05:00
|
|
|
awk -v newsums="$newsums" '
|
2014-08-09 18:02:33 -04:00
|
|
|
/^[[:blank:]]*(md|sha)[[:digit:]]+sums(_[^=]+)?=/,/\)[[:blank:]]*(#.*)?$/ {
|
2012-01-09 16:01:48 -05:00
|
|
|
if (!w) {
|
|
|
|
print newsums
|
|
|
|
w++
|
|
|
|
}
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
1
|
|
|
|
END { if (!w) print newsums }
|
2014-12-18 23:20:22 -05:00
|
|
|
' "$buildfile" > "$newbuildfile" || die 'Failed to write new PKGBUILD'
|
2014-12-14 13:45:06 -05:00
|
|
|
|
2014-12-31 14:33:31 -05:00
|
|
|
# Rewrite the original buildfile. Use cat instead of mv/cp to preserve
|
|
|
|
# permissions implicitly.
|
|
|
|
if ! cat -- "$newbuildfile" >"$buildfile"; then
|
2014-12-14 13:45:06 -05:00
|
|
|
die "Failed to update %s. The file has not been modified." "$buildfile"
|
|
|
|
fi
|
2012-01-09 16:01:48 -05:00
|
|
|
|
2014-01-22 18:06:11 -05:00
|
|
|
# vim: set noet:
|