Fix typos in code comments
[pacman-ng.git] / scripts / repo-remove.sh.in
blob05bec390e3f9d2873d00c1cac805001cfc3ec3e7
1 #!/bin/bash
3 # repo-remove - remove a package entry from a given repo database file
4 # @configure_input@
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@'
28 FORCE=0
29 REPO_DB_FILE=""
31 msg() {
32 local mesg=$1; shift
33 printf "==> ${mesg}\n" "$@" >&1
36 msg2() {
37 local mesg=$1; shift
38 printf " -> ${mesg}\n" "$@" >&1
41 warning() {
42 local mesg=$1; shift
43 printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
46 error() {
47 local mesg=$1; shift
48 printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
51 # print usage instructions
52 usage() {
53 printf "$(gettext "repo-remove %s\n\n")" $myver
54 printf "$(gettext "usage: %s <path-to-db> <packagename> ...\n\n")" "$0"
55 printf "$(gettext "\
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")"
62 version() {
63 printf "repo-remove (pacman) %s\n" "$myver"
64 printf "$(gettext "\
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
74 return 0 # YES
78 return 1 # NO
81 # remove existing entries from the DB
82 db_remove_entry() {
83 pushd "$gstmpdir" 2>&1 >/dev/null
85 # remove any other package in the DB with same name
86 local existing
87 for existing in *; do
88 if [ "${existing%-*-*}" = "$1" ]; then
89 msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
90 rm -rf "$existing"
92 done
94 popd 2>&1 >/dev/null
95 } # end db_remove_entry
97 # PROGRAM START
99 # check for help flags
100 if [ "$1" = "-h" -o "$1" = "--help" ]; then
101 usage
102 exit 0
105 # check for version flags
106 if [ "$1" = "-V" -o "$1" = "--version" ]; then
107 version
108 exit 0
111 # check for correct number of args
112 if [ $# -lt 2 ]; then
113 usage
114 exit 1
117 # source system and user makepkg.conf
118 if [ -r "$confdir/makepkg.conf" ]; then
119 source "$confdir/makepkg.conf"
120 else
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
129 # main routine
130 gstmpdir=$(mktemp -d /tmp/repo-remove.XXXXXXXXXX) || (\
131 error "$(gettext "Cannot create temp directory for database building.")"; \
132 exit 1)
134 success=0
135 # parse arguments
136 for arg in "$@"; do
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"
141 exit 1
142 elif [ -f "$REPO_DB_FILE" ]; then
143 msg "$(gettext "Extracting database to a temporary location...")"
144 bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
146 else
147 msg "$(gettext "Searching for package '%s'...")" "$arg"
149 if db_remove_entry "$arg"; then
150 success=1
151 else
152 error "$(gettext "Package matching '%s' not found.")" "$arg"
155 done
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
166 gz) TAR_OPT="z" ;;
167 bz2) TAR_OPT="j" ;;
168 *) warning "$(gettext "No compression set.")" ;;
169 esac
171 bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" *
174 popd 2>&1 >/dev/null
175 else
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: