[pacman-dev] [PATCH] updpkgsums: add new contrib script

Dave Reisner d at falconindy.com
Mon Jan 9 20:51:57 EST 2012


updpkgsums updates checksums in a PKGBUILD "in place"
---
This is really a whole lot of sanity checking and very little actual noise,
but given what this script does (deleting a file), I chose to err on the
side of extreme caution.

I remembered to add to .gitignore this time!

 contrib/.gitignore    |    1 +
 contrib/Makefile.am   |    5 ++-
 contrib/updpkgsums.in |   90 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 1 deletions(-)
 create mode 100755 contrib/updpkgsums.in

diff --git a/contrib/.gitignore b/contrib/.gitignore
index 19b81e0..4f8e1e7 100644
--- a/contrib/.gitignore
+++ b/contrib/.gitignore
@@ -7,5 +7,6 @@ paclog-pkglist
 pacscripts
 pacsearch
 pacsysclean
+updpkgsums
 wget-xdelta.sh
 zsh_completion
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index eca39e7..fab8d7c 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -12,7 +12,8 @@ OURSCRIPTS = \
 	paclog-pkglist \
 	pacscripts \
 	pacsearch \
-	pacsysclean
+	pacsysclean \
+	updpkgsums
 
 OURFILES = \
 	bash_completion \
@@ -29,6 +30,7 @@ EXTRA_DIST = \
 	pacscripts.in \
 	pacsearch.in \
 	pacsysclean.in \
+	updpkgsums.in \
 	vimprojects \
 	zsh_completion.in \
 	README
@@ -84,6 +86,7 @@ pacscripts: $(srcdir)/pacscripts.in
 pacsearch: $(srcdir)/pacsearch.in
 pacsysclean: $(srcdir)/pacsysclean.in
 pactree: $(srcdir)/pactree.in
+updpkgsums: $(srcdir)/updpkgsums.in
 zsh_completion: $(srcdir)/zsh_completion.in
 
 # vim:set ts=2 sw=2 noet:
diff --git a/contrib/updpkgsums.in b/contrib/updpkgsums.in
new file mode 100755
index 0000000..304f5db
--- /dev/null
+++ b/contrib/updpkgsums.in
@@ -0,0 +1,90 @@
+#!/bin/bash
+#
+# updpkgsums - update source checksums in-place in PKGBUILDs
+#
+# Copyright (C) 2012 Dave Reisner <dreisner at archlinux.org>
+#
+# 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() {
+	printf 'usage: %s [buildfile]\n\n' "$myname"
+	printf '    -h, --help        display this help message and exit\n'
+	printf '    -V, --version     display version information and exit\n\n'
+	printf '%s will perform an in place update the checksums in the\n' "$myname"
+	printf 'path specified by [buildfile], defaulting to PKGBUILD in the current\n'
+	printf 'working directory.\n'
+}
+
+version() {
+	printf "%s %s\n" "$myname" "$myver"
+	echo 'Copyright (C) 2012 Dave Reisner <dreisner at archlinux.org>'
+}
+
+case $1 in
+	-h|--help) usage; exit ;;
+	-V|--version) version; exit ;;
+esac
+
+buildfile=${1:-PKGBUILD}
+if [[ ! -f $buildfile ]]; then
+	printf $'==> ERROR: \`%s\' not found or is not a file: %s\n' "$buildfile"
+	exit 1
+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 OS's.
+while [[ -L $buildfile ]]; do
+	buildfile=$(readlink "$buildfile")
+	cd "${buildfile%/*}"
+	buildfile=${buildfile##*/}
+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
+	printf $'==> ERROR: No write permission in `%s\'\n' "$PWD"
+	exit 1
+fi
+
+{
+	# Generate the new sums and try to unlink the file before writing stdin back
+	# into it. This final precaution shouldn't fail based on the previous checks,
+	# but it's better to be extra careful before unlinking files.
+	newsums=$(makepkg -g -p "$buildfile") && rm -f "$buildfile" &&
+	exec awk -v newsums="$newsums" '
+	/^[[:blank:]]*(md|sha)[[:digit:]]+sums=/,/\)[[:blank:]]*(#.*)?$/ {
+		if (!w) {
+			print newsums
+			w++
+		}
+		next
+	}
+
+	1
+	' > "$buildfile"
+} < "$buildfile"
+
+# vim: set ts=2 sw=2 noet:
-- 
1.7.8.3



More information about the pacman-dev mailing list