Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/makepkg.sh.in94
-rw-r--r--scripts/pacman-optimize.sh.in49
-rw-r--r--scripts/repo-add.sh.in284
-rw-r--r--scripts/repo-remove.sh.in130
4 files changed, 298 insertions, 259 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 30e6b711..d5b41144 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -26,6 +26,11 @@
# USA.
#
+# makepkg uses quite a few external programs during its execution. You
+# need to have at least the following installed for makepkg to function:
+# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils),
+# getopt (util-linux), gettext, grep, gzip, sed
+
# gettext initialization
export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='@localedir@'
@@ -61,7 +66,7 @@ PACMAN_OPTS=
plain() {
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
else
printf " ${mesg}\n" "$@" >&2
@@ -70,7 +75,7 @@ plain() {
msg() {
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
else
printf "==> ${mesg}\n" "$@" >&2
@@ -79,7 +84,7 @@ msg() {
msg2() {
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
else
printf " -> ${mesg}\n" "$@" >&2
@@ -88,7 +93,7 @@ msg2() {
warning() {
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
else
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
@@ -97,7 +102,7 @@ warning() {
error() {
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
else
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
@@ -294,9 +299,9 @@ get_downloadclient() {
check_deps() {
[ $# -gt 0 ] || return
- pmout=$(pacman $PACMAN_OPTS -T $*)
+ pmout=$(pacman $PACMAN_OPTS -T "$@")
ret=$?
- if [ $ret -eq 1 ]; then #unresolved deps
+ if [ $ret -eq 127 ]; then #unresolved deps
echo "$pmout"
elif [ $ret -ne 0 ]; then
error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout"
@@ -327,9 +332,9 @@ handledeps() {
local ret=0
if [ "$ASROOT" = 0 ]; then
- sudo pacman $PACMAN_OPTS -S $striplist || ret=$?
+ sudo pacman $PACMAN_OPTS -S --asdeps $striplist || ret=$?
else
- pacman $PACMAN_OPTS -S $striplist || ret=$?
+ pacman $PACMAN_OPTS -S --asdeps $striplist || ret=$?
fi
if [ $ret -ne 0 ]; then
@@ -433,16 +438,25 @@ remove_deps() {
download_sources() {
msg "$(gettext "Retrieving Sources...")"
+
+ if [ ! -w "$SRCDEST" ] ; then
+ error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+
+ pushd "$SRCDEST" &>/dev/null
+
local netfile
for netfile in ${source[@]}; do
local file=$(strip_url "$netfile")
- if [ -f "../$file" ]; then
+ if [ -f "$startdir/$file" ]; then
msg2 "$(gettext "Found %s in build dir")" "$file"
- cp "../$file" .
+ cp -s --remove-destination "$startdir/$file" "$srcdir/"
continue
elif [ -f "$SRCDEST/$file" ]; then
msg2 "$(gettext "Using cached copy of %s")" "$file"
- cp "$SRCDEST/$file" .
+ cp -s --remove-destination "$SRCDEST/$file" "$srcdir/"
continue
fi
@@ -458,17 +472,10 @@ download_sources() {
plain "$(gettext "Aborting...")"
exit 1
fi
-
- if [ -n "$SRCDEST" ]; then
- mkdir -p "$SRCDEST" && cp "$file" "$SRCDEST" || ret=$?
- if [ $ret -gt 0 ]; then
- warning "$(gettext "You do not have correct permissions to cache source in %s")" "$SRCDEST"
- cp "$file" ..
- fi
- else
- cp "$file" ..
- fi
+ cp -s --remove-destination "$SRCDEST/$file" "$srcdir/"
done
+
+ popd &>/dev/null
}
generate_checksums() {
@@ -504,6 +511,17 @@ generate_checksums() {
local netfile
for netfile in ${source[@]}; do
local file="$(strip_url "$netfile")"
+
+ if [ ! -f "$file" ] ; then
+ if [ ! -f "$SRCDEST/$file" ] ; then
+ error "$(gettext "Unable to find source file %s to generate checksum.")" "$file"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ else
+ file=$SRCDEST/$file
+ fi
+ fi
+
local sum="$(${integ}sum "$file" | cut -d ' ' -f 1)"
[ $ct -gt 0 ] && echo -n "$indent"
echo -n "'$sum'"
@@ -541,6 +559,16 @@ check_checksums() {
file="$(strip_url "$file")"
echo -n " $file ... " >&2
+ if [ ! -f "$file" ] ; then
+ if [ ! -f "$file" ] ; then
+ echo "$(gettext "NOT FOUND")" >&2
+ errors=1
+ continue
+ else
+ file=$SRCDEST/$file
+ fi
+ fi
+
if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c - &>/dev/null; then
echo "$(gettext "Passed")" >&2
else
@@ -548,7 +576,7 @@ check_checksums() {
errors=1
fi
- idx=$(($idx+1))
+ idx=$((idx + 1))
done
if [ $errors -gt 0 ]; then
@@ -572,8 +600,18 @@ extract_sources() {
continue
fi
+ if [ ! -f "$file" ] ; then
+ if [ ! -f "$SRCDEST/$file" ] ; then
+ error "$(gettext "Unable to find source file %s for extraction.")" "$file"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ else
+ file=$SRCDEST/$file
+ fi
+ fi
+
# fix flyspray #6246
- local file_type=$(file -biz "$file")
+ local file_type=$(file -bizL "$file")
local cmd=''
case "$file_type" in
*application/x-tar*|*application/x-zip*|*application/x-cpio*)
@@ -631,7 +669,7 @@ run_build() {
umask 0022
# ensure all necessary build variables are exported
- export CFLAGS CXXFLAGS MAKEFLAGS
+ export CFLAGS CXXFLAGS MAKEFLAGS CHOST
local ret=0
if [ "$LOGGING" = "1" ]; then
@@ -1107,13 +1145,13 @@ if [ "$INFAKEROOT" = "0" ]; then
error "$(gettext "The --asroot option is meant for the root user only.")"
plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
exit 1 # $E_USER_ABORT
- elif [ "$(check_buildenv fakeroot)" = "y" ]; then
+ elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
if [ ! $(type -p fakeroot) ]; then
error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
plain "$(gettext "in the BUILDENV array in %s.")" "$confdir/makepkg.conf"
exit 1
fi
- else
+ elif [ $EUID -gt 0 ]; then
warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
plain "$(gettext "placing 'fakeroot' in the BUILDENV array in makepkg.conf.")"
@@ -1174,7 +1212,7 @@ if [ $(echo "$pkgrel" | grep '-') ]; then
fi
if ! in_array $CARCH ${arch[@]}; then
- if "$IGNOREARCH" = "0" ]; then
+ if [ "$IGNOREARCH" = "0" ]; then
error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH"
plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
plain "$(gettext "such as arch=('%s').")" "$CARCH"
diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in
index fe59e661..83c56a77 100644
--- a/scripts/pacman-optimize.sh.in
+++ b/scripts/pacman-optimize.sh.in
@@ -63,13 +63,13 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
}
die() {
- error $@
+ error "$@"
exit 1
}
die_r() {
- rm -f $lockfile
- die $@
+ rm -f "$lockfile"
+ die "$@"
}
if [ "$1" = "-h" -o "$1" = "--help" ]; then
@@ -87,8 +87,8 @@ if [ "$1" != "" ]; then
fi
# make sure pacman isn't running
-if [ -f $lockfile ]; then
- die "$(gettext "Pacman lockfile was found. Cannot run while pacman is running.")"
+if [ -f "$lockfile" ]; then
+ die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
fi
if [ ! -d "$dbroot" ]; then
@@ -99,55 +99,58 @@ if [ ! -w "$dbroot" ]; then
die "$(gettext "You must have correct permissions to optimize the database.")"
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
-touch $lockfile
+touch "$lockfile"
# step 1: sum the old db
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
msg "$(gettext "Tar'ing up %s...")" "$dbroot"
-cd $dbroot
-tar -czf /tmp/pacmanDB.tgz ./
+cd "$dbroot"
+bsdtar -czf "$workdir/pacmanDB.tgz" ./
if [ $? -ne 0 ]; then
- rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old
+ rm -rf "$workdir"
die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot"
fi
# step 3: make and sum the new db
msg "$(gettext "Making and MD5sum'ing the new db...")"
-mkdir $dbroot.new
-tar -zxpf /tmp/pacmanDB.tgz -C $dbroot.new/
+mkdir "$dbroot.new"
+bsdtar -zxpf "$workdir/pacmanDB.tgz" -C "$dbroot.new/"
if [ $? -ne 0 ]; then
- rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old
- rm -rf "$dbroot.new"
- die_r "$(gettext "Untar'ing $dbroot failed.")"
+ rm -rf "$workdir"
+ die_r "$(gettext "Untar'ing %s failed.")" "$dbroot"
fi
-find "$dbroot.new" -type f | sort | sed -e 's/pacman.new/pacman/g' | \
- xargs md5sum > /tmp/pacsums.new
+find "$dbroot.new" -type f | sort | \
+ xargs md5sum | sed 's#.new/##' > "$workdir/pacsums.new"
# step 4: compare the sums
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
# failed
# leave /tmp/pacsums.old and .new for checking to see what doesn't match up
- rm -rf "$dbroot.new" $lockfile /tmp/pacmanDB.tgz
- die_r "$(gettext "integrity check FAILED, reverting to old database.")"
+ rm -rf "$dbroot.new"
+ die_r "$(gettext "Integrity check FAILED, reverting to old database.")"
fi
# step 5: remove the new temporary database and the old one
# and use the .tgz to replace the old one
msg "$(gettext "Putting the new database in place...")"
rm -rf "$dbroot.new" "$dbroot"/*
-tar -zxpf /tmp/pacmanDB.tgz -C "$dbroot"/
+bsdtar -zxpf "$workdir/pacmanDB.tgz" -C "$dbroot/"
# 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 "$(gettext "Finished. Your pacman database has been optimized.")"
+msg "$(gettext "Finished. Your pacman database has been optimized.")"
echo
exit 0
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 1df650bd..cb741d76 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -25,10 +25,30 @@ export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@'
+confdir='@sysconfdir@'
FORCE=0
REPO_DB_FILE=""
-TMP_DIR=""
+
+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
usage() {
@@ -52,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")"
}
-# 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_repo_db_file () {
if [ -f "$REPO_DB_FILE" ]; then
- [ "$(tar 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
- 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
}
@@ -91,36 +102,26 @@ test_repo_db_file () {
db_write_entry()
{
# blank out all variables and set pkgfile
- pkgfile=$(readlink -f $1)
- export pkgname=""
- pkgver=""
- pkgdesc=""
- url=""
- builddate=""
- packager=""
- csize=""
- size=""
- _groups=""
- _depends=""
- _backups=""
- _licenses=""
- _replaces=""
- _provides=""
- _conflicts=""
-
- OLDIFS="$IFS"
+ local pkgfile=$(readlink -f "$1")
+ local pkgname pkgver pkgdesc url builddate packager csize size \
+ group depend backup license replaces provides conflict \
+ _groups _depends _backups _licenses _replaces _provides _conflicts
+
+ local OLDIFS="$IFS"
# IFS (field seperator) is only the newline character
IFS="
"
# read info from the zipped package
- for i in $(tar xOf "$pkgfile" .PKGINFO | grep -v "^#" |sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
- eval "${i}"
- case "$i" in
- group=*) _groups="$_groups $group" ;;
- depend=*) _depends="$_depends $depend" ;;
- backup=*) _backups="$_backups $backup" ;;
- license=*) _licenses="$_licenses $license" ;;
+ local line
+ for line in $(bsdtar -xOf "$pkgfile" .PKGINFO | \
+ grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
+ eval "$line"
+ case "$line" in
+ group=*) _groups="$_groups $group" ;;
+ depend=*) _depends="$_depends $depend" ;;
+ backup=*) _backups="$_backups $backup" ;;
+ license=*) _licenses="$_licenses $license" ;;
replaces=*) _replaces="$_replaces $replaces" ;;
provides=*) _provides="$_provides $provides" ;;
conflict=*) _conflicts="$_conflicts $conflict" ;;
@@ -130,21 +131,23 @@ db_write_entry()
IFS=$OLDIFS
# 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
if [ -z "$pkgname" -o -z "$pkgver" ]; then
- echo "$(gettext " error: invalid package file")"
+ error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
+ popd 2>&1 >/dev/null
return 1
fi
# remove any other package in the DB with same name
+ local existing
for existing in *; do
if [ "${existing%-*-*}" = "$pkgname" ]; then
- echo "$(gettext ":: removing existing package '%s'")" $existing
- rm -rf $existing
+ msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
+ rm -rf "$existing"
fi
done
@@ -153,67 +156,37 @@ db_write_entry()
cd "$pkgname-$pkgver"
# create desc entry
- echo "$(gettext ":: creating 'desc' db entry")"
- echo -e "%FILENAME%\n$(basename $1)\n" >>desc
+ msg2 "$(gettext "Creating 'desc' db entry...")"
+ echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
echo -e "%NAME%\n$pkgname\n" >>desc
echo -e "%VERSION%\n$pkgver\n" >>desc
- if [ -n "$pkgdesc" ]; then
- echo -e "%DESC%\n$pkgdesc\n" >>desc
- fi
- if [ -n "$_groups" ]; then
- echo "%GROUPS%" >>desc
- echo $_groups | tr -s ' ' '\n' >>desc
- echo "" >>desc
- fi
+ [ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc
+ write_list_entry "GROUPS" "$_groups" "desc"
[ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc
[ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc
# compute checksums
- for chk in ${DB_CHECKSUMS[@]}; do
- name="$(checksum_name $chk)"
- echo "$(gettext ":: computing %s checksums")" $name
- if [ -n "$name" ]; then
- echo -e "%$name%\n$(get_checksum $chk $pkgfile)\n" >>desc
- fi
- done
+ msg2 "$(gettext "Computing md5 checksums...")"
+ echo -e "%MD5SUM%\n$(md5sum "$pkgfile" | cut -d ' ' -f 1)\n" >>desc
[ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
- if [ -n "$_licenses" ]; then
- echo "%LICENSE%" >>desc
- echo $_licenses | tr -s ' ' '\n' >>desc
- echo "" >>desc
- fi
+ write_list_entry "LICENSE" "$_licenses" "desc"
[ -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
-
- if [ -n "$_replaces" ]; then
- echo "%REPLACES%" >>desc
- echo $_replaces | tr -s ' ' '\n' >>desc
- echo "" >>desc
- fi
- [ "$FORCE" = "1" ] && echo -e "%FORCE%\n" >>desc
+ write_list_entry "REPLACES" "$_replaces" "desc"
+ [ $FORCE -eq 1 ] && echo -e "%FORCE%\n" >>desc
# create depends entry
- echo ":: creating 'depends' db entry"
- if [ -n "$_depends" ]; then
- echo "%DEPENDS%" >>depends
- echo $_depends | tr -s ' ' '\n' >>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
+ msg2 "$(gettext "Creating 'depends' db entry...")"
+ write_list_entry "DEPENDS" "$_depends" "depends"
+ write_list_entry "CONFLICTS" "$_conflicts" "depends"
+ write_list_entry "PROVIDES" "$_provides" "depends"
# preserve the modification time
touch -r "$pkgfile" desc depends
+
+ popd 2>&1 >/dev/null
} # end db_write_entry
# PROGRAM START
@@ -237,10 +210,10 @@ if [ $# -lt 2 ]; then
fi
# source system and user makepkg.conf
-if [ -r @sysconfdir@/makepkg.conf ]; then
- source @sysconfdir@/makepkg.conf
+if [ -r "$confdir/makepkg.conf" ]; then
+ source "$confdir/makepkg.conf"
else
- echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2
+ error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
exit 1 # $E_CONFIG_ERROR
fi
@@ -249,64 +222,65 @@ if [ -r ~/.makepkg.conf ]; then
fi
# main routine
-if [ $# -gt 1 ]; then
- gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\
- echo "$(gettext "cannot create temp directory for database building")"; \
+gstmpdir=$(mktemp -d /tmp/repo-add.XXXXXXXXXX) || (\
+ error "$(gettext "Cannot create temp directory for database building.")"; \
exit 1)
- success=0
- # parse arguements
- for arg in $@; do
- if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
- FORCE=1
- elif [ -z "$REPO_DB_FILE" ]; then
- REPO_DB_FILE="$(readlink -f $arg)"
- if ! test_repo_db_file; then
- echo "$(gettext "error: repository file '%s' is not a proper pacman db")" $REPO_DB_FILE
- exit 1
- elif [ -f "$REPO_DB_FILE" ]; then
- echo "$(gettext ":: extracting database to a temporary location")"
- tar xf "$REPO_DB_FILE" -C "$gstmpdir"
- fi
- else
- if [ -f "$arg" ]; then
- if ! tar tf "$arg" .PKGINFO 2>&1 >/dev/null; then
- echo "$(gettext "error: '%s' is not a package file, skipping")" $arg
- else
- echo "$(gettext ":: adding package '%s'")" $arg
-
- this_dir="$(pwd)"
- if db_write_entry "$arg"; then
- success=1
- fi
- cd $this_dir
- fi
+success=0
+# parse arguements
+for arg in "$@"; do
+ if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
+ FORCE=1
+ elif [ -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.")" "$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"
+ fi
+ else
+ 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
- echo "$(gettext "error: package '%s' not found")" $arg
+ 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
- done
+ fi
+done
- # if all operations were a success, rezip database
- if [ "$success" = "1" ]; then
- echo "$(gettext ":: creating updated database file %s")" ${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) tar c * | gzip -9 >$REPO_DB_FILE ;;
- bz2) tar c * | bzip2 -9 >$REPO_DB_FILE ;;
- *) echo "$(gettext "warning: no compression set")"
- tar c * >$REPO_DB_FILE;;
- esac
- fi
- else
- echo "$(gettext ":: no packages modified, nothing to do")"
+# 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
# remove the temp directory used to unzip
-[ -d "$gstmpdir" ] && rm -rf $gstmpdir
+[ -d "$gstmpdir" ] && rm -rf "$gstmpdir"
# vim: set ts=2 sw=2 noet:
diff --git a/scripts/repo-remove.sh.in b/scripts/repo-remove.sh.in
index 63209728..617f04cf 100644
--- a/scripts/repo-remove.sh.in
+++ b/scripts/repo-remove.sh.in
@@ -25,10 +25,30 @@ export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@'
+confdir='@sysconfdir@'
FORCE=0
REPO_DB_FILE=""
-TMP_DIR=""
+
+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
usage() {
@@ -52,24 +72,28 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
# test if a file is a repository DB
test_repo_db_file () {
if [ -f "$REPO_DB_FILE" ]; then
- [ "$(tar tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1
- else
- true
+ if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
+ return 0 # YES
+ fi
fi
+
+ return 1 # NO
}
# remove existing entries from the DB
-db_remove_entry()
-{
- cd $gstmpdir
+db_remove_entry() {
+ pushd "$gstmpdir" 2>&1 >/dev/null
# remove any other package in the DB with same name
+ local existing
for existing in *; do
if [ "${existing%-*-*}" = "$1" ]; then
- echo "$(gettext ":: removing existing package '%s'")" $existing
- rm -rf $existing
+ msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
+ rm -rf "$existing"
fi
done
+
+ popd 2>&1 >/dev/null
} # end db_remove_entry
# PROGRAM START
@@ -93,10 +117,10 @@ if [ $# -lt 2 ]; then
fi
# source system and user makepkg.conf
-if [ -r @sysconfdir@/makepkg.conf ]; then
- source @sysconfdir@/makepkg.conf
+if [ -r "$confdir/makepkg.conf" ]; then
+ source "$confdir/makepkg.conf"
else
- echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2
+ error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
exit 1 # $E_CONFIG_ERROR
fi
@@ -105,53 +129,53 @@ if [ -r ~/.makepkg.conf ]; then
fi
# main routine
-if [ $# -gt 1 ]; then
- gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\
- echo "$(gettext "cannot create temp directory for database building")"; \
+gstmpdir=$(mktemp -d /tmp/repo-remove.XXXXXXXXXX) || (\
+ error "$(gettext "Cannot create temp directory for database building.")"; \
exit 1)
- 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
- echo "$(gettext "error: repository file '%s' is not a proper pacman db")" $REPO_DB_FILE
- exit 1
- elif [ -f "$REPO_DB_FILE" ]; then
- echo "$(gettext ":: extracting database to a temporary location")"
- tar xf "$REPO_DB_FILE" -C "$gstmpdir"
- fi
- else
- echo "$(gettext ":: searching for package '%s'")"
-
- this_dir="$(pwd)"
- if db_remove_entry "$arg"; then
- success=1
- else
- echo "$(gettext "error: package matching '%s' not found")" $arg
- fi
- cd $this_dir
+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"
fi
- done
+ else
+ msg "$(gettext "Searching for package '%s'...")" "$arg"
- # if all operations were a success, rezip database
- if [ "$success" = "1" ]; then
- echo "$(gettext ":: creating updated database file %s")" ${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) tar c * | gzip -9 >$REPO_DB_FILE ;;
- bz2) tar c * | bzip2 -9 >$REPO_DB_FILE ;;
- *) echo "$(gettext "warning: no compression set")"
- tar c * >$REPO_DB_FILE;;
- esac
+ if db_remove_entry "$arg"; then
+ success=1
+ else
+ error "$(gettext "Package matching '%s' not found.")" "$arg"
fi
- else
- echo "$(gettext ":: no packages modified, nothing to do")"
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
# remove the temp directory used to unzip