1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

scripts/*.sh.in: Clean up and fix a few bugs

repo-add, repo-remove:
		'bsdtar -c * | ...' doesn't work (you need '-f -'). Code clean up
		eliminated this bug.

		Removed the multiple checksum support, pacman now only supports MD5, so
		there's no need for the database to contain multiple checksums.

		Quote all variables containing file/dir names to prevent paths
		containing spaces from causing problems.

		Add msg, warning and error functions.

		General code clean up.

	pacman-optimize:
		Use a sub-directory in /tmp for working files to make it easier to clean
		up at the end.

		Add quotes round $@ in die and die_r, otherwise printf can't display the
		message correctly.

	makepkg:
		Disable colour output if stderr is not a tty.

Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
This commit is contained in:
Andrew Fyfe 2007-08-29 10:49:24 +01:00 committed by Dan McGee
parent 9cceb3d9c4
commit 678983d262
4 changed files with 239 additions and 236 deletions

View File

@ -66,7 +66,7 @@ PACMAN_OPTS=
plain() { plain() {
local mesg=$1; shift local mesg=$1; shift
if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
printf "\033[1;37m ${mesg}\033[0m\n" "$@" >&2 printf "\033[1;37m ${mesg}\033[0m\n" "$@" >&2
else else
printf " ${mesg}\n" "$@" >&2 printf " ${mesg}\n" "$@" >&2
@ -75,7 +75,7 @@ plain() {
msg() { msg() {
local mesg=$1; shift local mesg=$1; shift
if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
printf "\033[1;32m==>\033[1;37m ${mesg}\033[0m\n" "$@" >&2 printf "\033[1;32m==>\033[1;37m ${mesg}\033[0m\n" "$@" >&2
else else
printf "==> ${mesg}\n" "$@" >&2 printf "==> ${mesg}\n" "$@" >&2
@ -84,7 +84,7 @@ msg() {
msg2() { msg2() {
local mesg=$1; shift local mesg=$1; shift
if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
printf "\033[1;34m ->\033[1;37m ${mesg}\033[0m\n" "$@" >&2 printf "\033[1;34m ->\033[1;37m ${mesg}\033[0m\n" "$@" >&2
else else
printf " -> ${mesg}\n" "$@" >&2 printf " -> ${mesg}\n" "$@" >&2
@ -93,7 +93,7 @@ msg2() {
warning() { warning() {
local mesg=$1; shift local mesg=$1; shift
if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
printf "\033[1;33m==> $(gettext "WARNING:")\033[1;37m ${mesg}\033[0m\n" "$@" >&2 printf "\033[1;33m==> $(gettext "WARNING:")\033[1;37m ${mesg}\033[0m\n" "$@" >&2
else else
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
@ -102,7 +102,7 @@ warning() {
error() { error() {
local mesg=$1; shift local mesg=$1; shift
if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
printf "\033[1;31m==> $(gettext "ERROR:")\033[1;37m ${mesg}\033[0m\n" "$@" >&2 printf "\033[1;31m==> $(gettext "ERROR:")\033[1;37m ${mesg}\033[0m\n" "$@" >&2
else else
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2

View File

@ -63,13 +63,13 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
} }
die() { die() {
error $@ error "$@"
exit 1 exit 1
} }
die_r() { die_r() {
rm -f $lockfile rm -f "$lockfile"
die $@ die "$@"
} }
if [ "$1" = "-h" -o "$1" = "--help" ]; then if [ "$1" = "-h" -o "$1" = "--help" ]; then
@ -87,8 +87,8 @@ if [ "$1" != "" ]; then
fi fi
# make sure pacman isn't running # make sure pacman isn't running
if [ -f $lockfile ]; then if [ -f "$lockfile" ]; then
die "$(gettext "Pacman lockfile was found. Cannot run while pacman is running.")" die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
fi fi
if [ ! -d "$dbroot" ]; then if [ ! -d "$dbroot" ]; then
@ -99,55 +99,58 @@ if [ ! -w "$dbroot" ]; then
die "$(gettext "You must have correct permissions to optimize the database.")" die "$(gettext "You must have correct permissions to optimize the database.")"
fi fi
workdir=$(mktemp -d /tmp/pacman-optimize.XXXXXXXXXX) ||
die_r "$(gettext "ERROR: Can not create temp directory for database building.")\n" >&2
# do not let pacman run while we do this # do not let pacman run while we do this
touch $lockfile touch "$lockfile"
# step 1: sum the old db # step 1: sum the old db
msg "$(gettext "MD5sum'ing the old database...")" msg "$(gettext "MD5sum'ing the old database...")"
find $dbroot -type f | sort | xargs md5sum > /tmp/pacsums.old find "$dbroot" -type f | sort | xargs md5sum > "$workdir/pacsums.old"
# step 2: tar it up # step 2: tar it up
msg "$(gettext "Tar'ing up %s...")" "$dbroot" msg "$(gettext "Tar'ing up %s...")" "$dbroot"
cd $dbroot cd "$dbroot"
bsdtar -czf /tmp/pacmanDB.tgz ./ bsdtar -czf "$workdir/pacmanDB.tgz" ./
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old rm -rf "$workdir"
die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot" die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot"
fi fi
# step 3: make and sum the new db # step 3: make and sum the new db
msg "$(gettext "Making and MD5sum'ing the new db...")" msg "$(gettext "Making and MD5sum'ing the new db...")"
mkdir $dbroot.new mkdir "$dbroot.new"
bsdtar -zxpf /tmp/pacmanDB.tgz -C $dbroot.new/ bsdtar -zxpf "$workdir/pacmanDB.tgz" -C "$dbroot.new/"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old rm -rf "$workdir"
rm -rf "$dbroot.new" die_r "$(gettext "Untar'ing %s failed.")" "$dbroot"
die_r "$(gettext "Untar'ing $dbroot failed.")"
fi fi
find "$dbroot.new" -type f | sort | sed -e 's/pacman.new/pacman/g' | \ find "$dbroot.new" -type f | sort | \
xargs md5sum > /tmp/pacsums.new xargs md5sum | sed 's#.new/##' > "$workdir/pacsums.new"
# step 4: compare the sums # step 4: compare the sums
msg "$(gettext "Checking integrity...")" msg "$(gettext "Checking integrity...")"
diff /tmp/pacsums.old /tmp/pacsums.new >/dev/null 2>&1 diff "$workdir/pacsums.old" "$workdir/pacsums.new" >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# failed # failed
# leave /tmp/pacsums.old and .new for checking to see what doesn't match up # leave /tmp/pacsums.old and .new for checking to see what doesn't match up
rm -rf "$dbroot.new" $lockfile /tmp/pacmanDB.tgz rm -rf "$dbroot.new"
die_r "$(gettext "integrity check FAILED, reverting to old database.")" die_r "$(gettext "Integrity check FAILED, reverting to old database.")"
fi fi
# step 5: remove the new temporary database and the old one # step 5: remove the new temporary database and the old one
# and use the .tgz to replace the old one # and use the .tgz to replace the old one
msg "$(gettext "Putting the new database in place...")" msg "$(gettext "Putting the new database in place...")"
rm -rf "$dbroot.new" "$dbroot"/* rm -rf "$dbroot.new" "$dbroot"/*
bsdtar -zxpf /tmp/pacmanDB.tgz -C "$dbroot"/ bsdtar -zxpf "$workdir/pacmanDB.tgz" -C "$dbroot/"
# remove the lock file, sum files, and .tgz of database # remove the lock file, sum files, and .tgz of database
rm -f $lockfile /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz rm -f "$lockfile"
rm -rf "$workdir"
echo echo
echo "$(gettext "Finished. Your pacman database has been optimized.")" msg "$(gettext "Finished. Your pacman database has been optimized.")"
echo echo
exit 0 exit 0

View File

@ -25,10 +25,31 @@ export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='@localedir@' export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@' myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@'
FORCE=0 FORCE=0
REPO_DB_FILE="" REPO_DB_FILE=""
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
}
# print usage instructions # print usage instructions
usage() { usage() {
printf "repo-add (pacman) %s\n\n" "$myver" printf "repo-add (pacman) %s\n\n" "$myver"
@ -51,37 +72,28 @@ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"
} }
# return calculated checksum of package
# arg1 - checksum type
# arg2 - path to package
get_checksum () {
case "$(echo "$1" | tr A-Z a-z)" in
md5) sum=$(md5sum $2); echo ${sum% *} ;;
sha1) sum=$(sha1sum $2); echo ${sum% *} ;;
sha256) sum=$(sha256sum $2); echo ${sum% *} ;;
sha384) sum=$(sha256sum $2); echo ${sum% *} ;;
sha512) sum=$(sha256sum $2); echo ${sum% *} ;;
esac
}
# return PKGINFO string for checksum type
# arg1 - checksum type
checksum_name () {
case "$(echo "$1" | tr A-Z a-z)" in
md5) echo "MD5SUM" ;;
sha1) echo "SHA1SUM" ;;
sha256) echo "SHA256SUM" ;;
sha384) echo "SHA384SUM" ;;
sha512) echo "SHA512SUM" ;;
esac
}
# test if a file is a repository DB # test if a file is a repository DB
test_repo_db_file () { test_repo_db_file () {
if [ -f "$REPO_DB_FILE" ]; then if [ -f "$REPO_DB_FILE" ]; then
[ "$(bsdtar -tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1 if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
return 0 # YES
fi
else else
true return 0 # YES - No database file is also aloud.
fi
return 1 # NO
}
# write a list entry
# arg1 - Entry name
# arg2 - List
# arg3 - File to write to
write_list_entry() {
if [ -n "$2" ]; then
echo "%$1%" >>$3
echo $2 | tr -s ' ' '\n' >>$3
echo "" >>$3
fi fi
} }
@ -90,36 +102,26 @@ test_repo_db_file () {
db_write_entry() db_write_entry()
{ {
# blank out all variables and set pkgfile # blank out all variables and set pkgfile
pkgfile=$(readlink -f $1) local pkgfile=$(readlink -f "$1")
export pkgname="" local pkgname pkgver pkgdesc url builddate packager csize size \
pkgver="" group depend backup license replaces provides conflict \
pkgdesc="" _groups _depends _backups _licenses _replaces _provides _conflicts
url=""
builddate=""
packager=""
csize=""
size=""
_groups=""
_depends=""
_backups=""
_licenses=""
_replaces=""
_provides=""
_conflicts=""
OLDIFS="$IFS" local OLDIFS="$IFS"
# IFS (field seperator) is only the newline character # IFS (field seperator) is only the newline character
IFS=" IFS="
" "
# read info from the zipped package # read info from the zipped package
for i in $(bsdtar -xOf "$pkgfile" .PKGINFO | grep -v "^#" |sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do local line
eval "${i}" for line in $(bsdtar -xOf "$pkgfile" .PKGINFO | \
case "$i" in grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
group=*) _groups="$_groups $group" ;; eval "$line"
depend=*) _depends="$_depends $depend" ;; case "$line" in
backup=*) _backups="$_backups $backup" ;; group=*) _groups="$_groups $group" ;;
license=*) _licenses="$_licenses $license" ;; depend=*) _depends="$_depends $depend" ;;
backup=*) _backups="$_backups $backup" ;;
license=*) _licenses="$_licenses $license" ;;
replaces=*) _replaces="$_replaces $replaces" ;; replaces=*) _replaces="$_replaces $replaces" ;;
provides=*) _provides="$_provides $provides" ;; provides=*) _provides="$_provides $provides" ;;
conflict=*) _conflicts="$_conflicts $conflict" ;; conflict=*) _conflicts="$_conflicts $conflict" ;;
@ -129,21 +131,23 @@ db_write_entry()
IFS=$OLDIFS IFS=$OLDIFS
# get compressed size of package # get compressed size of package
csize="$(du -b -L $pkgfile | cut -f1)" csize=$(du -b -L "$pkgfile" | cut -f 1)
cd $gstmpdir pushd "$gstmpdir" 2>&1 >/dev/null
# ensure $pkgname and $pkgver variables were found # ensure $pkgname and $pkgver variables were found
if [ -z "$pkgname" -o -z "$pkgver" ]; then if [ -z "$pkgname" -o -z "$pkgver" ]; then
printf "$(gettext " error: invalid package file")\n" error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
popd 2>&1 >/dev/null
return 1 return 1
fi fi
# remove any other package in the DB with same name # remove any other package in the DB with same name
local existing
for existing in *; do for existing in *; do
if [ "${existing%-*-*}" = "$pkgname" ]; then if [ "${existing%-*-*}" = "$pkgname" ]; then
printf "$(gettext ":: removing existing package '%s'")\n" "$existing" msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
rm -rf $existing rm -rf "$existing"
fi fi
done done
@ -152,67 +156,37 @@ db_write_entry()
cd "$pkgname-$pkgver" cd "$pkgname-$pkgver"
# create desc entry # create desc entry
printf "$(gettext ":: creating 'desc' db entry")\n" msg2 "$(gettext "Creating 'desc' db entry...")"
echo -e "%FILENAME%\n$(basename $1)\n" >>desc echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
echo -e "%NAME%\n$pkgname\n" >>desc echo -e "%NAME%\n$pkgname\n" >>desc
echo -e "%VERSION%\n$pkgver\n" >>desc echo -e "%VERSION%\n$pkgver\n" >>desc
if [ -n "$pkgdesc" ]; then [ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc
echo -e "%DESC%\n$pkgdesc\n" >>desc write_list_entry "GROUPS" "$_groups" "desc"
fi
if [ -n "$_groups" ]; then
echo "%GROUPS%" >>desc
echo $_groups | tr -s ' ' '\n' >>desc
echo "" >>desc
fi
[ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc [ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc
[ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc [ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc
# compute checksums # compute checksums
for chk in ${DB_CHECKSUMS[@]}; do msg2 "$(gettext "Computing md5 checksums...")"
name="$(checksum_name $chk)" echo -e "%MD5SUM%\n$(md5sum "$pkgfile" | cut -d ' ' -f 1)\n" >>desc
printf "$(gettext ":: computing %s checksums")\n" "$name"
if [ -n "$name" ]; then
echo -e "%$name%\n$(get_checksum $chk $pkgfile)\n" >>desc
fi
done
[ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
if [ -n "$_licenses" ]; then write_list_entry "LICENSE" "$_licenses" "desc"
echo "%LICENSE%" >>desc
echo $_licenses | tr -s ' ' '\n' >>desc
echo "" >>desc
fi
[ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc [ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc
[ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc [ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc
[ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc [ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc
write_list_entry "REPLACES" "$_replaces" "desc"
if [ -n "$_replaces" ]; then [ $FORCE -eq 1 ] && echo -e "%FORCE%\n" >>desc
echo "%REPLACES%" >>desc
echo $_replaces | tr -s ' ' '\n' >>desc
echo "" >>desc
fi
[ "$FORCE" = "1" ] && echo -e "%FORCE%\n" >>desc
# create depends entry # create depends entry
echo ":: creating 'depends' db entry" msg2 "$(gettext "Creating 'depends' db entry...")"
if [ -n "$_depends" ]; then write_list_entry "DEPENDS" "$_depends" "depends"
echo "%DEPENDS%" >>depends write_list_entry "CONFLICTS" "$_conflicts" "depends"
echo $_depends | tr -s ' ' '\n' >>depends write_list_entry "PROVIDES" "$_provides" "depends"
echo "" >>depends
fi
if [ -n "$_conflicts" ]; then
echo "%CONFLICTS%" >>depends
echo $_conflicts | tr -s ' ' '\n' >>depends
echo "" >>depends
fi
if [ -n "$_provides" ]; then
echo "%PROVIDES%" >>depends
echo $_provides | tr -s ' ' '\n' >>depends
echo "" >>depends
fi
# preserve the modification time # preserve the modification time
touch -r "$pkgfile" desc depends touch -r "$pkgfile" desc depends
popd 2>&1 >/dev/null
} # end db_write_entry } # end db_write_entry
# PROGRAM START # PROGRAM START
@ -236,10 +210,10 @@ if [ $# -lt 2 ]; then
fi fi
# source system and user makepkg.conf # source system and user makepkg.conf
if [ -r @sysconfdir@/makepkg.conf ]; then if [ -r "$confdir/makepkg.conf" ]; then
source @sysconfdir@/makepkg.conf source "$confdir/makepkg.conf"
else else
printf "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")\n" >&2 error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
exit 1 # $E_CONFIG_ERROR exit 1 # $E_CONFIG_ERROR
fi fi
@ -248,64 +222,65 @@ if [ -r ~/.makepkg.conf ]; then
fi fi
# main routine # main routine
if [ $# -gt 1 ]; then gstmpdir=$(mktemp -d /tmp/repo-add.XXXXXXXXXX) || (\
gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ error "$(gettext "Cannot create temp directory for database building.")"; \
printf "$(gettext "cannot create temp directory for database building")\n"; \
exit 1) exit 1)
success=0 success=0
# parse arguements # parse arguements
for arg in $@; do for arg in "$@"; do
if [ "$arg" == "--force" -o "$arg" == "-f" ]; then if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
FORCE=1 FORCE=1
elif [ -z "$REPO_DB_FILE" ]; then elif [ -z "$REPO_DB_FILE" ]; then
REPO_DB_FILE="$(readlink -f $arg)" REPO_DB_FILE=$(readlink -f "$arg")
if ! test_repo_db_file; then if ! test_repo_db_file; then
printf "$(gettext "error: repository file '%s' is not a proper pacman db")\n" "$REPO_DB_FILE" error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
exit 1 exit 1
elif [ -f "$REPO_DB_FILE" ]; then elif [ -f "$REPO_DB_FILE" ]; then
printf "$(gettext ":: extracting database to a temporary location")\n" msg "$(gettext "Extracting database to a temporary location...")"
bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir" bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
fi
else
if [ -f "$arg" ]; then
if ! bsdtar -tf "$arg" .PKGINFO 2>&1 >/dev/null; then
printf "$(gettext "error: '%s' is not a package file, skipping")\n" "$arg"
else
printf "$(gettext ":: adding package '%s'")\n" "$arg"
this_dir="$(pwd)"
if db_write_entry "$arg"; then
success=1
fi
cd $this_dir
fi
else
printf "$(gettext "error: package '%s' not found")\n" "$arg"
fi
fi
done
# if all operations were a success, rezip database
if [ "$success" = "1" ]; then
printf "$(gettext ":: creating updated database file %s")\n" "$REPO_DB_FILE"
cd $gstmpdir
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) bsdtar -c * | gzip -9 >$REPO_DB_FILE ;;
bz2) bsdtar -c * | bzip2 -9 >$REPO_DB_FILE ;;
*) printf "$(gettext "warning: no compression set")\n"
bsdtar -c * >$REPO_DB_FILE;;
esac
fi fi
else else
printf "$(gettext ":: no packages modified, nothing to do")\n" if [ -f "$arg" ]; then
if ! bsdtar -tf "$arg" .PKGINFO 2>&1 >/dev/null; then
error "$(gettext "'%s' is not a package file, skipping")" "$arg"
else
msg "$(gettext "Adding package '%s'")" "$arg"
if db_write_entry "$arg"; then
success=1
fi
fi
else
error "$(gettext "Package '%s' not found.")" "$arg"
fi
fi fi
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.")"
fi fi
# remove the temp directory used to unzip # remove the temp directory used to unzip
[ -d "$gstmpdir" ] && rm -rf $gstmpdir [ -d "$gstmpdir" ] && rm -rf "$gstmpdir"
# vim: set ts=2 sw=2 noet: # vim: set ts=2 sw=2 noet:

View File

@ -25,10 +25,31 @@ export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='@localedir@' export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@' myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@'
FORCE=0 FORCE=0
REPO_DB_FILE="" REPO_DB_FILE=""
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
}
# print usage instructions # print usage instructions
usage() { usage() {
printf "$(gettext "repo-remove %s\n\n")" $myver printf "$(gettext "repo-remove %s\n\n")" $myver
@ -51,24 +72,28 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
# test if a file is a repository DB # test if a file is a repository DB
test_repo_db_file () { test_repo_db_file () {
if [ -f "$REPO_DB_FILE" ]; then if [ -f "$REPO_DB_FILE" ]; then
[ "$(bsdtar -tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1 if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
else return 0 # YES
true fi
fi fi
return 1 # NO
} }
# remove existing entries from the DB # remove existing entries from the DB
db_remove_entry() db_remove_entry() {
{ pushd "$gstmpdir" 2>&1 >/dev/null
cd $gstmpdir
# remove any other package in the DB with same name # remove any other package in the DB with same name
local existing
for existing in *; do for existing in *; do
if [ "${existing%-*-*}" = "$1" ]; then if [ "${existing%-*-*}" = "$1" ]; then
printf "$(gettext ":: removing existing package '%s'")\n" "$existing" msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
rm -rf $existing rm -rf "$existing"
fi fi
done done
popd 2>&1 >/dev/null
} # end db_remove_entry } # end db_remove_entry
# PROGRAM START # PROGRAM START
@ -92,10 +117,10 @@ if [ $# -lt 2 ]; then
fi fi
# source system and user makepkg.conf # source system and user makepkg.conf
if [ -r @sysconfdir@/makepkg.conf ]; then if [ -r "$confdir/makepkg.conf" ]; then
source @sysconfdir@/makepkg.conf source "$confdir/makepkg.conf"
else else
printf "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")\n" >&2 error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
exit 1 # $E_CONFIG_ERROR exit 1 # $E_CONFIG_ERROR
fi fi
@ -104,53 +129,53 @@ if [ -r ~/.makepkg.conf ]; then
fi fi
# main routine # main routine
if [ $# -gt 1 ]; then gstmpdir=$(mktemp -d /tmp/repo-remove.XXXXXXXXXX) || (\
gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ error "$(gettext "Cannot create temp directory for database building.")"; \
printf "$(gettext "cannot create temp directory for database building")\n"; \
exit 1) exit 1)
success=0 success=0
# parse arguements # parse arguements
for arg in $@; do for arg in "$@"; do
if [ -z "$REPO_DB_FILE" ]; then if [ -z "$REPO_DB_FILE" ]; then
REPO_DB_FILE="$(readlink -f $arg)" REPO_DB_FILE=$(readlink -f "$arg")
if ! test_repo_db_file; then if ! test_repo_db_file; then
printf "$(gettext "error: repository file '%s' is not a proper pacman db")\n" "$REPO_DB_FILE" error "$(gettext "Repository file '%s' is not a proper pacman database.")\n" "$REPO_DB_FILE"
exit 1 exit 1
elif [ -f "$REPO_DB_FILE" ]; then elif [ -f "$REPO_DB_FILE" ]; then
printf "$(gettext ":: extracting database to a temporary location")\n" msg "$(gettext "Extracting database to a temporary location...")"
bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir" bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
fi
else
printf "$(gettext ":: searching for package '%s'")\n"
this_dir="$(pwd)"
if db_remove_entry "$arg"; then
success=1
else
printf "$(gettext "error: package matching '%s' not found")\n" "$arg"
fi
cd $this_dir
fi
done
# if all operations were a success, rezip database
if [ "$success" = "1" ]; then
printf "$(gettext ":: creating updated database file %s")\n" "$REPO_DB_FILE"
cd $gstmpdir
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) bsdtar -c * | gzip -9 >$REPO_DB_FILE ;;
bz2) bsdtar -c * | bzip2 -9 >$REPO_DB_FILE ;;
*) printf "$(gettext "warning: no compression set")\n"
bsdtar -c * >$REPO_DB_FILE;;
esac
fi fi
else else
printf "$(gettext ":: no packages modified, nothing to do")\n" msg "$(gettext "Searching for package '%s'...")" "$arg"
if db_remove_entry "$arg"; then
success=1
else
error "$(gettext "Package matching '%s' not found.")" "$arg"
fi
fi fi
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.")"
fi fi
# remove the temp directory used to unzip # remove the temp directory used to unzip