3 # repo-remove - remove a package entry from a given repo database file
6 # Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # gettext initialization
22 export TEXTDOMAIN
='pacman'
23 export TEXTDOMAINDIR
='@localedir@'
25 myver
='@PACKAGE_VERSION@'
26 confdir
='@sysconfdir@'
33 printf "==> ${mesg}\n" "$@" >&1
38 printf " -> ${mesg}\n" "$@" >&1
43 printf "==> $(gettext "WARNING
:") ${mesg}\n" "$@" >&2
48 printf "==> $(gettext "ERROR
:") ${mesg}\n" "$@" >&2
51 # print usage instructions
53 printf "$(gettext "repo-remove
%s
\n\n")" $myver
54 printf "$(gettext "usage
: %s
<path-to-db
> <packagename
> ...
\n\n")" "$0"
56 repo-remove will update a package database by removing the package name
\n\
57 specified on the
command line from the given repo database. Multiple
\n\
58 packages to remove can be specified on the
command line.
\n\n")"
59 echo "$(gettext "Example
: repo-remove
/path
/to
/repo.db.
tar.gz kernel26
")"
63 printf "repo-remove (pacman) %s\n" "$myver"
65 Copyright
(C
) 2002-2007 Judd Vinet
<jvinet@zeroflux.org
>.
\n\n\
66 This is free software
; see the
source for copying conditions.
\n\
67 There is NO WARRANTY
, to the extent permitted by law.
\n")"
70 # test if a file is a repository DB
71 test_repo_db_file
() {
72 if [ -f "$REPO_DB_FILE" ]; then
73 if bsdtar
-tf "$REPO_DB_FILE" |
grep -q "/desc"; then
81 # remove existing entries from the DB
83 pushd "$gstmpdir" 2>&1 >/dev
/null
85 # remove any other package in the DB with same name
88 if [ "${existing%-*-*}" = "$1" ]; then
89 msg2
"$(gettext "Removing existing package
'%s'...
")" "$existing"
95 } # end db_remove_entry
99 # check for help flags
100 if [ "$1" = "-h" -o "$1" = "--help" ]; then
105 # check for version flags
106 if [ "$1" = "-V" -o "$1" = "--version" ]; then
111 # check for correct number of args
112 if [ $# -lt 2 ]; then
117 # source system and user makepkg.conf
118 if [ -r "$confdir/makepkg.conf" ]; then
119 source "$confdir/makepkg.conf"
121 error
"$(gettext "%s not found. Cannot
continue.
")" "$confdir/makepkg.conf"
122 exit 1 # $E_CONFIG_ERROR
125 if [ -r ~
/.makepkg.conf
]; then
126 source ~
/.makepkg.conf
130 gstmpdir
=$
(mktemp
-d /tmp
/repo-remove.XXXXXXXXXX
) ||
(\
131 error
"$(gettext "Cannot create temp directory
for database building.
")"; \
137 if [ -z "$REPO_DB_FILE" ]; then
138 REPO_DB_FILE
=$
(readlink
-f "$arg")
139 if ! test_repo_db_file
; then
140 error
"$(gettext "Repository
file '%s' is not a proper pacman database.
")\n" "$REPO_DB_FILE"
142 elif [ -f "$REPO_DB_FILE" ]; then
143 msg
"$(gettext "Extracting database to a temporary location...
")"
144 bsdtar
-xf "$REPO_DB_FILE" -C "$gstmpdir"
147 msg
"$(gettext "Searching
for package
'%s'...
")" "$arg"
149 if db_remove_entry
"$arg"; then
152 error
"$(gettext "Package matching
'%s' not found.
")" "$arg"
157 # if all operations were a success, re-zip database
158 if [ $success -eq 1 ]; then
159 msg
"$(gettext "Creating updated database
file '%s'...
")" "$REPO_DB_FILE"
160 pushd "$gstmpdir" 2>&1 >/dev
/null
162 if [ -n "$(ls)" ]; then
163 [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old"
164 [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
165 case "$DB_COMPRESSION" in
168 *) warning
"$(gettext "No compression
set.
")" ;;
171 bsdtar
-c${TAR_OPT}f
"$REPO_DB_FILE" *
176 msg
"$(gettext "No packages modified
, nothing to
do.
")"
179 # remove the temp directory used to unzip
180 [ -d "$gstmpdir" ] && rm -rf $gstmpdir
182 # vim: set ts=2 sw=2 noet: