summaryrefslogtreecommitdiff
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.in91
1 files changed, 57 insertions, 34 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 5724022a..504cae97 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -25,8 +25,8 @@ shopt -s extglob
export TEXTDOMAIN='pacman-scripts'
export TEXTDOMAINDIR='@localedir@'
-myver='@PACKAGE_VERSION@'
-confdir='@sysconfdir@'
+declare -r myver='@PACKAGE_VERSION@'
+declare -r confdir='@sysconfdir@'
QUIET=0
DELTA=0
@@ -176,6 +176,11 @@ db_remove_delta() {
if grep -q "$filename" "$deltas"; then
sed -i.backup "/$filename/d" "$deltas" && rm -f "$deltas.backup"
msg2 "$(gettext "Removing existing entry '%s'...")" "$filename"
+ # empty deltas file contains only "%DELTAS%"
+ if (( $(wc -l < "$deltas") == 1 )); then
+ msg2 "$(gettext "Removing empty deltas file ...")"
+ rm "$deltas"
+ fi
return 0
fi
@@ -203,7 +208,7 @@ create_signature() {
gpg --detach-sign --use-agent ${SIGNWITHKEY} "$dbfile" &>/dev/null || ret=$?
if (( ! ret )); then
- msg2 "$(gettext "Created signature file %s.")" "${dbfile##*/}.sig"
+ msg2 "$(gettext "Created signature file %s.")" "${dbfile##*/.tmp.}.sig"
else
warning "$(gettext "Failed to sign package database.")"
fi
@@ -251,7 +256,8 @@ verify_repo_extension() {
db_write_entry() {
# blank out all variables
local pkgfile=$1
- local -a _groups _licenses _replaces _depends _conflicts _provides _optdepends
+ local -a _groups _licenses _replaces _depends _conflicts _provides \
+ _optdepends _makedepends _checkdepends
local pkgname pkgver pkgdesc csize size url arch builddate packager \
md5sum sha256sum pgpsig pgpsigsize
@@ -264,13 +270,15 @@ db_write_entry() {
# normalize whitespace with an extglob
declare "$var=${val//+([[:space:]])/ }"
case $var in
- group) _groups+=("$group") ;;
- license) _licenses+=("$license") ;;
- replaces) _replaces+=("$replaces") ;;
- depend) _depends+=("$depend") ;;
- conflict) _conflicts+=("$conflict") ;;
- provides) _provides+=("$provides") ;;
+ group) _groups+=("$group") ;;
+ license) _licenses+=("$license") ;;
+ replaces) _replaces+=("$replaces") ;;
+ depend) _depends+=("$depend") ;;
+ conflict) _conflicts+=("$conflict") ;;
+ provides) _provides+=("$provides") ;;
optdepend) _optdepends+=("$optdepend") ;;
+ makedepend) _makedepends+=("$makedepend") ;;
+ checkdepend) _checkdepends+=("$checkdepend") ;;
esac
done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
@@ -353,10 +361,12 @@ db_write_entry() {
# create depends entry
msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
{
- format_entry "DEPENDS" "${_depends[@]}"
- format_entry "CONFLICTS" "${_conflicts[@]}"
- format_entry "PROVIDES" "${_provides[@]}"
+ format_entry "DEPENDS" "${_depends[@]}"
+ format_entry "CONFLICTS" "${_conflicts[@]}"
+ format_entry "PROVIDES" "${_provides[@]}"
format_entry "OPTDEPENDS" "${_optdepends[@]}"
+ format_entry "MAKEDEPENDS" "${_makedepends[@]}"
+ format_entry "CHECKDEPENDS" "${_checkdepends[@]}"
} >'depends'
popd >/dev/null
@@ -424,13 +434,8 @@ elephant() {
check_repo_db() {
local repodir
- # ensure the path to the DB exists
- if [[ "$LOCKFILE" == /* ]]; then
- repodir=${LOCKFILE%/*}/
- else
- repodir=$PWD/$LOCKFILE
- repodir=${repodir%/*}/
- fi
+ # ensure the path to the DB exists; $LOCKFILE is always an absolute path
+ repodir=${LOCKFILE%/*}/
if [[ ! -d $repodir ]]; then
error "$(gettext "%s does not exist or is not a directory.")" "$repodir"
@@ -579,7 +584,7 @@ if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then
exit 1
fi
-tmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
+tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/repo-tools.XXXXXXXXXX") || (\
error "$(gettext "Cannot create temp directory for database building.")"; \
exit 1)
mkdir "$tmpdir/tree"
@@ -637,7 +642,11 @@ if [[ -z $REPO_DB_FILE ]]; then
exit 1
fi
-LOCKFILE=$REPO_DB_FILE.lck
+if [[ $REPO_DB_FILE == /* ]]; then
+ LOCKFILE=$REPO_DB_FILE.lck
+else
+ LOCKFILE=$PWD/$REPO_DB_FILE.lck
+fi
verify_repo_extension "$REPO_DB_FILE" >/dev/null
check_repo_db
@@ -654,37 +663,51 @@ if (( success )); then
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
+ # $LOCKFILE is already guaranteed to be absolute so this is safe
+ dirname=${LOCKFILE%/*}
filename=${REPO_DB_FILE##*/}
+ # this ensures we create it on the same filesystem, making moves atomic
+ tempname=$dirname/.tmp.$filename
pushd "$tmpdir/tree" >/dev/null
if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
- bsdtar -c${TAR_OPT}f "$tmpdir/$filename" *
+ bsdtar -c${TAR_OPT}f "$tempname" *
else
# we have no packages remaining? zip up some emptyness
warning "$(gettext "No packages remain, creating empty database.")"
- bsdtar -c${TAR_OPT}f "$tmpdir/$filename" -T /dev/null
+ bsdtar -c${TAR_OPT}f "$tempname" -T /dev/null
fi
popd >/dev/null
- create_signature "$tmpdir/$filename"
+ create_signature "$tempname"
- [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ # hardlink or move the previous version of the database and signature to .old
+ # extension as a backup measure
+ if [[ -f $REPO_DB_FILE ]]; then
+ ln -f "$REPO_DB_FILE" "$REPO_DB_FILE.old" 2>/dev/null || \
+ mv -f "$REPO_DB_FILE" "$REPO_DB_FILE.old"
+ fi
if [[ -f $REPO_DB_FILE.sig ]]; then
- mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
+ ln -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig" 2>/dev/null || \
+ mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
else
rm -f "$REPO_DB_FILE.old.sig"
fi
- [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
- [[ -f $tmpdir/$filename.sig ]] && mv "$tmpdir/$filename.sig" "$REPO_DB_FILE.sig"
+
+ # rotate the newly-created database and signature into place
+ mv "$tempname" "$REPO_DB_FILE"
+ if [[ -f $tempname.sig ]]; then
+ mv "$tempname.sig" "$REPO_DB_FILE.sig"
+ fi
+
dblink=${REPO_DB_FILE%.tar*}
- target=${REPO_DB_FILE##*/}
rm -f "$dblink" "$dblink.sig"
- ln -s "$target" "$dblink" 2>/dev/null || \
- ln "$target" "$dblink" 2>/dev/null || \
+ ln -s "$filename" "$dblink" 2>/dev/null || \
+ ln "$filename" "$dblink" 2>/dev/null || \
cp "$REPO_DB_FILE" "$dblink"
if [[ -f "$REPO_DB_FILE.sig" ]]; then
- ln -s "$target.sig" "$dblink.sig" 2>/dev/null || \
- ln "$target.sig" "$dblink.sig" 2>/dev/null || \
+ ln -s "$filename.sig" "$dblink.sig" 2>/dev/null || \
+ ln "$filename.sig" "$dblink.sig" 2>/dev/null || \
cp "$REPO_DB_FILE.sig" "$dblink.sig"
fi
else