2011-06-30 11:07:54 -04:00
|
|
|
#!/bin/bash
|
2007-01-30 19:38:13 -05:00
|
|
|
#
|
2007-05-30 11:04:49 -04:00
|
|
|
# repo-add - add a package to a given repo database file
|
2008-06-14 12:29:29 -04:00
|
|
|
# repo-remove - remove a package entry from a given repo database file
|
2007-05-30 11:04:49 -04:00
|
|
|
# @configure_input@
|
|
|
|
#
|
2015-01-21 01:31:20 -05:00
|
|
|
# Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org>
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# 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.
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# 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.
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2011-06-20 15:01:23 -04:00
|
|
|
shopt -s extglob
|
|
|
|
|
2007-06-04 01:21:14 -04:00
|
|
|
# gettext initialization
|
2011-06-23 22:21:51 -04:00
|
|
|
export TEXTDOMAIN='pacman-scripts'
|
2007-06-04 01:21:14 -04:00
|
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
|
2011-12-06 16:29:33 -05:00
|
|
|
declare -r myver='@PACKAGE_VERSION@'
|
|
|
|
declare -r confdir='@sysconfdir@'
|
2007-01-30 19:38:13 -05:00
|
|
|
|
2008-05-09 20:26:57 -04:00
|
|
|
QUIET=0
|
2010-10-11 11:08:00 -04:00
|
|
|
DELTA=0
|
2012-12-13 09:53:37 -05:00
|
|
|
ONLYADDNEW=0
|
2013-06-03 01:05:10 -04:00
|
|
|
RMEXISTING=0
|
2011-01-11 17:04:20 -05:00
|
|
|
WITHFILES=0
|
2009-08-24 14:23:44 -04:00
|
|
|
SIGN=0
|
2015-01-23 00:16:55 -05:00
|
|
|
KEY=0
|
2009-08-24 17:52:23 -04:00
|
|
|
VERIFY=0
|
2009-03-03 11:05:14 -05:00
|
|
|
REPO_DB_FILE=
|
|
|
|
LOCKFILE=
|
|
|
|
CLEAN_LOCK=0
|
2013-03-04 03:33:42 -05:00
|
|
|
USE_COLOR='y'
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2008-01-13 05:08:59 -05:00
|
|
|
# ensure we have a sane umask set
|
|
|
|
umask 0022
|
|
|
|
|
2011-06-09 06:43:25 -04:00
|
|
|
m4_include(library/output_format.sh)
|
2007-08-29 05:49:24 -04:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# print usage instructions
|
|
|
|
usage() {
|
2011-06-20 10:32:12 -04:00
|
|
|
cmd=${0##*/}
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "%s (pacman) %s\n\n" "$cmd" "$myver"
|
2011-03-27 22:04:40 -04:00
|
|
|
if [[ $cmd == "repo-add" ]] ; then
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext "Usage: repo-add [options] <path-to-db> <package|delta> ...\n")"
|
|
|
|
printf -- "\n"
|
|
|
|
printf -- "$(gettext "\
|
2007-07-06 19:35:32 -04:00
|
|
|
repo-add will update a package database by reading a package file.\n\
|
2012-01-12 10:32:19 -05:00
|
|
|
Multiple packages to add can be specified on the command line.\n")"
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "\n"
|
|
|
|
printf -- "$(gettext "Options:\n")"
|
|
|
|
printf -- "$(gettext " -d, --delta generate and add delta for package update\n")"
|
2012-12-13 09:53:37 -05:00
|
|
|
printf -- "$(gettext " -n, --new only add packages that are not already in the database\n")"
|
2015-01-22 23:08:04 -05:00
|
|
|
printf -- "$(gettext " -R, --remove remove old package file from disk after updating database\n")"
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext " -f, --files update database's file list\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
elif [[ $cmd == "repo-remove" ]] ; then
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")"
|
|
|
|
printf -- "\n"
|
|
|
|
printf -- "$(gettext "\
|
2008-06-14 12:29:29 -04:00
|
|
|
repo-remove will update a package database by removing the package name\n\
|
|
|
|
specified on the command line from the given repo database. Multiple\n\
|
2012-01-12 10:32:19 -05:00
|
|
|
packages to remove can be specified on the command line.\n")"
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "\n"
|
|
|
|
printf -- "$(gettext "Options:\n")"
|
2012-01-12 10:32:19 -05:00
|
|
|
else
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext "Please move along, there is nothing to see here.\n")"
|
2012-01-12 10:32:19 -05:00
|
|
|
return
|
2011-03-27 22:04:40 -04:00
|
|
|
fi
|
2013-03-04 03:33:42 -05:00
|
|
|
printf -- "$(gettext " --nocolor turn off color in output\n")"
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext " -q, --quiet minimize output\n")"
|
|
|
|
printf -- "$(gettext " -s, --sign sign database with GnuPG after update\n")"
|
|
|
|
printf -- "$(gettext " -k, --key <key> use the specified key to sign the database\n")"
|
|
|
|
printf -- "$(gettext " -v, --verify verify database's signature before update\n")"
|
|
|
|
printf -- "$(gettext "\n\
|
2012-01-12 10:32:19 -05:00
|
|
|
See %s(8) for more details and descriptions of the available options.\n")" $cmd
|
|
|
|
printf "\n"
|
2011-03-27 22:04:40 -04:00
|
|
|
if [[ $cmd == "repo-add" ]] ; then
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
elif [[ $cmd == "repo-remove" ]] ; then
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
fi
|
2007-01-30 19:38:13 -05:00
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-04-11 17:02:56 -04:00
|
|
|
version() {
|
2011-06-20 10:32:12 -04:00
|
|
|
cmd=${0##*/}
|
2011-03-27 22:04:40 -04:00
|
|
|
printf "%s (pacman) %s\n\n" "$cmd" "$myver"
|
2012-01-23 17:14:25 -05:00
|
|
|
printf -- "$(gettext "\
|
2015-01-21 01:31:20 -05:00
|
|
|
Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org>\n\n\
|
2007-07-06 19:35:32 -04:00
|
|
|
This is free software; see the source for copying conditions.\n\
|
|
|
|
There is NO WARRANTY, to the extent permitted by law.\n")"
|
2007-04-11 17:02:56 -04:00
|
|
|
}
|
|
|
|
|
2011-06-20 15:12:01 -04:00
|
|
|
# format a metadata entry
|
2007-08-29 05:49:24 -04:00
|
|
|
# arg1 - Entry name
|
2011-06-20 15:12:01 -04:00
|
|
|
# ... - value(s)
|
|
|
|
format_entry() {
|
|
|
|
local field=$1; shift
|
|
|
|
|
|
|
|
if [[ $1 ]]; then
|
|
|
|
printf '%%%s%%\n' "$field"
|
|
|
|
printf '%s\n' "$@"
|
|
|
|
printf '\n'
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2011-06-20 16:38:57 -04:00
|
|
|
find_pkgentry() {
|
2009-02-26 14:02:05 -05:00
|
|
|
local pkgname=$1
|
|
|
|
local pkgentry
|
2012-04-07 08:18:28 -04:00
|
|
|
for pkgentry in "$tmpdir/tree/$pkgname"*; do
|
2009-02-26 14:02:05 -05:00
|
|
|
name=${pkgentry##*/}
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ${name%-*-*} = $pkgname ]]; then
|
2009-02-26 14:02:05 -05:00
|
|
|
echo $pkgentry
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2009-02-25 13:06:16 -05:00
|
|
|
# Get the package name from the delta filename
|
|
|
|
get_delta_pkgname() {
|
|
|
|
local tmp
|
|
|
|
|
|
|
|
tmp=${1##*/}
|
|
|
|
echo ${tmp%-*-*_to*}
|
|
|
|
}
|
|
|
|
|
|
|
|
# write a delta entry
|
|
|
|
# arg1 - path to delta file
|
2011-06-20 16:38:57 -04:00
|
|
|
db_write_delta() {
|
2012-04-07 08:18:28 -04:00
|
|
|
deltafile=$1
|
|
|
|
pkgname=$(get_delta_pkgname "$deltafile")
|
2009-02-25 13:06:16 -05:00
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
pkgentry=$(find_pkgentry "$pkgname")
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -z $pkgentry ]]; then
|
2010-10-11 12:28:35 -04:00
|
|
|
error "$(gettext "No database entry for package '%s'.")" "$pkgname"
|
2009-02-25 13:06:16 -05:00
|
|
|
return 1
|
|
|
|
fi
|
2012-04-07 08:18:28 -04:00
|
|
|
deltas=$pkgentry/deltas
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ! -f $deltas ]]; then
|
2012-04-07 08:18:28 -04:00
|
|
|
echo -e "%DELTAS%" >"$deltas"
|
2009-02-25 13:06:16 -05:00
|
|
|
fi
|
|
|
|
# get md5sum and compressed size of package
|
2012-04-07 08:18:28 -04:00
|
|
|
md5sum=$(openssl dgst -md5 "$deltafile")
|
|
|
|
md5sum=${md5sum##* }
|
2012-02-24 06:40:20 -05:00
|
|
|
csize=$(@SIZECMD@ -L "$deltafile")
|
2009-02-25 13:06:16 -05:00
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
oldfile=$(xdelta3 printhdr "$deltafile" | grep "XDELTA filename (source)" | sed 's/.*: *//')
|
|
|
|
newfile=$(xdelta3 printhdr "$deltafile" | grep "XDELTA filename (output)" | sed 's/.*: *//')
|
2009-02-25 13:06:16 -05:00
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
if grep -q "$oldfile.*$newfile" "$deltas"; then
|
|
|
|
sed -i.backup "/$oldfile.*$newfile/d" "$deltas" && rm -f "$deltas.backup"
|
2009-02-25 13:06:16 -05:00
|
|
|
fi
|
2010-10-11 12:28:35 -04:00
|
|
|
msg2 "$(gettext "Adding 'deltas' entry : %s -> %s")" "$oldfile" "$newfile"
|
2012-04-07 08:18:28 -04:00
|
|
|
echo "${deltafile##*/} $md5sum $csize $oldfile $newfile" >> "$deltas"
|
2009-02-25 13:06:16 -05:00
|
|
|
|
|
|
|
return 0
|
|
|
|
} # end db_write_delta
|
|
|
|
|
|
|
|
# remove a delta entry
|
|
|
|
# arg1 - path to delta file
|
2011-06-20 16:38:57 -04:00
|
|
|
db_remove_delta() {
|
2012-04-07 08:18:28 -04:00
|
|
|
deltafile=$1
|
2009-02-25 13:06:16 -05:00
|
|
|
filename=${deltafile##*/}
|
2012-04-07 08:18:28 -04:00
|
|
|
pkgname=$(get_delta_pkgname "$deltafile")
|
2009-02-25 13:06:16 -05:00
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
pkgentry=$(find_pkgentry "$pkgname")
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -z $pkgentry ]]; then
|
2009-02-25 13:06:16 -05:00
|
|
|
return 1
|
|
|
|
fi
|
2012-04-07 08:18:28 -04:00
|
|
|
deltas=$pkgentry/deltas
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ! -f $deltas ]]; then
|
2009-02-25 13:06:16 -05:00
|
|
|
return 1
|
|
|
|
fi
|
2012-04-07 08:18:28 -04:00
|
|
|
if grep -q "$filename" "$deltas"; then
|
|
|
|
sed -i.backup "/$filename/d" "$deltas" && rm -f "$deltas.backup"
|
2009-02-25 13:06:16 -05:00
|
|
|
msg2 "$(gettext "Removing existing entry '%s'...")" "$filename"
|
2012-04-06 12:17:06 -04:00
|
|
|
# empty deltas file contains only "%DELTAS%"
|
|
|
|
if (( $(wc -l < "$deltas") == 1 )); then
|
|
|
|
msg2 "$(gettext "Removing empty deltas file ...")"
|
|
|
|
rm "$deltas"
|
|
|
|
fi
|
2009-02-25 13:06:16 -05:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
} # end db_remove_delta
|
|
|
|
|
2011-04-24 06:56:59 -04:00
|
|
|
check_gpg() {
|
|
|
|
if ! type -p gpg >/dev/null; then
|
2011-08-08 20:01:26 -04:00
|
|
|
error "$(gettext "Cannot find the gpg binary! Is GnuPG installed?")"
|
2011-04-24 06:56:59 -04:00
|
|
|
exit 1 # $E_MISSING_PROGRAM
|
|
|
|
fi
|
2015-01-23 00:16:55 -05:00
|
|
|
|
|
|
|
if (( ! VERIFY )); then
|
|
|
|
if ! gpg --list-key ${GPGKEY} &>/dev/null; then
|
|
|
|
if [[ ! -z $GPGKEY ]]; then
|
|
|
|
error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
|
|
|
|
elif (( ! KEY )); then
|
|
|
|
error "$(gettext "There is no key in your keyring.")"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2011-04-24 06:56:59 -04:00
|
|
|
}
|
|
|
|
|
2009-08-24 14:23:44 -04:00
|
|
|
# sign the package database once repackaged
|
|
|
|
create_signature() {
|
|
|
|
(( ! SIGN )) && return
|
2012-04-07 08:18:28 -04:00
|
|
|
local dbfile=$1
|
2009-08-24 14:23:44 -04:00
|
|
|
local ret=0
|
|
|
|
msg "$(gettext "Signing database...")"
|
2011-04-24 06:48:08 -04:00
|
|
|
|
|
|
|
local SIGNWITHKEY=""
|
|
|
|
if [[ -n $GPGKEY ]]; then
|
|
|
|
SIGNWITHKEY="-u ${GPGKEY}"
|
|
|
|
fi
|
|
|
|
gpg --detach-sign --use-agent ${SIGNWITHKEY} "$dbfile" &>/dev/null || ret=$?
|
|
|
|
|
2009-08-24 14:23:44 -04:00
|
|
|
if (( ! ret )); then
|
2012-09-24 23:59:30 -04:00
|
|
|
msg2 "$(gettext "Created signature file '%s'")" "${dbfile##*/.tmp.}.sig"
|
2009-08-24 14:23:44 -04:00
|
|
|
else
|
|
|
|
warning "$(gettext "Failed to sign package database.")"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-08-24 17:52:23 -04:00
|
|
|
# verify the existing package database signature
|
|
|
|
verify_signature() {
|
|
|
|
(( ! VERIFY )) && return
|
2012-04-07 08:18:28 -04:00
|
|
|
local dbfile=$1
|
2009-08-24 17:52:23 -04:00
|
|
|
local ret=0
|
|
|
|
msg "$(gettext "Verifying database signature...")"
|
2011-04-24 06:56:59 -04:00
|
|
|
|
2009-08-24 17:52:23 -04:00
|
|
|
if [[ ! -f $dbfile.sig ]]; then
|
|
|
|
warning "$(gettext "No existing signature found, skipping verification.")"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
gpg --verify "$dbfile.sig" || ret=$?
|
|
|
|
if (( ! ret )); then
|
|
|
|
msg2 "$(gettext "Database signature file verified.")"
|
|
|
|
else
|
|
|
|
error "$(gettext "Database signature was NOT valid!")"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-06-21 13:58:32 -04:00
|
|
|
verify_repo_extension() {
|
|
|
|
local repofile=$1
|
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
case $repofile in
|
2011-06-21 13:58:32 -04:00
|
|
|
*.@(db|files).tar.gz) TAR_OPT="z" ;;
|
|
|
|
*.@(db|files).tar.bz2) TAR_OPT="j" ;;
|
|
|
|
*.@(db|files).tar.xz) TAR_OPT="J" ;;
|
2011-07-14 15:58:46 -04:00
|
|
|
*.@(db|files).tar.Z) TAR_OPT="Z" ;;
|
2011-06-21 13:58:32 -04:00
|
|
|
*.@(db|files).tar) TAR_OPT="" ;;
|
2015-01-22 23:48:16 -05:00
|
|
|
*) error "$(gettext "'%s' does not have a valid database archive extension.")" \
|
2011-06-21 13:58:32 -04:00
|
|
|
"$repofile"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
printf '%s' "$TAR_OPT"
|
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# write an entry to the pacman database
|
|
|
|
# arg1 - path to package
|
2011-06-20 16:38:57 -04:00
|
|
|
db_write_entry() {
|
2009-02-18 11:15:39 -05:00
|
|
|
# blank out all variables
|
2012-04-07 08:18:28 -04:00
|
|
|
local pkgfile=$1
|
2012-05-19 07:00:18 -04:00
|
|
|
local -a _groups _licenses _replaces _depends _conflicts _provides \
|
2012-06-07 02:21:05 -04:00
|
|
|
_optdepends _makedepends _checkdepends
|
2014-03-27 01:46:07 -04:00
|
|
|
local pkgname pkgbase pkgver pkgdesc csize size url arch builddate packager \
|
2011-12-05 11:07:40 -05:00
|
|
|
md5sum sha256sum pgpsig pgpsigsize
|
2007-08-29 05:49:24 -04:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# read info from the zipped package
|
2009-02-08 13:21:49 -05:00
|
|
|
local line var val
|
2011-06-20 15:01:23 -04:00
|
|
|
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:]])/ }"
|
2012-04-07 08:18:28 -04:00
|
|
|
case $var in
|
2012-05-19 07:00:18 -04:00
|
|
|
group) _groups+=("$group") ;;
|
|
|
|
license) _licenses+=("$license") ;;
|
|
|
|
replaces) _replaces+=("$replaces") ;;
|
|
|
|
depend) _depends+=("$depend") ;;
|
|
|
|
conflict) _conflicts+=("$conflict") ;;
|
|
|
|
provides) _provides+=("$provides") ;;
|
2011-06-20 15:12:01 -04:00
|
|
|
optdepend) _optdepends+=("$optdepend") ;;
|
2012-05-19 07:00:18 -04:00
|
|
|
makedepend) _makedepends+=("$makedepend") ;;
|
2012-06-07 02:21:05 -04:00
|
|
|
checkdepend) _checkdepends+=("$checkdepend") ;;
|
2006-12-20 20:53:40 -05:00
|
|
|
esac
|
2011-06-20 15:01:23 -04:00
|
|
|
done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# ensure $pkgname and $pkgver variables were found
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -z $pkgname || -z $pkgver ]]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
|
2006-12-20 20:53:40 -05:00
|
|
|
return 1
|
2007-05-30 11:04:49 -04:00
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2011-08-15 09:05:59 -04:00
|
|
|
if [[ -d $tmpdir/tree/$pkgname-$pkgver ]]; then
|
2009-02-26 12:00:15 -05:00
|
|
|
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
|
2012-12-13 09:53:37 -05:00
|
|
|
if (( ONLYADDNEW )); then
|
|
|
|
return 0;
|
|
|
|
fi
|
2010-10-11 11:08:00 -04:00
|
|
|
else
|
2011-01-22 09:13:24 -05:00
|
|
|
if (( DELTA )); then
|
2012-04-07 08:18:28 -04:00
|
|
|
pkgentry=$(find_pkgentry "$pkgname")
|
2011-01-22 09:13:24 -05:00
|
|
|
if [[ -n $pkgentry ]]; then
|
2012-04-07 08:18:28 -04:00
|
|
|
local oldfilename=$(grep -A1 FILENAME "$pkgentry/desc" | tail -n1)
|
|
|
|
local oldfile="$(dirname "$1")/$oldfilename"
|
2010-10-11 11:08:00 -04:00
|
|
|
fi
|
2015-01-22 23:08:04 -05:00
|
|
|
fi
|
|
|
|
if (( RMEXISTING )); then
|
|
|
|
# gather information needed to remove old file
|
2013-06-03 01:05:10 -04:00
|
|
|
pkgentry=$(find_pkgentry "$pkgname")
|
|
|
|
if [[ -n $pkgentry ]]; then
|
|
|
|
local oldfilename="$(sed -n '/^%FILENAME%$/ {n;p;q;}' "$pkgentry/desc")"
|
|
|
|
local oldfile="$(dirname "$1")/$oldfilename"
|
|
|
|
fi
|
2010-10-11 11:08:00 -04:00
|
|
|
fi
|
2009-02-26 12:00:15 -05:00
|
|
|
fi
|
|
|
|
|
2011-12-05 11:07:40 -05:00
|
|
|
# compute base64'd PGP signature
|
|
|
|
if [[ -f "$pkgfile.sig" ]]; then
|
2012-02-24 06:40:20 -05:00
|
|
|
pgpsigsize=$(@SIZECMD@ -L "$pkgfile.sig")
|
2011-12-05 11:07:40 -05:00
|
|
|
if (( pgpsigsize > 16384 )); then
|
|
|
|
error "$(gettext "Invalid package signature file '%s'.")" "$pkgfile.sig"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
msg2 "$(gettext "Adding package signature...")"
|
|
|
|
pgpsig=$(openssl base64 -in "$pkgfile.sig" | tr -d '\n')
|
|
|
|
fi
|
|
|
|
|
2012-02-24 06:40:20 -05:00
|
|
|
csize=$(@SIZECMD@ -L "$pkgfile")
|
2011-08-15 09:05:59 -04:00
|
|
|
|
|
|
|
# compute checksums
|
|
|
|
msg2 "$(gettext "Computing checksums...")"
|
2012-04-07 08:18:28 -04:00
|
|
|
md5sum=$(openssl dgst -md5 "$pkgfile")
|
|
|
|
md5sum=${md5sum##* }
|
|
|
|
sha256sum=$(openssl dgst -sha256 "$pkgfile")
|
|
|
|
sha256sum=${sha256sum##* }
|
2011-08-15 09:05:59 -04:00
|
|
|
|
2009-02-26 12:00:15 -05:00
|
|
|
# remove an existing entry if it exists, ignore failures
|
|
|
|
db_remove_entry "$pkgname"
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create package directory
|
2011-08-15 09:05:59 -04:00
|
|
|
pushd "$tmpdir/tree" >/dev/null
|
2007-01-30 19:38:13 -05:00
|
|
|
mkdir "$pkgname-$pkgver"
|
2011-01-11 16:15:07 -05:00
|
|
|
pushd "$pkgname-$pkgver" >/dev/null
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2009-02-26 14:02:05 -05:00
|
|
|
# restore an eventual deltas file
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas
|
2009-02-26 14:02:05 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create desc entry
|
2011-02-28 18:50:23 -05:00
|
|
|
msg2 "$(gettext "Creating '%s' db entry...")" 'desc'
|
2011-06-20 15:37:09 -04:00
|
|
|
{
|
|
|
|
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'
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create depends entry
|
2011-02-28 18:50:23 -05:00
|
|
|
msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
|
2011-06-20 15:12:01 -04:00
|
|
|
{
|
2012-05-19 07:00:18 -04:00
|
|
|
format_entry "DEPENDS" "${_depends[@]}"
|
|
|
|
format_entry "CONFLICTS" "${_conflicts[@]}"
|
|
|
|
format_entry "PROVIDES" "${_provides[@]}"
|
2011-06-20 15:12:01 -04:00
|
|
|
format_entry "OPTDEPENDS" "${_optdepends[@]}"
|
2012-05-19 07:00:18 -04:00
|
|
|
format_entry "MAKEDEPENDS" "${_makedepends[@]}"
|
2012-06-07 02:21:05 -04:00
|
|
|
format_entry "CHECKDEPENDS" "${_checkdepends[@]}"
|
2011-06-20 15:12:01 -04:00
|
|
|
} >'depends'
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2011-01-11 16:15:07 -05:00
|
|
|
popd >/dev/null
|
|
|
|
popd >/dev/null
|
2009-02-18 11:15:39 -05:00
|
|
|
|
2011-01-11 17:04:20 -05:00
|
|
|
# create files file if wanted
|
|
|
|
if (( WITHFILES )); then
|
2011-02-28 18:50:23 -05:00
|
|
|
msg2 "$(gettext "Creating '%s' db entry...")" 'files'
|
2011-06-28 20:53:12 -04:00
|
|
|
local files_path="$tmpdir/tree/$pkgname-$pkgver/files"
|
2012-04-07 08:18:28 -04:00
|
|
|
echo "%FILES%" >"$files_path"
|
|
|
|
bsdtar --exclude='^.*' -tf "$pkgfile" >>"$files_path"
|
2011-01-11 17:04:20 -05:00
|
|
|
fi
|
|
|
|
|
2010-10-11 11:08:00 -04:00
|
|
|
# create a delta file
|
2011-01-22 09:13:24 -05:00
|
|
|
if (( DELTA )); then
|
|
|
|
if [[ -n $oldfilename ]]; then
|
|
|
|
if [[ -f $oldfile ]]; then
|
2012-04-07 08:18:28 -04:00
|
|
|
delta=$(pkgdelta -q "$oldfile" "$1")
|
2011-01-22 09:13:24 -05:00
|
|
|
if [[ -f $delta ]]; then
|
2012-04-07 08:18:28 -04:00
|
|
|
db_write_delta "$delta"
|
2011-01-22 09:13:24 -05:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
warning "$(gettext "Old package file not found: %s")" "$oldfilename"
|
2011-01-13 10:33:01 -05:00
|
|
|
fi
|
2010-10-11 11:08:00 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-01-22 23:08:04 -05:00
|
|
|
if (( RMEXISTING )); then
|
|
|
|
msg2 "$(gettext "Removing old package file '%s'")" "$oldfilename"
|
|
|
|
rm -f ${oldfile} ${oldfile}.sig
|
|
|
|
fi
|
|
|
|
|
2009-02-18 11:15:39 -05:00
|
|
|
return 0
|
2007-01-30 19:38:13 -05:00
|
|
|
} # end db_write_entry
|
|
|
|
|
2008-06-14 12:29:29 -04:00
|
|
|
# remove existing entries from the DB
|
|
|
|
# arg1 - package name
|
|
|
|
db_remove_entry() {
|
2009-02-26 14:02:05 -05:00
|
|
|
local pkgname=$1
|
|
|
|
local notfound=1
|
2012-04-07 08:18:28 -04:00
|
|
|
local pkgentry=$(find_pkgentry "$pkgname")
|
2009-11-05 10:55:48 -05:00
|
|
|
while [[ -n $pkgentry ]]; do
|
2009-02-26 14:02:05 -05:00
|
|
|
notfound=0
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -f $pkgentry/deltas ]]; then
|
2011-06-28 20:53:12 -04:00
|
|
|
mv "$pkgentry/deltas" "$tmpdir/tree/$pkgname.deltas"
|
2008-06-14 12:29:29 -04:00
|
|
|
fi
|
2009-02-25 13:06:16 -05:00
|
|
|
msg2 "$(gettext "Removing existing entry '%s'...")" \
|
2011-06-20 10:32:12 -04:00
|
|
|
"${pkgentry##*/}"
|
2012-04-07 08:18:28 -04:00
|
|
|
rm -rf "$pkgentry"
|
|
|
|
pkgentry=$(find_pkgentry "$pkgname")
|
2008-06-14 12:29:29 -04:00
|
|
|
done
|
2009-02-26 14:02:05 -05:00
|
|
|
return $notfound
|
2008-06-14 12:29:29 -04:00
|
|
|
} # end db_remove_entry
|
|
|
|
|
2011-06-24 15:19:36 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-06-20 16:38:57 -04:00
|
|
|
check_repo_db() {
|
2011-06-22 09:30:35 -04:00
|
|
|
local repodir
|
|
|
|
|
2011-11-15 23:16:41 -05:00
|
|
|
# ensure the path to the DB exists; $LOCKFILE is always an absolute path
|
|
|
|
repodir=${LOCKFILE%/*}/
|
2011-06-22 09:30:35 -04:00
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
if [[ ! -d $repodir ]]; then
|
2011-06-22 09:30:35 -04:00
|
|
|
error "$(gettext "%s does not exist or is not a directory.")" "$repodir"
|
2011-06-20 11:05:08 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-03-03 11:05:14 -05:00
|
|
|
# check lock file
|
|
|
|
if ( set -o noclobber; echo "$$" > "$LOCKFILE") 2> /dev/null; then
|
|
|
|
CLEAN_LOCK=1
|
|
|
|
else
|
|
|
|
error "$(gettext "Failed to acquire lockfile: %s.")" "$LOCKFILE"
|
2012-04-07 08:18:28 -04:00
|
|
|
[[ -f $LOCKFILE ]] && error "$(gettext "Held by process %s")" "$(cat "$LOCKFILE")"
|
2009-03-03 11:05:14 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -f $REPO_DB_FILE ]]; then
|
2009-09-23 22:15:53 -04:00
|
|
|
# there are two situations we can have here- a DB with some entries,
|
|
|
|
# or a DB with no contents at all.
|
|
|
|
if ! bsdtar -tqf "$REPO_DB_FILE" '*/desc' >/dev/null 2>&1; then
|
|
|
|
# check empty case
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -n $(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null) ]]; then
|
2009-09-23 22:15:53 -04:00
|
|
|
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-02-26 13:23:33 -05:00
|
|
|
fi
|
2009-08-24 17:52:23 -04:00
|
|
|
verify_signature "$REPO_DB_FILE"
|
2009-02-26 13:23:33 -05:00
|
|
|
msg "$(gettext "Extracting database to a temporary location...")"
|
2011-06-28 20:53:12 -04:00
|
|
|
bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir/tree"
|
2009-02-26 13:23:33 -05:00
|
|
|
else
|
2012-04-07 08:18:28 -04:00
|
|
|
case $cmd in
|
2009-02-26 12:16:23 -05:00
|
|
|
repo-remove)
|
2009-02-26 13:23:33 -05:00
|
|
|
error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
|
|
|
|
exit 1
|
2009-02-26 12:16:23 -05:00
|
|
|
;;
|
|
|
|
repo-add)
|
|
|
|
# check if the file can be created (write permission, directory existence, etc)
|
|
|
|
if ! touch "$REPO_DB_FILE"; then
|
|
|
|
error "$(gettext "Repository file '%s' could not be created.")" "$REPO_DB_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rm -f "$REPO_DB_FILE"
|
|
|
|
;;
|
|
|
|
esac
|
2009-02-26 13:23:33 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-06-20 16:38:57 -04:00
|
|
|
add() {
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ! -f $1 ]]; then
|
2009-02-25 13:06:16 -05:00
|
|
|
error "$(gettext "File '%s' not found.")" "$1"
|
2009-02-26 13:23:33 -05:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ${1##*.} == "delta" ]]; then
|
2009-02-25 13:06:16 -05:00
|
|
|
deltafile=$1
|
|
|
|
msg "$(gettext "Adding delta '%s'")" "$deltafile"
|
2009-11-05 10:55:48 -05:00
|
|
|
if ! type xdelta3 &>/dev/null; then
|
2009-02-25 13:06:16 -05:00
|
|
|
error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if db_write_delta "$deltafile"; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
pkgfile=$1
|
2009-05-12 04:59:34 -04:00
|
|
|
if ! bsdtar -tqf "$pkgfile" .PKGINFO >/dev/null 2>&1; then
|
2009-02-26 13:23:33 -05:00
|
|
|
error "$(gettext "'%s' is not a package file, skipping")" "$pkgfile"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
msg "$(gettext "Adding package '%s'")" "$pkgfile"
|
|
|
|
|
|
|
|
db_write_entry "$pkgfile"
|
|
|
|
}
|
|
|
|
|
2011-06-20 16:38:57 -04:00
|
|
|
remove() {
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ${1##*.} == "delta" ]]; then
|
2009-02-25 13:06:16 -05:00
|
|
|
deltafile=$1
|
|
|
|
msg "$(gettext "Searching for delta '%s'...")" "$deltafile"
|
|
|
|
if db_remove_delta "$deltafile"; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
error "$(gettext "Delta matching '%s' not found.")" "$deltafile"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2009-02-26 14:02:05 -05:00
|
|
|
pkgname=$1
|
|
|
|
msg "$(gettext "Searching for package '%s'...")" "$pkgname"
|
2009-02-26 13:23:33 -05:00
|
|
|
|
2009-02-26 14:02:05 -05:00
|
|
|
if db_remove_entry "$pkgname"; then
|
2011-06-28 20:53:12 -04:00
|
|
|
rm -f "$tmpdir/tree/$pkgname.deltas"
|
2009-02-26 14:02:05 -05:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
error "$(gettext "Package matching '%s' not found.")" "$pkgname"
|
|
|
|
return 1
|
|
|
|
fi
|
2009-02-26 13:23:33 -05:00
|
|
|
}
|
|
|
|
|
2011-06-20 16:38:57 -04:00
|
|
|
trap_exit() {
|
2011-10-13 11:23:19 -04:00
|
|
|
# unhook all traps to avoid race conditions
|
|
|
|
trap '' EXIT TERM HUP QUIT INT ERR
|
|
|
|
|
2009-03-03 11:05:14 -05:00
|
|
|
echo
|
|
|
|
error "$@"
|
2011-10-13 11:23:19 -04:00
|
|
|
clean_up 1
|
2009-03-03 11:05:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
clean_up() {
|
2011-10-13 11:23:19 -04:00
|
|
|
local exit_code=${1:-$?}
|
|
|
|
|
|
|
|
# unhook all traps to avoid race conditions
|
|
|
|
trap '' EXIT TERM HUP QUIT INT ERR
|
2009-03-03 11:05:14 -05:00
|
|
|
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -d $tmpdir ]] && rm -rf "$tmpdir"
|
|
|
|
(( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE"
|
2009-03-03 11:05:14 -05:00
|
|
|
|
|
|
|
exit $exit_code
|
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# PROGRAM START
|
|
|
|
|
2008-02-17 22:15:06 -05:00
|
|
|
# determine whether we have gettext; make it a no-op if we do not
|
2009-11-05 10:55:48 -05:00
|
|
|
if ! type gettext &>/dev/null; then
|
2008-02-17 22:15:06 -05:00
|
|
|
gettext() {
|
|
|
|
echo "$@"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
case $1 in
|
2009-02-26 13:23:33 -05:00
|
|
|
-h|--help) usage; exit 0;;
|
|
|
|
-V|--version) version; exit 0;;
|
|
|
|
esac
|
2007-04-11 17:02:56 -04:00
|
|
|
|
2008-06-14 12:29:29 -04:00
|
|
|
# figure out what program we are
|
2011-06-20 10:32:12 -04:00
|
|
|
cmd=${0##*/}
|
2011-06-24 15:19:36 -04:00
|
|
|
if [[ $cmd == "repo-elephant" ]]; then
|
|
|
|
elephant
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then
|
2008-06-14 12:29:29 -04:00
|
|
|
error "$(gettext "Invalid command name '%s' specified.")" "$cmd"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-10-13 11:23:21 -04:00
|
|
|
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/repo-tools.XXXXXXXXXX") || (\
|
2009-03-03 11:05:14 -05:00
|
|
|
error "$(gettext "Cannot create temp directory for database building.")"; \
|
|
|
|
exit 1)
|
2012-04-07 08:18:28 -04:00
|
|
|
mkdir "$tmpdir/tree"
|
2009-03-03 11:05:14 -05:00
|
|
|
|
|
|
|
trap 'clean_up' EXIT
|
2011-10-13 11:23:20 -04:00
|
|
|
for signal in TERM HUP QUIT; do
|
|
|
|
trap "trap_exit \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal"
|
|
|
|
done
|
2009-03-03 11:05:14 -05:00
|
|
|
trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
|
2011-10-13 11:23:20 -04:00
|
|
|
trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
|
2009-03-03 11:05:14 -05:00
|
|
|
|
2011-06-22 16:26:55 -04:00
|
|
|
declare -a args
|
2007-08-29 05:49:24 -04:00
|
|
|
success=0
|
2008-01-14 00:26:31 -05:00
|
|
|
# parse arguments
|
2011-06-22 16:26:55 -04:00
|
|
|
while (( $# )); do
|
2012-04-07 08:18:28 -04:00
|
|
|
case $1 in
|
2009-02-26 13:23:33 -05:00
|
|
|
-q|--quiet) QUIET=1;;
|
2010-10-11 11:08:00 -04:00
|
|
|
-d|--delta) DELTA=1;;
|
2012-12-13 09:53:37 -05:00
|
|
|
-n|--new) ONLYADDNEW=1;;
|
2013-06-03 01:05:10 -04:00
|
|
|
-R|--remove) RMEXISTING=1;;
|
2011-01-11 17:04:20 -05:00
|
|
|
-f|--files) WITHFILES=1;;
|
2013-03-04 03:33:42 -05:00
|
|
|
--nocolor) USE_COLOR='n';;
|
2011-04-24 06:51:53 -04:00
|
|
|
-s|--sign)
|
|
|
|
SIGN=1
|
|
|
|
;;
|
2011-04-24 06:48:08 -04:00
|
|
|
-k|--key)
|
2015-01-23 00:16:55 -05:00
|
|
|
KEY=1
|
2011-04-24 06:48:08 -04:00
|
|
|
shift
|
2012-04-07 08:18:28 -04:00
|
|
|
GPGKEY=$1
|
2011-04-24 06:48:08 -04:00
|
|
|
;;
|
2011-04-24 06:56:59 -04:00
|
|
|
-v|--verify)
|
|
|
|
VERIFY=1
|
|
|
|
;;
|
2009-02-26 13:23:33 -05:00
|
|
|
*)
|
2011-06-22 16:26:55 -04:00
|
|
|
args+=("$1")
|
2009-02-26 13:23:33 -05:00
|
|
|
;;
|
|
|
|
esac
|
2011-04-24 06:48:08 -04:00
|
|
|
shift
|
2007-08-29 05:49:24 -04:00
|
|
|
done
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2013-03-04 03:33:42 -05:00
|
|
|
m4_include(library/term_colors.sh)
|
|
|
|
|
2011-06-22 16:26:55 -04:00
|
|
|
REPO_DB_FILE=${args[0]}
|
2011-07-28 13:07:25 -04:00
|
|
|
if [[ -z $REPO_DB_FILE ]]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-11-15 23:16:41 -05:00
|
|
|
if [[ $REPO_DB_FILE == /* ]]; then
|
|
|
|
LOCKFILE=$REPO_DB_FILE.lck
|
|
|
|
else
|
|
|
|
LOCKFILE=$PWD/$REPO_DB_FILE.lck
|
|
|
|
fi
|
2011-06-21 13:58:32 -04:00
|
|
|
|
|
|
|
verify_repo_extension "$REPO_DB_FILE" >/dev/null
|
2011-06-22 16:26:55 -04:00
|
|
|
check_repo_db
|
|
|
|
|
2015-01-23 00:16:55 -05:00
|
|
|
if (( SIGN || KEY || VERIFY )); then
|
|
|
|
check_gpg
|
|
|
|
fi
|
|
|
|
|
2011-06-22 16:26:55 -04:00
|
|
|
for arg in "${args[@]:1}"; do
|
2012-04-07 08:18:28 -04:00
|
|
|
case $cmd in
|
2011-06-22 16:26:55 -04:00
|
|
|
repo-add) add "$arg" ;;
|
|
|
|
repo-remove) remove "$arg" ;;
|
|
|
|
esac && success=1
|
|
|
|
done
|
|
|
|
|
2009-02-26 13:23:33 -05:00
|
|
|
# if at least one operation was a success, re-zip database
|
2009-11-05 10:55:48 -05:00
|
|
|
if (( success )); then
|
2008-06-14 11:48:28 -04:00
|
|
|
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
|
2007-08-29 05:49:24 -04:00
|
|
|
|
2011-06-21 13:58:32 -04:00
|
|
|
TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
# $LOCKFILE is already guaranteed to be absolute so this is safe
|
|
|
|
dirname=${LOCKFILE%/*}
|
2011-06-20 10:32:12 -04:00
|
|
|
filename=${REPO_DB_FILE##*/}
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
# this ensures we create it on the same filesystem, making moves atomic
|
2012-04-07 08:18:28 -04:00
|
|
|
tempname=$dirname/.tmp.$filename
|
2007-08-29 05:49:24 -04:00
|
|
|
|
2011-06-28 20:53:12 -04:00
|
|
|
pushd "$tmpdir/tree" >/dev/null
|
2011-06-28 21:32:40 -04:00
|
|
|
if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
bsdtar -c${TAR_OPT}f "$tempname" *
|
2011-06-28 21:32:40 -04:00
|
|
|
else
|
|
|
|
# we have no packages remaining? zip up some emptyness
|
|
|
|
warning "$(gettext "No packages remain, creating empty database.")"
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
bsdtar -c${TAR_OPT}f "$tempname" -T /dev/null
|
2011-06-28 21:32:40 -04:00
|
|
|
fi
|
2011-01-11 16:15:07 -05:00
|
|
|
popd >/dev/null
|
2009-02-18 10:39:31 -05:00
|
|
|
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
create_signature "$tempname"
|
2011-06-28 20:53:12 -04:00
|
|
|
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
# 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
|
2011-07-04 11:28:27 -04:00
|
|
|
if [[ -f $REPO_DB_FILE.sig ]]; then
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
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"
|
2011-07-04 11:28:27 -04:00
|
|
|
else
|
|
|
|
rm -f "$REPO_DB_FILE.old.sig"
|
|
|
|
fi
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2012-04-07 08:18:28 -04:00
|
|
|
dblink=${REPO_DB_FILE%.tar*}
|
2011-07-18 07:05:51 -04:00
|
|
|
rm -f "$dblink" "$dblink.sig"
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
ln -s "$filename" "$dblink" 2>/dev/null || \
|
|
|
|
ln "$filename" "$dblink" 2>/dev/null || \
|
2010-06-24 11:06:36 -04:00
|
|
|
cp "$REPO_DB_FILE" "$dblink"
|
2011-08-15 23:55:00 -04:00
|
|
|
if [[ -f "$REPO_DB_FILE.sig" ]]; then
|
repo-add: ensure database and signature files are always viewed in whole
This addresses a short but sweet race condition currently existing in
repo-add and repo-remove. We do the smart thing and zip the database to
a location in a temporary directory and not over the original database
directly. However, we then proceed to move this file directly from the
temporary directory to our final location, which is more than likely a
cross-filesystem move (/tmp on tmpfs) and thus non-atomic.
Instead, zip the file to the same directory, prefixing the filename with
'.tmp.'. We then move the file into place. This move is guaranteed to be
atomic, so any reader of the database file will get either the old
version, the new version, or ENOENT.
We also perform a hardlink if possible instead of a move when shifting
the old database out of the way to '.old'; this ensures there is no
chance of a database file not existing during the whole process.
Only one small race condition should now be present- when the database
has been fully moved into place and the signature has not, you may see a
mismatch. There seems to be no good way to address this, and it existed
before this patch.
A final note- if someone had locked-down permissions on the directory
that the database files are in (e.g., could only write to foo.db.tar.gz,
foo.db, foo.db.tar.gz.old, foo.db.old, and the lock file), this would
break.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-15 23:16:42 -05:00
|
|
|
ln -s "$filename.sig" "$dblink.sig" 2>/dev/null || \
|
|
|
|
ln "$filename.sig" "$dblink.sig" 2>/dev/null || \
|
2010-11-22 23:57:58 -05:00
|
|
|
cp "$REPO_DB_FILE.sig" "$dblink.sig"
|
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
else
|
|
|
|
msg "$(gettext "No packages modified, nothing to do.")"
|
2009-08-24 12:19:26 -04:00
|
|
|
exit 1
|
2006-11-20 04:10:23 -05:00
|
|
|
fi
|
|
|
|
|
2009-03-03 11:05:14 -05:00
|
|
|
exit 0
|
2014-01-22 18:06:11 -05:00
|
|
|
# vim: set noet:
|