2006-11-20 04:10:23 -05: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@
|
|
|
|
#
|
2008-05-09 20:26:57 -04:00
|
|
|
# Copyright (c) 2006-2008 Aaron Griffin <aaron@archlinux.org>
|
2008-06-14 12:29:29 -04:00
|
|
|
# Copyright (c) 2007-2008 Dan McGee <dan@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
|
2009-03-03 11:05:14 -05:00
|
|
|
REPO_DB_FILE=
|
|
|
|
LOCKFILE=
|
|
|
|
CLEAN_LOCK=0
|
|
|
|
startdir="$PWD"
|
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() {
|
|
|
|
local mesg=$1; shift
|
|
|
|
printf "==> ${mesg}\n" "$@" >&1
|
|
|
|
}
|
|
|
|
|
|
|
|
msg2() {
|
2008-05-09 20:26:57 -04:00
|
|
|
[ $QUIET -ne 0 ] && 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() {
|
2008-06-14 12:29:29 -04:00
|
|
|
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
|
2009-02-25 13:06:16 -05:00
|
|
|
printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package|delta> ...\n")"
|
|
|
|
printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")"
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "$(gettext "\
|
|
|
|
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")"
|
2008-05-09 20:26:57 -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")"
|
|
|
|
printf "$(gettext "\
|
2008-12-12 01:02:19 -05:00
|
|
|
Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\
|
|
|
|
and errors\n\n")"
|
2007-07-06 19:35:32 -04:00
|
|
|
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
|
2008-06-14 12:29:29 -04:00
|
|
|
echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
|
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() {
|
2008-06-14 12:29:29 -04:00
|
|
|
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "$(gettext "\
|
2008-06-14 12:29:29 -04:00
|
|
|
Copyright (C) 2006-2008 Aaron Griffin <aaron@archlinux.org>.\n\
|
|
|
|
Copyright (c) 2007-2008 Dan McGee <dan@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() {
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
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##*/}
|
|
|
|
if [ "${name%-*-*}" = "$pkgname" ]; then
|
|
|
|
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)
|
|
|
|
if [ -z "$pkgentry" ]; then
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
# get md5sum and compressed size of package
|
|
|
|
md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')"
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
if [ -z "$pkgentry" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
deltas="$pkgentry/deltas"
|
|
|
|
if [ ! -f "$deltas" ]; then
|
|
|
|
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
|
|
|
|
|
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"
|
2009-02-27 09:18:10 -05:00
|
|
|
local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager force \
|
|
|
|
_groups _licenses _replaces _depends _conflicts _provides _optdepends
|
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
|
|
|
|
|
2009-02-18 11:15:39 -05:00
|
|
|
# get md5sum and compressed size of package
|
|
|
|
md5sum="$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')"
|
2008-08-20 00:29:56 -04:00
|
|
|
csize=$(@SIZECMD@ "$pkgfile")
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# ensure $pkgname and $pkgver variables were found
|
2006-12-20 20:53:40 -05:00
|
|
|
if [ -z "$pkgname" -o -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
|
|
|
|
2009-03-03 11:13:52 -05:00
|
|
|
cd "$tmpdir"
|
2009-02-18 11:15:39 -05:00
|
|
|
|
2009-02-26 12:00:15 -05:00
|
|
|
if [ -d "$pkgname-$pkgver" ]; then
|
|
|
|
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
|
|
|
|
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"
|
|
|
|
cd "$pkgname-$pkgver"
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2009-02-26 14:02:05 -05:00
|
|
|
# restore an eventual deltas file
|
|
|
|
[ -f "../$pkgname.deltas" ] && mv "../$pkgname.deltas" deltas
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create desc entry
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Creating 'desc' db entry...")"
|
|
|
|
echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
echo -e "%NAME%\n$pkgname\n" >>desc
|
2009-07-21 22:33:09 -04: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
|
2007-08-29 05:49:24 -04:00
|
|
|
[ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc
|
|
|
|
write_list_entry "GROUPS" "$_groups" "desc"
|
2009-05-12 05:01:58 -04: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
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# compute checksums
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Computing md5 checksums...")"
|
2009-02-18 11:15:39 -05:00
|
|
|
echo -e "%MD5SUM%\n$md5sum\n" >>desc
|
2006-12-20 20:53:40 -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"
|
2006-12-20 20:53:40 -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"
|
2008-02-02 17:24:49 -05:00
|
|
|
[ -n "$force" ] && echo -e "%FORCE%\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create depends entry
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Creating 'depends' db entry...")"
|
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
|
|
|
|
2009-03-03 11:05:14 -05:00
|
|
|
cd "$startdir"
|
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)
|
|
|
|
while [ -n "$pkgentry" ]; do
|
|
|
|
notfound=0
|
|
|
|
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-08-02 17:00:04 -04:00
|
|
|
[ -f "$LOCKFILE" ] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)"
|
2009-03-03 11:05:14 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-02-26 13:23:33 -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
|
|
|
|
if [ -n "$(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null)" ]; then
|
|
|
|
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
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
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-02-25 13:06:16 -05:00
|
|
|
if [ "${1##*.}" == "delta" ]; then
|
|
|
|
deltafile=$1
|
|
|
|
msg "$(gettext "Adding delta '%s'")" "$deltafile"
|
|
|
|
if [ ! "$(type -p xdelta3)" ]; then
|
|
|
|
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-06-16 21:04:19 -04:00
|
|
|
if ! bsdtar -tqf "$pkgfile" .PKGINFO 2>&1 >/dev/null; 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-02-25 13:06:16 -05:00
|
|
|
if [ "${1##*.}" == "delta" ]; then
|
|
|
|
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=$?
|
|
|
|
|
|
|
|
cd "$startdir"
|
2009-03-03 11:13:52 -05:00
|
|
|
[ -d "$tmpdir" ] && rm -rf "$tmpdir"
|
2009-03-03 11:05:14 -05:00
|
|
|
[ $CLEAN_LOCK -eq 1 -a -f "$LOCKFILE" ] && rm -f "$LOCKFILE"
|
|
|
|
|
|
|
|
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
|
|
|
|
if [ ! $(type -t gettext) ]; then
|
|
|
|
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
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# check for correct number of args
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2008-06-14 12:29:29 -04:00
|
|
|
# figure out what program we are
|
|
|
|
cmd="$(basename $0)"
|
|
|
|
if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then
|
|
|
|
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
|
2007-08-29 05:49:24 -04:00
|
|
|
for arg in "$@"; do
|
2009-02-26 13:23:33 -05:00
|
|
|
case "$arg" in
|
|
|
|
-q|--quiet) QUIET=1;;
|
|
|
|
|
|
|
|
-f|--force)
|
|
|
|
warning "$(gettext "the -f and --force options are no longer recognized")"
|
|
|
|
msg2 "$(gettext "use options=(force) in the PKGBUILD instead")"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
if [ -z "$REPO_DB_FILE" ]; then
|
|
|
|
REPO_DB_FILE="$arg"
|
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
|
|
|
|
repo-add) add $arg && success=1 ;;
|
|
|
|
repo-remove) remove $arg && success=1 ;;
|
|
|
|
esac
|
2008-06-14 12:29:29 -04:00
|
|
|
fi
|
2009-02-26 13:23:33 -05:00
|
|
|
;;
|
|
|
|
esac
|
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
|
2007-08-29 05:49:24 -04:00
|
|
|
if [ $success -eq 1 ]; 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
|
|
|
|
2009-03-03 11:13:52 -05:00
|
|
|
cd "$tmpdir"
|
2009-02-18 10:39:31 -05:00
|
|
|
if [ -n "$(ls)" ]; then
|
|
|
|
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
|
2009-03-03 11:05:14 -05:00
|
|
|
cd "$startdir"
|
2009-02-18 10:39:31 -05:00
|
|
|
|
|
|
|
[ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
|
2009-03-03 11:13:52 -05:00
|
|
|
[ -f "$tmpdir/$filename" ] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
|
2007-08-29 05:49:24 -04:00
|
|
|
else
|
|
|
|
msg "$(gettext "No packages modified, nothing to do.")"
|
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:
|