2010-10-13 18:50:54 -04:00
|
|
|
#!@BASH_SHELL@
|
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@
|
|
|
|
#
|
2011-04-24 07:17:03 -04:00
|
|
|
# Copyright (c) 2006-2011 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
|
|
|
|
2007-06-04 01:21:14 -04:00
|
|
|
# gettext initialization
|
|
|
|
export TEXTDOMAIN='pacman'
|
|
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
|
2007-04-11 17:02:56 -04:00
|
|
|
myver='@PACKAGE_VERSION@'
|
2007-08-29 05:49:24 -04:00
|
|
|
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
|
2011-01-11 17:04:20 -05:00
|
|
|
WITHFILES=0
|
2009-08-24 14:23:44 -04:00
|
|
|
SIGN=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
|
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
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
msg() {
|
2010-08-07 21:54:33 -04:00
|
|
|
(( QUIET )) && return
|
2007-08-29 05:49:24 -04:00
|
|
|
local mesg=$1; shift
|
|
|
|
printf "==> ${mesg}\n" "$@" >&1
|
|
|
|
}
|
|
|
|
|
|
|
|
msg2() {
|
2009-11-05 10:55:48 -05:00
|
|
|
(( QUIET )) && return
|
2007-08-29 05:49:24 -04:00
|
|
|
local mesg=$1; shift
|
|
|
|
printf " -> ${mesg}\n" "$@" >&1
|
|
|
|
}
|
|
|
|
|
|
|
|
warning() {
|
|
|
|
local mesg=$1; shift
|
|
|
|
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
local mesg=$1; shift
|
|
|
|
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# print usage instructions
|
|
|
|
usage() {
|
2011-03-27 22:04:40 -04:00
|
|
|
cmd="$(basename $0)"
|
|
|
|
printf "%s (pacman) %s\n\n" "$cmd" "$myver"
|
|
|
|
if [[ $cmd == "repo-add" ]] ; then
|
2011-04-24 03:36:21 -04:00
|
|
|
printf "$(gettext "Usage: repo-add [options] <path-to-db> <package|delta> ...\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
printf "$(gettext "\
|
2007-07-06 19:35:32 -04:00
|
|
|
repo-add will update a package database by reading a package file.\n\
|
|
|
|
Multiple packages to add can be specified on the command line.\n\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
printf "$(gettext "Options:\n")"
|
2011-04-24 06:48:08 -04:00
|
|
|
printf "$(gettext " -d, --delta generate and add delta for package update\n")"
|
|
|
|
printf "$(gettext " -f, --files update database's file list\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
elif [[ $cmd == "repo-remove" ]] ; then
|
2011-04-24 03:36:21 -04:00
|
|
|
printf "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
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\
|
|
|
|
packages to remove can be specified on the command line.\n\n")"
|
2011-03-27 22:04:40 -04:00
|
|
|
printf "$(gettext "Options:\n")"
|
|
|
|
fi
|
2011-04-24 06:48:08 -04: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")"
|
2011-03-27 22:04:40 -04:00
|
|
|
printf "$(gettext "\n\
|
|
|
|
See %s(8) for more details and descriptions of the available options.\n\n")" $cmd
|
|
|
|
if [[ $cmd == "repo-add" ]] ; then
|
2011-04-24 03:36:21 -04:00
|
|
|
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz")"
|
2011-03-27 22:04:40 -04:00
|
|
|
elif [[ $cmd == "repo-remove" ]] ; then
|
|
|
|
echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
|
|
|
|
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-03-27 22:04:40 -04:00
|
|
|
cmd="$(basename $0)"
|
|
|
|
printf "%s (pacman) %s\n\n" "$cmd" "$myver"
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "$(gettext "\
|
2011-04-24 07:17:03 -04:00
|
|
|
Copyright (c) 2006-2011 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
|
|
|
}
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
# write a list entry
|
|
|
|
# arg1 - Entry name
|
|
|
|
# arg2 - List
|
|
|
|
# arg3 - File to write to
|
|
|
|
write_list_entry() {
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -n $2 ]]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
echo "%$1%" >>$3
|
2008-01-15 05:50:46 -05:00
|
|
|
echo -e $2 >>$3
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2009-02-26 14:02:05 -05:00
|
|
|
find_pkgentry()
|
|
|
|
{
|
|
|
|
local pkgname=$1
|
|
|
|
local pkgentry
|
2009-03-03 11:13:52 -05:00
|
|
|
for pkgentry in $tmpdir/$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
|
|
|
|
db_write_delta()
|
|
|
|
{
|
|
|
|
deltafile="$1"
|
|
|
|
pkgname="$(get_delta_pkgname $deltafile)"
|
|
|
|
|
|
|
|
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
|
|
|
|
deltas="$pkgentry/deltas"
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ ! -f $deltas ]]; then
|
2010-10-11 12:28:35 -04:00
|
|
|
echo -e "%DELTAS%" >$deltas
|
2009-02-25 13:06:16 -05:00
|
|
|
fi
|
|
|
|
# get md5sum and compressed size of package
|
2009-10-20 09:44:00 -04:00
|
|
|
md5sum="$(openssl dgst -md5 "$deltafile")"
|
|
|
|
md5sum="${md5sum##* }"
|
2009-02-25 13:06:16 -05:00
|
|
|
csize=$(@SIZECMD@ "$deltafile")
|
|
|
|
|
|
|
|
oldfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (source)" | sed 's/.*: *//')
|
|
|
|
newfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (output)" | sed 's/.*: *//')
|
|
|
|
|
|
|
|
if grep -q "$oldfile.*$newfile" $deltas; then
|
|
|
|
sed -i.backup "/$oldfile.*$newfile/d" $deltas && rm -f $deltas.backup
|
|
|
|
fi
|
2010-10-11 12:28:35 -04:00
|
|
|
msg2 "$(gettext "Adding 'deltas' entry : %s -> %s")" "$oldfile" "$newfile"
|
2009-02-25 13:06:16 -05:00
|
|
|
echo ${deltafile##*/} $md5sum $csize $oldfile $newfile >> $deltas
|
|
|
|
|
|
|
|
return 0
|
|
|
|
} # end db_write_delta
|
|
|
|
|
|
|
|
# remove a delta entry
|
|
|
|
# arg1 - path to delta file
|
|
|
|
db_remove_delta()
|
|
|
|
{
|
|
|
|
deltafile="$1"
|
|
|
|
filename=${deltafile##*/}
|
|
|
|
pkgname="$(get_delta_pkgname $deltafile)"
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
if grep -q "$filename" $deltas; then
|
|
|
|
sed -i.backup "/$filename/d" $deltas && rm -f $deltas.backup
|
|
|
|
msg2 "$(gettext "Removing existing entry '%s'...")" "$filename"
|
|
|
|
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
|
|
|
|
error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
|
|
|
|
exit 1 # $E_MISSING_PROGRAM
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-08-24 14:23:44 -04:00
|
|
|
# sign the package database once repackaged
|
|
|
|
create_signature() {
|
|
|
|
(( ! SIGN )) && return
|
|
|
|
local dbfile="$1"
|
|
|
|
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
|
|
|
|
msg2 "$(gettext "Created signature file %s.")" "$dbfile.sig"
|
|
|
|
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
|
|
|
|
local dbfile="$1"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# write an entry to the pacman database
|
|
|
|
# arg1 - path to package
|
2006-11-20 04:10:23 -05:00
|
|
|
db_write_entry()
|
|
|
|
{
|
2009-02-18 11:15:39 -05:00
|
|
|
# blank out all variables
|
|
|
|
local pkgfile="$1"
|
2011-03-24 18:05:30 -04:00
|
|
|
local pkgname pkgver pkgdesc csize size url arch builddate packager \
|
|
|
|
_groups _licenses _replaces _depends _conflicts _provides _optdepends \
|
|
|
|
md5sum sha256sum pgpsig
|
2007-08-29 05:49:24 -04:00
|
|
|
|
|
|
|
local OLDIFS="$IFS"
|
2008-01-14 00:26:31 -05:00
|
|
|
# IFS (field separator) is only the newline character
|
2007-02-22 20:29:14 -05:00
|
|
|
IFS="
|
|
|
|
"
|
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
|
2009-06-16 21:04:19 -04:00
|
|
|
for line in $(bsdtar -xOqf "$pkgfile" .PKGINFO |
|
2009-02-08 13:21:49 -05:00
|
|
|
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"
|
|
|
|
case "$var" in
|
|
|
|
group) _groups="$_groups$group\n" ;;
|
|
|
|
license) _licenses="$_licenses$license\n" ;;
|
|
|
|
replaces) _replaces="$_replaces$replaces\n" ;;
|
2009-02-27 09:18:10 -05:00
|
|
|
depend) _depends="$_depends$depend\n" ;;
|
2009-02-08 13:21:49 -05:00
|
|
|
conflict) _conflicts="$_conflicts$conflict\n" ;;
|
2009-02-27 09:18:10 -05:00
|
|
|
provides) _provides="$_provides$provides\n" ;;
|
2009-02-08 13:21:49 -05:00
|
|
|
optdepend) _optdepends="$_optdepends$optdepend\n" ;;
|
2006-12-20 20:53:40 -05:00
|
|
|
esac
|
|
|
|
done
|
2007-01-30 19:38:13 -05:00
|
|
|
|
2006-12-20 20:53:40 -05:00
|
|
|
IFS=$OLDIFS
|
|
|
|
|
2008-08-20 00:29:56 -04:00
|
|
|
csize=$(@SIZECMD@ "$pkgfile")
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2011-03-24 18:05:30 -04:00
|
|
|
# compute checksums
|
|
|
|
msg2 "$(gettext "Computing checksums...")"
|
|
|
|
md5sum="$(openssl dgst -md5 "$pkgfile")"
|
|
|
|
md5sum="${md5sum##* }"
|
|
|
|
sha256sum="$(openssl dgst -sha256 "$pkgfile")"
|
|
|
|
sha256sum="${sha256sum##* }"
|
|
|
|
|
|
|
|
# compute base64'd PGP signature
|
|
|
|
if [[ -f "$pkgfile.sig" ]]; then
|
|
|
|
pgpsig=$(openssl base64 -in "$pkgfile.sig" | tr -d '\n')
|
|
|
|
fi
|
|
|
|
|
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-01-11 16:15:07 -05:00
|
|
|
pushd "$tmpdir" >/dev/null
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -d $pkgname-$pkgver ]]; then
|
2009-02-26 12:00:15 -05:00
|
|
|
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
|
2010-10-11 11:08:00 -04:00
|
|
|
else
|
2011-01-22 09:13:24 -05:00
|
|
|
if (( DELTA )); then
|
2010-10-11 11:08:00 -04:00
|
|
|
pkgentry=$(find_pkgentry $pkgname)
|
2011-01-22 09:13:24 -05:00
|
|
|
if [[ -n $pkgentry ]]; then
|
2010-10-11 11:08:00 -04:00
|
|
|
local oldfilename=$(grep -A1 FILENAME $pkgentry/desc | tail -n1)
|
|
|
|
local oldfile="$(dirname $1)/$oldfilename"
|
|
|
|
fi
|
|
|
|
fi
|
2009-02-26 12:00:15 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# remove an existing entry if it exists, ignore failures
|
|
|
|
db_remove_entry "$pkgname"
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create package directory
|
|
|
|
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'
|
2007-08-29 05:49:24 -04:00
|
|
|
echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
echo -e "%NAME%\n$pkgname\n" >>desc
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
echo -e "%VERSION%\n$pkgver\n" >>desc
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc
|
2007-08-29 05:49:24 -04:00
|
|
|
write_list_entry "GROUPS" "$_groups" "desc"
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc
|
|
|
|
[[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2011-03-23 01:10:36 -04:00
|
|
|
# add checksums
|
2009-02-18 11:15:39 -05:00
|
|
|
echo -e "%MD5SUM%\n$md5sum\n" >>desc
|
2011-03-23 01:10:36 -04:00
|
|
|
echo -e "%SHA256SUM%\n$sha256sum\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2011-03-24 18:05:30 -04:00
|
|
|
# add PGP sig
|
|
|
|
[[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc
|
2008-06-02 04:27:01 -04:00
|
|
|
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc
|
2007-08-29 05:49:24 -04:00
|
|
|
write_list_entry "LICENSE" "$_licenses" "desc"
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -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
|
2007-08-29 05:49:24 -04:00
|
|
|
write_list_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'
|
2009-03-03 11:10:26 -05:00
|
|
|
# create the file even if it will remain empty
|
|
|
|
touch "depends"
|
2007-08-29 05:49:24 -04:00
|
|
|
write_list_entry "DEPENDS" "$_depends" "depends"
|
|
|
|
write_list_entry "CONFLICTS" "$_conflicts" "depends"
|
|
|
|
write_list_entry "PROVIDES" "$_provides" "depends"
|
2008-07-31 10:53:28 -04:00
|
|
|
write_list_entry "OPTDEPENDS" "$_optdepends" "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-01-11 17:04:20 -05:00
|
|
|
local files_path="$tmpdir/$pkgname-$pkgver/files"
|
|
|
|
echo "%FILES%" >$files_path
|
2011-06-02 08:59:45 -04:00
|
|
|
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
|
|
|
|
delta=$(pkgdelta -q $oldfile $1)
|
|
|
|
if [[ -f $delta ]]; then
|
|
|
|
db_write_delta $delta
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
2009-03-03 11:13:52 -05:00
|
|
|
mv "$pkgentry/deltas" "$tmpdir/$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'...")" \
|
2009-02-26 14:02:05 -05:00
|
|
|
"$(basename $pkgentry)"
|
|
|
|
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
|
|
|
|
|
2009-02-26 13:23:33 -05:00
|
|
|
check_repo_db()
|
|
|
|
{
|
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"
|
2009-11-05 10:55:48 -05: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...")"
|
2009-03-03 11:13:52 -05:00
|
|
|
bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir"
|
2009-02-26 13:23:33 -05:00
|
|
|
else
|
2009-02-26 12:16:23 -05:00
|
|
|
case "$cmd" in
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2009-03-03 11:13:52 -05:00
|
|
|
rm -f "$tmpdir/$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
|
|
|
}
|
|
|
|
|
2009-03-03 11:05:14 -05:00
|
|
|
trap_exit()
|
|
|
|
{
|
|
|
|
echo
|
|
|
|
error "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
clean_up() {
|
|
|
|
local exit_code=$?
|
|
|
|
|
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
|
|
|
|
|
2009-02-26 13:23:33 -05:00
|
|
|
case "$1" in
|
|
|
|
-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
|
|
|
|
cmd="$(basename $0)"
|
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
|
|
|
|
|
2009-03-03 11:13:52 -05:00
|
|
|
tmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
|
2009-03-03 11:05:14 -05:00
|
|
|
error "$(gettext "Cannot create temp directory for database building.")"; \
|
|
|
|
exit 1)
|
|
|
|
|
|
|
|
trap 'clean_up' EXIT
|
|
|
|
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
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
success=0
|
2008-01-14 00:26:31 -05:00
|
|
|
# parse arguments
|
2011-04-24 06:48:08 -04:00
|
|
|
while [[ $# > 0 ]]; do
|
|
|
|
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;;
|
2011-01-11 17:04:20 -05:00
|
|
|
-f|--files) WITHFILES=1;;
|
2011-04-24 06:51:53 -04:00
|
|
|
-s|--sign)
|
2011-04-24 06:56:59 -04:00
|
|
|
check_gpg
|
2011-04-24 06:51:53 -04:00
|
|
|
SIGN=1
|
|
|
|
if ! gpg --list-key ${GPGKEY} &>/dev/null; then
|
|
|
|
if [[ ! -z $GPGKEY ]]; then
|
|
|
|
error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
|
|
|
|
else
|
|
|
|
error "$(gettext "There is no key in your keyring.")"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2011-04-24 06:48:08 -04:00
|
|
|
-k|--key)
|
2011-04-24 06:56:59 -04:00
|
|
|
check_gpg
|
2011-04-24 06:48:08 -04:00
|
|
|
shift
|
|
|
|
GPGKEY="$1"
|
|
|
|
if ! gpg --list-key ${GPGKEY} &>/dev/null; then
|
|
|
|
error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2011-04-24 06:56:59 -04:00
|
|
|
-v|--verify)
|
|
|
|
check_gpg
|
|
|
|
VERIFY=1
|
|
|
|
;;
|
2009-02-26 13:23:33 -05:00
|
|
|
*)
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -z $REPO_DB_FILE ]]; then
|
2011-04-24 06:48:08 -04:00
|
|
|
REPO_DB_FILE="$1"
|
2009-03-03 11:05:14 -05:00
|
|
|
LOCKFILE="$REPO_DB_FILE.lck"
|
2009-02-26 13:23:33 -05:00
|
|
|
check_repo_db
|
2006-12-20 20:53:40 -05:00
|
|
|
else
|
2009-02-26 13:23:33 -05:00
|
|
|
case "$cmd" in
|
2011-04-24 06:48:08 -04:00
|
|
|
repo-add) add $1 && success=1 ;;
|
|
|
|
repo-remove) remove $1 && success=1 ;;
|
2009-02-26 13:23:33 -05:00
|
|
|
esac
|
2008-06-14 12:29:29 -04:00
|
|
|
fi
|
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
|
|
|
|
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
|
|
|
|
2009-02-18 10:39:31 -05:00
|
|
|
case "$REPO_DB_FILE" in
|
|
|
|
*tar.gz) TAR_OPT="z" ;;
|
|
|
|
*tar.bz2) TAR_OPT="j" ;;
|
2009-05-13 02:21:11 -04:00
|
|
|
*tar.xz) TAR_OPT="J" ;;
|
2009-02-18 10:39:31 -05:00
|
|
|
*) warning "$(gettext "'%s' does not have a valid archive extension.")" \
|
|
|
|
"$REPO_DB_FILE" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
filename=$(basename "$REPO_DB_FILE")
|
2007-08-29 05:49:24 -04:00
|
|
|
|
2011-01-11 16:15:07 -05:00
|
|
|
pushd "$tmpdir" >/dev/null
|
2009-11-05 10:55:48 -05:00
|
|
|
if [[ -n $(ls) ]]; then
|
2009-02-18 10:39:31 -05:00
|
|
|
bsdtar -c${TAR_OPT}f "$filename" *
|
2008-06-16 18:09:45 -04:00
|
|
|
else
|
2009-09-23 22:15:53 -04:00
|
|
|
# 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
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2011-03-25 19:25:38 -04:00
|
|
|
create_signature "$filename"
|
|
|
|
|
2011-01-11 16:15:07 -05:00
|
|
|
popd >/dev/null
|
2009-02-18 10:39:31 -05:00
|
|
|
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
|
2009-08-24 14:23:44 -04:00
|
|
|
[[ -f $REPO_DB_FILE.sig ]] && rm -f "$REPO_DB_FILE.sig"
|
2009-11-05 10:55:48 -05:00
|
|
|
[[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
|
2009-08-24 14:23:44 -04:00
|
|
|
[[ -f $tmpdir/$filename.sig ]] && mv "$tmpdir/$filename.sig" "$REPO_DB_FILE.sig"
|
2010-06-24 11:06:36 -04:00
|
|
|
dblink="${REPO_DB_FILE%.tar.*}"
|
2010-08-18 14:17:46 -04:00
|
|
|
target=${REPO_DB_FILE##*/}
|
|
|
|
ln -sf "$target" "$dblink" 2>/dev/null || \
|
|
|
|
ln -f "$target" "$dblink" 2>/dev/null || \
|
2010-06-24 11:06:36 -04:00
|
|
|
cp "$REPO_DB_FILE" "$dblink"
|
2010-11-22 23:57:58 -05:00
|
|
|
if [[ -f "$target.sig" ]]; then
|
|
|
|
ln -sf "$target.sig" "$dblink.sig" 2>/dev/null || \
|
|
|
|
ln -f "$target.sig" "$dblink.sig" 2>/dev/null || \
|
|
|
|
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
|
2006-12-20 20:53:40 -05:00
|
|
|
# vim: set ts=2 sw=2 noet:
|