summaryrefslogtreecommitdiffstats
path: root/scripts/repo-add.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/repo-add.sh.in')
-rw-r--r--scripts/repo-add.sh.in72
1 files changed, 54 insertions, 18 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 283ad07a..9b79022a 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,15 +28,17 @@ myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@'
QUIET=0
+DELTA=0
+WITHFILES=0
REPO_DB_FILE=
LOCKFILE=
CLEAN_LOCK=0
-startdir="$PWD"
# ensure we have a sane umask set
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] [-f] [-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\
@@ -71,7 +73,13 @@ specified on the command line from the given repo database. Multiple\n\
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")"
+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")"
+ printf "$(gettext "\
+Use the -f/--files flag to update a database including file entries.\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 +135,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 +151,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 +190,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 csize size md5sum url arch builddate packager \
_groups _licenses _replaces _depends _conflicts _provides _optdepends
local OLDIFS="$IFS"
@@ -224,10 +230,17 @@ db_write_entry()
return 1
fi
- cd "$tmpdir"
-
+ pushd "$tmpdir" >/dev/null
if [[ -d $pkgname-$pkgver ]]; then
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
+ else
+ if (( DELTA )); 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
@@ -235,7 +248,7 @@ db_write_entry()
# create package directory
mkdir "$pkgname-$pkgver"
- cd "$pkgname-$pkgver"
+ pushd "$pkgname-$pkgver" >/dev/null
# restore an eventual deltas file
[[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas
@@ -261,7 +274,6 @@ 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"
- [[ -n $force ]] && echo -e "%FORCE%\n" >>desc
# create depends entry
msg2 "$(gettext "Creating 'depends' db entry...")"
@@ -272,7 +284,30 @@ db_write_entry()
write_list_entry "PROVIDES" "$_provides" "depends"
write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
- cd "$startdir"
+ popd >/dev/null
+ popd >/dev/null
+
+ # create files file if wanted
+ if (( WITHFILES )); then
+ msg2 "$(gettext "Creating 'files' db entry...")"
+ local files_path="$tmpdir/$pkgname-$pkgver/files"
+ echo "%FILES%" >$files_path
+ bsdtar --exclude='.*' -tf "$pkgfile" >>$files_path
+ fi
+
+ # create a delta file
+ if (( DELTA )); then
+ if [[ -n $oldfilename ]]; then
+ if [[ -f $oldfile ]]; then
+ delta=$(pkgdelta -q $oldfile $1)
+ if [[ -f $delta ]]; then
+ db_write_delta $delta
+ fi
+ else
+ warning "$(gettext "Old package file not found: %s")" "$oldfilename"
+ fi
+ fi
+ fi
return 0
} # end db_write_entry
@@ -404,7 +439,6 @@ trap_exit()
clean_up() {
local exit_code=$?
- cd "$startdir"
[[ -d $tmpdir ]] && rm -rf "$tmpdir"
(( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE"
@@ -446,6 +480,8 @@ success=0
for arg in "$@"; do
case "$arg" in
-q|--quiet) QUIET=1;;
+ -d|--delta) DELTA=1;;
+ -f|--files) WITHFILES=1;;
*)
if [[ -z $REPO_DB_FILE ]]; then
REPO_DB_FILE="$arg"
@@ -475,7 +511,7 @@ if (( success )); then
filename=$(basename "$REPO_DB_FILE")
- cd "$tmpdir"
+ pushd "$tmpdir" >/dev/null
if [[ -n $(ls) ]]; then
bsdtar -c${TAR_OPT}f "$filename" *
else
@@ -483,7 +519,7 @@ if (( success )); then
warning "$(gettext "No packages remain, creating empty database.")"
bsdtar -c${TAR_OPT}f "$filename" -T /dev/null
fi
- cd "$startdir"
+ popd >/dev/null
[[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
[[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"