index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | scripts/repo-add.sh.in | 44 |
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 283ad07a..d09d1b48 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!@BASH_SHELL@ # # repo-add - add a package to a given repo database file # repo-remove - remove a package entry from a given repo database file @@ -28,6 +28,7 @@ myver='@PACKAGE_VERSION@' confdir='@sysconfdir@' QUIET=0 +DELTA=0 REPO_DB_FILE= LOCKFILE= CLEAN_LOCK=0 @@ -37,6 +38,7 @@ startdir="$PWD" umask 0022 msg() { + (( QUIET )) && return local mesg=$1; shift printf "==> ${mesg}\n" "$@" >&1 } @@ -60,7 +62,7 @@ error() { # print usage instructions usage() { printf "repo-add, repo-remove (pacman) %s\n\n" "$myver" - printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package|delta> ...\n")" + printf "$(gettext "Usage: repo-add [-d] [-q] <path-to-db> <package|delta> ...\n")" printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")" printf "$(gettext "\ repo-add will update a package database by reading a package file.\n\ @@ -72,6 +74,10 @@ packages to remove can be specified on the command line.\n\n")" printf "$(gettext "\ Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\ and errors\n\n")" + printf "$(gettext "\ +Use the -d/--delta flag to automatically generate and add a delta file\n\ +between the old entry and the new one, if the old package file is found\n\ +next to the new one.\n\n")" echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")" echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")" } @@ -127,13 +133,12 @@ db_write_delta() pkgentry=$(find_pkgentry $pkgname) if [[ -z $pkgentry ]]; then + error "$(gettext "No database entry for package '%s'.")" "$pkgname" return 1 fi deltas="$pkgentry/deltas" - # create deltas file if it does not already exist if [[ ! -f $deltas ]]; then - msg2 "$(gettext "Creating 'deltas' db entry...")" - echo -e "%DELTAS%" >>$deltas + echo -e "%DELTAS%" >$deltas fi # get md5sum and compressed size of package md5sum="$(openssl dgst -md5 "$deltafile")" @@ -144,10 +149,9 @@ db_write_delta() newfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (output)" | sed 's/.*: *//') if grep -q "$oldfile.*$newfile" $deltas; then - warning "$(gettext "An entry for '%s' already existed")" "$deltafile" sed -i.backup "/$oldfile.*$newfile/d" $deltas && rm -f $deltas.backup - msg2 "$(gettext "Removing existing entry '%s'...")" "$deltafile" fi + msg2 "$(gettext "Adding 'deltas' entry : %s -> %s")" "$oldfile" "$newfile" echo ${deltafile##*/} $md5sum $csize $oldfile $newfile >> $deltas return 0 @@ -184,7 +188,7 @@ db_write_entry() { # blank out all variables local pkgfile="$1" - local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager force \ + local pkgname pkgver pkgdesc epoch csize size md5sum url arch builddate packager force \ _groups _licenses _replaces _depends _conflicts _provides _optdepends local OLDIFS="$IFS" @@ -228,6 +232,14 @@ db_write_entry() if [[ -d $pkgname-$pkgver ]]; then warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver" + else + if [ $DELTA -eq 1 ]; then + pkgentry=$(find_pkgentry $pkgname) + if [ -n "$pkgentry" ]; then + local oldfilename=$(grep -A1 FILENAME $pkgentry/desc | tail -n1) + local oldfile="$(dirname $1)/$oldfilename" + fi + fi fi # remove an existing entry if it exists, ignore failures @@ -261,6 +273,11 @@ db_write_entry() [[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc [[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc write_list_entry "REPLACES" "$_replaces" "desc" + # remain backward-compatible for now; put a force entry in the database + if [[ -n $epoch ]]; then + echo -e "%EPOCH%\n#epoch\n" >>desc + echo -e "%FORCE%\n" >>desc + fi [[ -n $force ]] && echo -e "%FORCE%\n" >>desc # create depends entry @@ -274,6 +291,16 @@ db_write_entry() cd "$startdir" + # create a delta file + if [ -n "$oldfilename" -a -f "$oldfile" ]; then + delta=$(pkgdelta -q $oldfile $1) + if [ -f "$delta" ]; then + db_write_delta $delta + else + warning "$(gettext "Old package file not found : %s")" "$oldfilename" + fi + fi + return 0 } # end db_write_entry @@ -446,6 +473,7 @@ success=0 for arg in "$@"; do case "$arg" in -q|--quiet) QUIET=1;; + -d|--delta) DELTA=1;; *) if [[ -z $REPO_DB_FILE ]]; then REPO_DB_FILE="$arg" |