2007-02-11 15:40:19 -05:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2007-05-30 11:04:49 -04:00
|
|
|
# repo-remove - remove a package entry from a given repo database file
|
|
|
|
# @configure_input@
|
|
|
|
#
|
2007-07-06 19:35:32 -04:00
|
|
|
# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2007-02-11 15:40:19 -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
|
|
|
#
|
2007-02-11 15:40:19 -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
|
|
|
#
|
2007-02-11 15:40:19 -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/>.
|
2007-02-11 15:40:19 -05:00
|
|
|
|
2007-06-04 01:21:14 -04:00
|
|
|
# gettext initialization
|
|
|
|
export TEXTDOMAIN='pacman'
|
|
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
|
2007-04-11 17:10:55 -04:00
|
|
|
myver='@PACKAGE_VERSION@'
|
2007-08-29 05:49:24 -04:00
|
|
|
confdir='@sysconfdir@'
|
2007-02-11 15:40:19 -05:00
|
|
|
|
|
|
|
FORCE=0
|
|
|
|
REPO_DB_FILE=""
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
msg() {
|
|
|
|
local mesg=$1; shift
|
|
|
|
printf "==> ${mesg}\n" "$@" >&1
|
|
|
|
}
|
|
|
|
|
|
|
|
msg2() {
|
|
|
|
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-02-11 15:40:19 -05:00
|
|
|
# print usage instructions
|
|
|
|
usage() {
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "$(gettext "repo-remove %s\n\n")" $myver
|
|
|
|
printf "$(gettext "usage: %s <path-to-db> <packagename> ...\n\n")" "$0"
|
|
|
|
printf "$(gettext "\
|
|
|
|
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")"
|
|
|
|
echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
|
2007-02-11 15:40:19 -05:00
|
|
|
}
|
|
|
|
|
2007-04-11 17:10:55 -04:00
|
|
|
version() {
|
|
|
|
printf "repo-remove (pacman) %s\n" "$myver"
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "$(gettext "\
|
|
|
|
Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\
|
|
|
|
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:10:55 -04:00
|
|
|
}
|
|
|
|
|
2007-02-11 15:40:19 -05:00
|
|
|
# test if a file is a repository DB
|
|
|
|
test_repo_db_file () {
|
|
|
|
if [ -f "$REPO_DB_FILE" ]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
|
|
|
|
return 0 # YES
|
|
|
|
fi
|
2007-02-11 15:40:19 -05:00
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
|
|
|
|
return 1 # NO
|
2007-02-11 15:40:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# remove existing entries from the DB
|
2007-08-29 05:49:24 -04:00
|
|
|
db_remove_entry() {
|
|
|
|
pushd "$gstmpdir" 2>&1 >/dev/null
|
2007-02-11 15:40:19 -05:00
|
|
|
|
|
|
|
# remove any other package in the DB with same name
|
2007-08-29 05:49:24 -04:00
|
|
|
local existing
|
2007-02-11 15:40:19 -05:00
|
|
|
for existing in *; do
|
|
|
|
if [ "${existing%-*-*}" = "$1" ]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
|
|
|
|
rm -rf "$existing"
|
2007-02-11 15:40:19 -05:00
|
|
|
fi
|
|
|
|
done
|
2007-08-29 05:49:24 -04:00
|
|
|
|
|
|
|
popd 2>&1 >/dev/null
|
2007-02-11 15:40:19 -05:00
|
|
|
} # end db_remove_entry
|
|
|
|
|
|
|
|
# PROGRAM START
|
|
|
|
|
|
|
|
# check for help flags
|
|
|
|
if [ "$1" = "-h" -o "$1" = "--help" ]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2007-04-11 17:10:55 -04:00
|
|
|
# check for version flags
|
2007-04-11 17:22:25 -04:00
|
|
|
if [ "$1" = "-V" -o "$1" = "--version" ]; then
|
2007-04-11 17:10:55 -04:00
|
|
|
version
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2007-02-11 15:40:19 -05:00
|
|
|
# check for correct number of args
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2007-04-01 19:55:01 -04:00
|
|
|
# source system and user makepkg.conf
|
2007-08-29 05:49:24 -04:00
|
|
|
if [ -r "$confdir/makepkg.conf" ]; then
|
|
|
|
source "$confdir/makepkg.conf"
|
2007-04-01 19:55:01 -04:00
|
|
|
else
|
2007-08-29 05:49:24 -04:00
|
|
|
error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
|
2007-06-04 01:21:14 -04:00
|
|
|
exit 1 # $E_CONFIG_ERROR
|
2007-04-01 19:55:01 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -r ~/.makepkg.conf ]; then
|
|
|
|
source ~/.makepkg.conf
|
|
|
|
fi
|
|
|
|
|
2007-02-11 15:40:19 -05:00
|
|
|
# main routine
|
2007-08-29 05:49:24 -04:00
|
|
|
gstmpdir=$(mktemp -d /tmp/repo-remove.XXXXXXXXXX) || (\
|
|
|
|
error "$(gettext "Cannot create temp directory for database building.")"; \
|
2007-02-11 15:40:19 -05:00
|
|
|
exit 1)
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
success=0
|
|
|
|
# parse arguements
|
|
|
|
for arg in "$@"; do
|
|
|
|
if [ -z "$REPO_DB_FILE" ]; then
|
|
|
|
REPO_DB_FILE=$(readlink -f "$arg")
|
|
|
|
if ! test_repo_db_file; then
|
|
|
|
error "$(gettext "Repository file '%s' is not a proper pacman database.")\n" "$REPO_DB_FILE"
|
|
|
|
exit 1
|
|
|
|
elif [ -f "$REPO_DB_FILE" ]; then
|
|
|
|
msg "$(gettext "Extracting database to a temporary location...")"
|
|
|
|
bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
|
2007-02-11 15:40:19 -05:00
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
else
|
|
|
|
msg "$(gettext "Searching for package '%s'...")" "$arg"
|
2007-02-11 15:40:19 -05:00
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
if db_remove_entry "$arg"; then
|
|
|
|
success=1
|
|
|
|
else
|
|
|
|
error "$(gettext "Package matching '%s' not found.")" "$arg"
|
2007-02-11 15:40:19 -05:00
|
|
|
fi
|
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
# if all operations were a success, rezip database
|
|
|
|
if [ $success -eq 1 ]; then
|
|
|
|
msg "$(gettext "Creating updated database file '%s'...")" "$REPO_DB_FILE"
|
|
|
|
pushd "$gstmpdir" 2>&1 >/dev/null
|
|
|
|
|
|
|
|
if [ -n "$(ls)" ]; then
|
|
|
|
[ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old"
|
|
|
|
[ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
|
|
|
|
case "$DB_COMPRESSION" in
|
|
|
|
gz) TAR_OPT="z" ;;
|
|
|
|
bz2) TAR_OPT="j" ;;
|
|
|
|
*) warning "$(gettext "No compression set.")" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" *
|
|
|
|
fi
|
|
|
|
|
|
|
|
popd 2>&1 >/dev/null
|
|
|
|
else
|
|
|
|
msg "$(gettext "No packages modified, nothing to do.")"
|
2007-02-11 15:40:19 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# remove the temp directory used to unzip
|
|
|
|
[ -d "$gstmpdir" ] && rm -rf $gstmpdir
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 noet:
|