From c4ea4e017fc35fe8c5057b86bab0a95dac75fc6f Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 9 Jan 2012 16:01:48 -0500 Subject: updpkgsums: add new contrib script This updates checksums in a PKGBUILD in-place. If no sums are found, they are appended to the end. --- contrib/.gitignore | 1 + contrib/Makefile.am | 5 ++- contrib/updpkgsums.sh.in | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100755 contrib/updpkgsums.sh.in diff --git a/contrib/.gitignore b/contrib/.gitignore index 01bc22bd..afbca0fb 100644 --- a/contrib/.gitignore +++ b/contrib/.gitignore @@ -8,4 +8,5 @@ pacscripts pacsearch pacsysclean rankmirrors +updpkgsums zsh_completion diff --git a/contrib/Makefile.am b/contrib/Makefile.am index a325d62a..e33707bf 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -12,7 +12,8 @@ BASHSCRIPTS = \ paclog-pkglist \ pacscripts \ pacsysclean \ - rankmirrors + rankmirrors \ + updpkgsums OTHERSCRIPTS = \ pacsearch @@ -37,6 +38,7 @@ EXTRA_DIST = \ pacsearch.in \ pacsysclean.sh.in \ rankmirrors.sh.in + updpkgsums.sh.in \ vimprojects \ zsh_completion.in \ README @@ -98,6 +100,7 @@ pacscripts: $(srcdir)/pacscripts.sh.in pacsearch: $(srcdir)/pacsearch.in pacsysclean: $(srcdir)/pacsysclean.sh.in rankmirrors: $(srcdir)/rankmirrors.sh.in +updpkgsums: $(srcdir)/updpkgsums.sh.in zsh_completion: $(srcdir)/zsh_completion.in # vim:set ts=2 sw=2 noet: diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in new file mode 100755 index 00000000..f4649b54 --- /dev/null +++ b/contrib/updpkgsums.sh.in @@ -0,0 +1,93 @@ +#!/bin/bash +# +# updpkgsums - update source checksums in-place in PKGBUILDs +# +# Copyright (C) 2012 Dave Reisner +# +# 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 . + +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 ' +} + +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 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 + 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 + END { if (!w) print newsums } + ' > "$buildfile" +} < "$buildfile" + +# vim: set ts=2 sw=2 noet: -- cgit v1.2.3-24-g4f1b