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
|
2006-11-20 04:10:23 -05:00
|
|
|
REPO_DB_FILE=""
|
|
|
|
|
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"
|
|
|
|
printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package> ...\n")"
|
|
|
|
printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename> ...\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
|
|
|
|
for pkgentry in $gstmpdir/$pkgname*; do
|
|
|
|
name=${pkgentry##*/}
|
|
|
|
if [ "${name%-*-*}" = "$pkgname" ]; then
|
|
|
|
echo $pkgentry
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2007-10-19 13:17:50 -04:00
|
|
|
# write a delta entry to the pacman database
|
|
|
|
# arg1 - path to delta
|
|
|
|
db_write_delta()
|
|
|
|
{
|
2009-02-18 11:15:39 -05:00
|
|
|
# blank out all variables
|
|
|
|
local deltafile="$1"
|
2007-10-19 13:17:50 -04:00
|
|
|
local filename=$(basename "$deltafile")
|
|
|
|
local deltavars pkgname fromver tover arch csize md5sum
|
|
|
|
|
|
|
|
# format of the delta filename:
|
|
|
|
# (package)-(fromver)_to_(tover)-(arch).delta
|
|
|
|
deltavars=( $(echo "$filename" | sed -e 's/\(.*\)-\(.*-.*\)_to_\(.*-.*\)-\(.*\).delta/\1 \2 \3 \4/') )
|
|
|
|
pkgname=${deltavars[0]}
|
|
|
|
fromver=${deltavars[1]}
|
|
|
|
tover=${deltavars[2]}
|
|
|
|
arch=${deltavars[3]}
|
|
|
|
|
|
|
|
# get md5sum and size of delta
|
2008-10-18 22:27:00 -04:00
|
|
|
md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')"
|
2008-08-20 00:29:56 -04:00
|
|
|
csize=$(@SIZECMD@ "$deltafile")
|
2007-10-19 13:17:50 -04:00
|
|
|
|
|
|
|
# ensure variables were found
|
|
|
|
if [ -z "$pkgname" -o -z "$fromver" -o -z "$tover" -o -z "$arch" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add the entry for this delta file
|
|
|
|
echo -e "$fromver $tover $csize $filename $md5sum" >>deltas
|
|
|
|
} # end db_write_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"
|
2007-08-29 05:49:24 -04:00
|
|
|
local pkgname pkgver pkgdesc url builddate packager csize size \
|
2008-02-02 15:52:19 -05:00
|
|
|
group depend backup license replaces provides conflict force \
|
2007-10-19 13:17:50 -04:00
|
|
|
_groups _depends _backups _licenses _replaces _provides _conflicts \
|
2009-02-18 11:15:39 -05:00
|
|
|
startdir optdepend _optdepends md5sum
|
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
|
|
|
|
for line in $(bsdtar -xOf "$pkgfile" .PKGINFO |
|
|
|
|
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" ;;
|
|
|
|
depend) _depends="$_depends$depend\n" ;;
|
|
|
|
backup) _backups="$_backups$backup\n" ;;
|
|
|
|
license) _licenses="$_licenses$license\n" ;;
|
|
|
|
replaces) _replaces="$_replaces$replaces\n" ;;
|
|
|
|
provides) _provides="$_provides$provides\n" ;;
|
|
|
|
conflict) _conflicts="$_conflicts$conflict\n" ;;
|
|
|
|
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-02-18 11:15:39 -05:00
|
|
|
startdir=$(pwd)
|
|
|
|
pushd "$gstmpdir" 2>&1 >/dev/null
|
|
|
|
|
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
|
|
|
|
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"
|
2006-12-20 20:53:40 -05:00
|
|
|
[ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc
|
|
|
|
[ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc
|
|
|
|
|
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...")"
|
|
|
|
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
|
|
|
|
2007-10-19 13:17:50 -04:00
|
|
|
# create deltas entry if there are delta files
|
2009-02-18 11:15:39 -05:00
|
|
|
# Xav : why should deltas be in $startdir?
|
2007-10-19 13:17:50 -04:00
|
|
|
for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do
|
2007-11-12 16:54:50 -05:00
|
|
|
# This for loop also pulls in all files that start with the current package
|
|
|
|
# name and are followed by a -whatever. For instance, running this loop for
|
|
|
|
# gcc would also grab gcc-libs. To guard against this, compare the package
|
|
|
|
# name of the delta to the current package name.
|
|
|
|
local filename=$(basename "$delta")
|
|
|
|
local dpkgname="$(echo "$filename" | sed -e 's/\(.*\)-.*-.*_to_.*-.*-.*.delta/\1/')"
|
|
|
|
if [ "$pkgname" = "$dpkgname" -a -f "$delta" ]; then
|
2007-10-19 13:17:50 -04:00
|
|
|
# create deltas file if it does not already exist
|
|
|
|
if [ ! -f "deltas" ]; then
|
|
|
|
msg2 "$(gettext "Creating 'deltas' db entry...")"
|
|
|
|
echo -e "%DELTAS%" >>deltas
|
|
|
|
fi
|
|
|
|
|
|
|
|
# write this delta entry
|
|
|
|
if db_write_delta "$delta"; then
|
|
|
|
msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")"
|
|
|
|
else
|
2008-05-09 20:26:57 -04:00
|
|
|
warning "$(gettext "Could not add delta '%s'")" "$(basename "$delta")"
|
2007-10-19 13:17:50 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# add the final newline
|
|
|
|
[ -f "deltas" ] && echo -e "" >>deltas
|
|
|
|
|
2009-02-18 11:15:39 -05:00
|
|
|
popd 2>&1 >/dev/null
|
|
|
|
|
2006-12-20 20:53:40 -05:00
|
|
|
# preserve the modification time
|
2009-02-18 11:15:39 -05:00
|
|
|
# Xav : what for?
|
|
|
|
pkgdir="$gstmpdir/$pkgname-$pkgver"
|
|
|
|
touch -r "$pkgfile" "$pkgdir/desc" "$pkgdir/depends"
|
|
|
|
[ -f "$pkgdir/deltas" ] && touch -r "$pkgfile" "$pkgdir/deltas"
|
2007-08-29 05:49:24 -04:00
|
|
|
|
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
|
|
|
|
mv "$pkgentry/deltas" "$gstmpdir/$pkgname.deltas"
|
2008-06-14 12:29:29 -04:00
|
|
|
fi
|
2009-02-26 14:02:05 -05:00
|
|
|
msg2 "$(gettext "Removing existing package '%s'...")" \
|
|
|
|
"$(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()
|
|
|
|
{
|
|
|
|
if [ -f "$REPO_DB_FILE" ]; then
|
|
|
|
if ! (bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"); then
|
|
|
|
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
msg "$(gettext "Extracting database to a temporary location...")"
|
|
|
|
bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
|
|
|
|
else
|
|
|
|
if [ "$cmd" == "repo-remove" ]; then
|
|
|
|
error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
add()
|
|
|
|
{
|
|
|
|
pkgfile=$1
|
|
|
|
if [ ! -f "$1" ]; then
|
|
|
|
error "$(gettext "Package '%s' not found.")" "$pkgfile"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! bsdtar -tf "$pkgfile" .PKGINFO 2>&1 >/dev/null; then
|
|
|
|
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-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
|
|
|
|
rm -f "$gstmpdir/$pkgname.deltas"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
error "$(gettext "Package matching '%s' not found.")" "$pkgname"
|
|
|
|
return 1
|
|
|
|
fi
|
2009-02-26 13:23:33 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# main routine
|
2008-06-14 12:29:29 -04:00
|
|
|
gstmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
|
2007-08-29 05:49:24 -04:00
|
|
|
error "$(gettext "Cannot create temp directory for database building.")"; \
|
2006-12-20 20:53:40 -05:00
|
|
|
exit 1)
|
|
|
|
|
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
|
|
|
|
|
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"
|
|
|
|
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" ;;
|
|
|
|
*) 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-02-18 10:39:31 -05:00
|
|
|
pushd "$gstmpdir" 2>&1 >/dev/null
|
|
|
|
if [ -n "$(ls)" ]; then
|
|
|
|
bsdtar -c${TAR_OPT}f "$filename" *
|
2008-06-16 18:09:45 -04:00
|
|
|
else
|
2009-02-18 10:39:31 -05:00
|
|
|
# the database will be moved to .old below, and there will be no new one to replace it
|
2008-06-14 12:29:29 -04:00
|
|
|
error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE"
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
popd 2>&1 >/dev/null
|
2009-02-18 10:39:31 -05:00
|
|
|
|
|
|
|
[ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
|
|
|
|
[ -f "$gstmpdir/$filename" ] && mv "$gstmpdir/$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
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# remove the temp directory used to unzip
|
2007-08-29 05:49:24 -04:00
|
|
|
[ -d "$gstmpdir" ] && rm -rf "$gstmpdir"
|
2006-12-20 20:53:40 -05:00
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 noet:
|