From 8581694ceb63f4ed2854206b38574599c3d9df28 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 24 Jun 2011 08:36:54 -0400 Subject: makepkg: fix incorrect parenthesis in gettext call allan broke it in 4bdb868a. Signed-off-by: Dave Reisner --- scripts/makepkg.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index e101a763..3d40bc1e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2096,7 +2096,7 @@ if (( INFAKEROOT )); then tidy_install fi else - warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()" + warning "$(gettext "Repackaging without the use of a %s function is deprecated." "package()")" plain "$(gettext "File permissions may not be preserved.")" fi else -- cgit v1.2.3-70-g09d2 From 522c94f16842d4fe307cc72069b16a94c927c6ea Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 20 Jun 2011 15:01:23 -0400 Subject: repo-add: bashify reading of .PKGINFO file grep and sed aren't needed here, and this removes the truly ugly manipulation of IFS. The process substituion could just as well be a herestring, but it breaks vim's syntax highlighting. Style over substance, mang. Signed-off-by: Dave Reisner --- scripts/repo-add.sh.in | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index e970da38..82922536 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -19,6 +19,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +shopt -s extglob + # gettext initialization export TEXTDOMAIN='pacman-scripts' export TEXTDOMAINDIR='@localedir@' @@ -226,19 +228,14 @@ db_write_entry() { _groups _licenses _replaces _depends _conflicts _provides _optdepends \ md5sum sha256sum pgpsig - local OLDIFS="$IFS" - # IFS (field separator) is only the newline character - IFS=" -" - # read info from the zipped package local line var val - for line in $(bsdtar -xOqf "$pkgfile" .PKGINFO | - grep -v '^#' | sed 's|\(\w*\)\s*=\s*\(.*\)|\1 \2|'); do - # bash awesomeness here- var is always one word, val is everything else - var=${line%% *} - val=${line#* } - declare $var="$val" + while read -r line; do + [[ ${line:0:1} = '#' ]] && continue + IFS=' =' read -r var val < <(printf '%s\n' "$line") + + # normalize whitespace with an extglob + declare "$var=${val//+([[:space:]])/ }" case "$var" in group) _groups="$_groups$group\n" ;; license) _licenses="$_licenses$license\n" ;; @@ -248,9 +245,7 @@ db_write_entry() { provides) _provides="$_provides$provides\n" ;; optdepend) _optdepends="$_optdepends$optdepend\n" ;; esac - done - - IFS=$OLDIFS + done< <(bsdtar -xOqf "$pkgfile" .PKGINFO) csize=$(@SIZECMD@ "$pkgfile") -- cgit v1.2.3-70-g09d2 From 5246fdecf6ab6a3f847d02967250f100ef440242 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 20 Jun 2011 15:12:01 -0400 Subject: repo-add: store multi-value fields as arrays Fields like groups and depends should be stored as arrays. This requires rewriting our write_list_entry function to accomodate our new data type. This new function will not write to a file, but rather only format it. Signed-off-by: Dave Reisner --- scripts/repo-add.sh.in | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'scripts') diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 82922536..dcf376e7 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -84,14 +84,16 @@ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } -# write a list entry +# format a metadata entry # arg1 - Entry name -# arg2 - List -# arg3 - File to write to -write_list_entry() { - if [[ -n $2 ]]; then - echo "%$1%" >>$3 - echo -e $2 >>$3 +# ... - value(s) +format_entry() { + local field=$1; shift + + if [[ $1 ]]; then + printf '%%%s%%\n' "$field" + printf '%s\n' "$@" + printf '\n' fi } @@ -224,8 +226,8 @@ verify_signature() { db_write_entry() { # blank out all variables local pkgfile="$1" + local -a _groups _licenses _replaces _depends _conflicts _provides _optdepends local pkgname pkgver pkgdesc csize size url arch builddate packager \ - _groups _licenses _replaces _depends _conflicts _provides _optdepends \ md5sum sha256sum pgpsig # read info from the zipped package @@ -237,13 +239,13 @@ db_write_entry() { # normalize whitespace with an extglob declare "$var=${val//+([[:space:]])/ }" case "$var" in - group) _groups="$_groups$group\n" ;; - license) _licenses="$_licenses$license\n" ;; - replaces) _replaces="$_replaces$replaces\n" ;; - depend) _depends="$_depends$depend\n" ;; - conflict) _conflicts="$_conflicts$conflict\n" ;; - provides) _provides="$_provides$provides\n" ;; - optdepend) _optdepends="$_optdepends$optdepend\n" ;; + group) _groups+=("$group") ;; + license) _licenses+=("$license") ;; + replaces) _replaces+=("$replaces") ;; + depend) _depends+=("$depend") ;; + conflict) _conflicts+=("$conflict") ;; + provides) _provides+=("$provides") ;; + optdepend) _optdepends+=("$optdepend") ;; esac done< <(bsdtar -xOqf "$pkgfile" .PKGINFO) @@ -297,7 +299,7 @@ db_write_entry() { [[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc echo -e "%VERSION%\n$pkgver\n" >>desc [[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc - write_list_entry "GROUPS" "$_groups" "desc" + format_entry "GROUPS" "${_groups[@]}" >>"desc" [[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc [[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc @@ -309,20 +311,20 @@ db_write_entry() { [[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc [[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc - write_list_entry "LICENSE" "$_licenses" "desc" + format_entry "LICENSE" "${_licenses[@]}" >>"desc" [[ -n $arch ]] && echo -e "%ARCH%\n$arch\n" >>desc [[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc [[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc - write_list_entry "REPLACES" "$_replaces" "desc" + format_entry "REPLACES" "${_replaces[@]}" >>"desc" # create depends entry msg2 "$(gettext "Creating '%s' db entry...")" 'depends' - # create the file even if it will remain empty - touch "depends" - write_list_entry "DEPENDS" "$_depends" "depends" - write_list_entry "CONFLICTS" "$_conflicts" "depends" - write_list_entry "PROVIDES" "$_provides" "depends" - write_list_entry "OPTDEPENDS" "$_optdepends" "depends" + { + format_entry "DEPENDS" "${_depends[@]}" + format_entry "CONFLICTS" "${_conflicts[@]}" + format_entry "PROVIDES" "${_provides[@]}" + format_entry "OPTDEPENDS" "${_optdepends[@]}" + } >'depends' popd >/dev/null popd >/dev/null -- cgit v1.2.3-70-g09d2 From 7d8e9b8ed65343031284b891d713529aecbff659 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 20 Jun 2011 15:37:09 -0400 Subject: repo-add: use format_entry for all desc/depends fields This ranks high on the code readability scale. The same function formats all of our data and writes to the metadata file at once. Signed-off-by: Dave Reisner --- scripts/repo-add.sh.in | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'scripts') diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index dcf376e7..1e77015f 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -294,28 +294,30 @@ db_write_entry() { # create desc entry msg2 "$(gettext "Creating '%s' db entry...")" 'desc' - echo -e "%FILENAME%\n${1##*/}\n" >>desc - echo -e "%NAME%\n$pkgname\n" >>desc - [[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc - echo -e "%VERSION%\n$pkgver\n" >>desc - [[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc - format_entry "GROUPS" "${_groups[@]}" >>"desc" - [[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc - [[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc - - # add checksums - echo -e "%MD5SUM%\n$md5sum\n" >>desc - echo -e "%SHA256SUM%\n$sha256sum\n" >>desc - - # add PGP sig - [[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc - - [[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc - format_entry "LICENSE" "${_licenses[@]}" >>"desc" - [[ -n $arch ]] && echo -e "%ARCH%\n$arch\n" >>desc - [[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc - [[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc - format_entry "REPLACES" "${_replaces[@]}" >>"desc" + { + format_entry "FILENAME" "${1##*/}" + format_entry "NAME" "$pkgname" + format_entry "BASE" "$pkgbase" + format_entry "VERSION" "$pkgver" + format_entry "DESC" "$pkgdesc" + format_entry "GROUPS" "${_groups[@]}" + format_entry "CSIZE" "$csize" + format_entry "ISIZE" "$size" + + # add checksums + format_entry "MD5SUM" "$md5sum" + format_entry "SHA256SUM" "$sha256sum" + + # add PGP sig + format_entry "PGPSIG" "$pgpsig" + + format_entry "URL" "$url" + format_entry "LICENSE" "${_licenses[@]}" + format_entry "ARCH" "$arch" + format_entry "BUILDDATE" "$builddate" + format_entry "PACKAGER" "$packager" + format_entry "REPLACES" "${_replaces[@]}" + } >'desc' # create depends entry msg2 "$(gettext "Creating '%s' db entry...")" 'depends' -- cgit v1.2.3-70-g09d2 From 6f5a90edb39cdd7e5e3faa7acdbaad288876f9da Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 22 Jun 2011 15:35:27 -0400 Subject: repo-add: refactor repacking of repo file Dump the whole conditional and filter the contents of the directory to create an empty or non-empty archive. Signed-off-by: Dave Reisner --- scripts/repo-add.sh.in | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 1e77015f..e7a4be40 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -595,15 +595,9 @@ if (( success )); then filename=${REPO_DB_FILE##*/} pushd "$tmpdir" >/dev/null - if [[ -n $(ls) ]]; then - bsdtar -c${TAR_OPT}f "$filename" * - else - # we have no packages remaining? zip up some emptyness - warning "$(gettext "No packages remain, creating empty database.")" - bsdtar -c${TAR_OPT}f "$filename" -T /dev/null - fi + # strip the './' off filenames; this also allows us to tar an empty dir + bsdtar -s %^./%% -c${TAR_OPT}f "$REPO_DB_FILE" ./ create_signature "$filename" - popd >/dev/null [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old" -- cgit v1.2.3-70-g09d2 From 122b4c218785a89dcf6e1a335f6083aa166d4cdb Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 22 Jun 2011 16:26:55 -0400 Subject: repo-add: move command invocation out of arg parsing loop Signed-off-by: Dave Reisner --- scripts/repo-add.sh.in | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index e7a4be40..6d09f0a3 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -531,9 +531,10 @@ trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR +declare -a args success=0 # parse arguments -while [[ $# > 0 ]]; do +while (( $# )); do case "$1" in -q|--quiet) QUIET=1;; -d|--delta) DELTA=1;; @@ -564,21 +565,23 @@ while [[ $# > 0 ]]; do VERIFY=1 ;; *) - if [[ -z $REPO_DB_FILE ]]; then - REPO_DB_FILE="$1" - LOCKFILE="$REPO_DB_FILE.lck" - check_repo_db - else - case "$cmd" in - repo-add) add $1 && success=1 ;; - repo-remove) remove $1 && success=1 ;; - esac - fi + args+=("$1") ;; esac shift done +REPO_DB_FILE=${args[0]} +LOCKFILE=$REPO_DB_FILE.lck +check_repo_db + +for arg in "${args[@]:1}"; do + case "$cmd" in + repo-add) add "$arg" ;; + repo-remove) remove "$arg" ;; + esac && success=1 +done + # if at least one operation was a success, re-zip database if (( success )); then msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE" -- cgit v1.2.3-70-g09d2 From 399184d68f23e124e386a340abf5bcec968b322b Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 21 Jun 2011 13:58:32 -0400 Subject: repo-add: enforce file extensions Allow one of 4 archive extensions: .tar{,.gz,.xz,.bz2} for each of the 2 valid repo extensions: .db and .files. Check for this via 'verify_repo_extension' directly after option parsing to assert that this extension is present, and again after files have been added to get the proper archive option for bsdtar. Signed-off-by: Dave Reisner --- scripts/repo-add.sh.in | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 6d09f0a3..7f5674e2 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -221,6 +221,22 @@ verify_signature() { fi } +verify_repo_extension() { + local repofile=$1 + + case "$repofile" in + *.@(db|files).tar.gz) TAR_OPT="z" ;; + *.@(db|files).tar.bz2) TAR_OPT="j" ;; + *.@(db|files).tar.xz) TAR_OPT="J" ;; + *.@(db|files).tar) TAR_OPT="" ;; + *) error "$(gettext "'%s' does not have a valid archive extension.")" \ + "$repofile" + exit 1 ;; + esac + + printf '%s' "$TAR_OPT" +} + # write an entry to the pacman database # arg1 - path to package db_write_entry() { @@ -571,8 +587,11 @@ while (( $# )); do shift done + REPO_DB_FILE=${args[0]} LOCKFILE=$REPO_DB_FILE.lck + +verify_repo_extension "$REPO_DB_FILE" >/dev/null check_repo_db for arg in "${args[@]:1}"; do @@ -586,15 +605,7 @@ done if (( success )); then msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE" - case "$REPO_DB_FILE" in - *.tar.gz) TAR_OPT="z" ;; - *.tar.bz2) TAR_OPT="j" ;; - *.tar.xz) TAR_OPT="J" ;; - *.tar) TAR_OPT="" ;; - *) warning "$(gettext "'%s' does not have a valid archive extension.")" \ - "$REPO_DB_FILE" ;; - esac - + TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE") filename=${REPO_DB_FILE##*/} pushd "$tmpdir" >/dev/null -- cgit v1.2.3-70-g09d2 From db172b09c55fd4f110717e1e5586e9ba5e29607e Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 24 Jun 2011 15:19:36 -0400 Subject: repo-add: add new command, repo-elephant _ _ / \__/ \_____ / / \ \ `\ ) \''/ ( |\ `\__)/__/'_\ / ` //_|_|~|_|_| ^""'"' ""'"' Signed-off-by: Dave Reisner --- .gitignore | 1 + scripts/Makefile.am | 7 ++++++- scripts/repo-add.sh.in | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/.gitignore b/.gitignore index b2db3a07..cfe92e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ pacman-*.tar.gz root stamp-h1 tags +repo-elephant diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 3b96c110..492eb0ff 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -5,7 +5,8 @@ SUBDIRS = po bin_SCRIPTS = \ $(OURSCRIPTS) \ - repo-remove + repo-remove \ + repo-elephant OURSCRIPTS = \ makepkg \ @@ -97,4 +98,8 @@ repo-remove: $(srcdir)/repo-add.sh.in rm -f repo-remove $(LN_S) repo-add repo-remove +repo-elephant: $(srcdir)/repo-add.sh.in + rm -f repo-elephant + $(LN_S) repo-add repo-elephant + # vim:set ts=2 sw=2 noet: diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 7f5674e2..1d78c472 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -391,6 +391,22 @@ db_remove_entry() { return $notfound } # end db_remove_entry +elephant() { + case $(( RANDOM % 2 )) in + 0) printf '%s\n' "H4sIAL3qBE4CAyWLwQ3AMAgD/0xh5UPzYiFUMgjq7LUJsk7yIQNAQTAikFUDnqkr" \ + "OQFOUm0Wd9pHCi13ONjBpVdqcWx+EdXVX4vXvGv5cgztB9+fJxZ7AAAA" + ;; + + 1) printf '%s\n' "H4sIAJVWBU4CA21RMQ7DIBDbeYWrDgQJ7rZ+IA/IB05l69alcx5fc0ASVXUk4jOO" \ + "7yAAUWtorygwJ4hlMii0YkJKKRKGvsMsiykl1SalvrMD1gUXyXRkGZPx5OPft81K" \ + "tNAiAjyGjYO47h1JjizPkJrCWbK/4C+uLkT7bzpGc7CT9bmOzNSW5WLSO5vexjmH" \ + "ZL9JFFZeAa0a2+lKjL2anpYfV+0Zx9LJ+/MC8nRayuDlSNy2rfAPibOzsiWHL0jL" \ + "SsjFAQAA" + ;; + esac | openssl base64 -d | gzip -d + exit 0 +} + check_repo_db() { local repodir @@ -533,6 +549,11 @@ esac # figure out what program we are cmd=${0##*/} +if [[ $cmd == "repo-elephant" ]]; then + elephant + exit 0 +fi + if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then error "$(gettext "Invalid command name '%s' specified.")" "$cmd" exit 1 -- cgit v1.2.3-70-g09d2