Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts/repo-add.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/repo-add.sh.in')
-rw-r--r--scripts/repo-add.sh.in138
1 files changed, 97 insertions, 41 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 63d94d37..b6772db6 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -1,9 +1,11 @@
#!/bin/bash
#
# repo-add - add a package to a given repo database file
+# repo-remove - remove a package entry from a given repo database file
# @configure_input@
#
-# Copyright (c) 2006 Aaron Griffin <aaron@archlinux.org>
+# Copyright (c) 2006-2008 Aaron Griffin <aaron@archlinux.org>
+# Copyright (c) 2007-2008 Dan McGee <dan@archlinux.org>
#
# 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
@@ -25,18 +27,20 @@ export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@'
-FORCE=0
+QUIET=0
REPO_DB_FILE=""
# ensure we have a sane umask set
umask 0022
msg() {
+ [ $QUIET -ne 0 ] && return
local mesg=$1; shift
printf "==> ${mesg}\n" "$@" >&1
}
msg2() {
+ [ $QUIET -ne 0 ] && return
local mesg=$1; shift
printf " -> ${mesg}\n" "$@" >&1
}
@@ -53,34 +57,41 @@ error() {
# print usage instructions
usage() {
- printf "repo-add (pacman) %s\n\n" "$myver"
- printf "$(gettext "Usage: %s <path-to-db> [--force] <package> ...\n\n")" "$0"
+ printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
+ printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package> ...\n")"
+ printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename> ...\n\n")"
printf "$(gettext "\
repo-add will update a package database by reading a package file.\n\
Multiple packages to add can be specified on the command line.\n\n")"
printf "$(gettext "\
-The --force flag will add a 'force' entry to the sync database, which\n\
-tells pacman to skip its internal version number checking and update\n\
-the package regardless.\n\n")"
+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")"
+ printf "$(gettext "\
+The -q/--quiet flag to either program will force silent running except\n\
+in the case of warnings or errors.\n\n")"
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
+ echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
}
version() {
- printf "repo-add (pacman) %s\n" "$myver"
+ printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
printf "$(gettext "\
-Copyright (C) 2006 Aaron Griffin <aaron@archlinux.org>.\n\n\
+Copyright (C) 2006-2008 Aaron Griffin <aaron@archlinux.org>.\n\
+Copyright (c) 2007-2008 Dan McGee <dan@archlinux.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")"
}
# test if a file is a repository DB
+# arg1 - command name (repo-add, repo-remove)
test_repo_db_file () {
if [ -f "$REPO_DB_FILE" ]; then
if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
return 0 # YES
fi
- else
- return 0 # YES - No database file is also allowed
+ elif [ "$1" == "repo-add" ]; then
+ return 0 # YES - No database file is also allowed if we are adding
fi
return 1 # NO
@@ -102,8 +113,8 @@ write_list_entry() {
# arg1 - path to delta
db_write_delta()
{
- # blank out all variables and set deltafile
- local deltafile=$(readlink -f "$1")
+ # blank out all variables and set deltafile to absolute path
+ local deltafile=$($realpath "$1")
local filename=$(basename "$deltafile")
local deltavars pkgname fromver tover arch csize md5sum
@@ -117,7 +128,7 @@ db_write_delta()
# get md5sum and size of delta
md5sum="$(md5sum "$deltafile" | cut -d ' ' -f 1)"
- csize=$(du -b -L "$deltafile" | cut -f 1)
+ csize=$(du -kL "$deltafile" | awk '{print $1 * 1024}')
# ensure variables were found
if [ -z "$pkgname" -o -z "$fromver" -o -z "$tover" -o -z "$arch" ]; then
@@ -133,8 +144,8 @@ db_write_delta()
# arg1 - path to package
db_write_entry()
{
- # blank out all variables and set pkgfile
- local pkgfile=$(readlink -f "$1")
+ # blank out all variables and set pkgfile to an absolute path
+ local pkgfile=$($realpath "$1")
local pkgname pkgver pkgdesc url builddate packager csize size \
group depend backup license replaces provides conflict force \
_groups _depends _backups _licenses _replaces _provides _conflicts \
@@ -164,7 +175,7 @@ db_write_entry()
IFS=$OLDIFS
# get compressed size of package
- csize=$(du -b -L "$pkgfile" | cut -f 1)
+ csize=$(du -kL "$pkgfile" | awk '{print $1 * 1024}')
startdir=$(pwd)
pushd "$gstmpdir" 2>&1 >/dev/null
@@ -176,14 +187,8 @@ db_write_entry()
return 1
fi
- # remove any other package in the DB with same name
- local existing
- for existing in *; do
- if [ "${existing%-*-*}" = "$pkgname" ]; then
- msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
- rm -rf "$existing"
- fi
- done
+ # remove an existing entry if it exists, ignore failures
+ db_remove_entry "$pkgname"
# create package directory
mkdir "$pkgname-$pkgver"
@@ -209,7 +214,7 @@ db_write_entry()
[ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc
[ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc
write_list_entry "REPLACES" "$_replaces" "desc"
- [ $FORCE -eq 1 -o -n "$force" ] && echo -e "%FORCE%\n" >>desc
+ [ -n "$force" ] && echo -e "%FORCE%\n" >>desc
# create depends entry
msg2 "$(gettext "Creating 'depends' db entry...")"
@@ -236,7 +241,7 @@ db_write_entry()
if db_write_delta "$delta"; then
msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")"
else
- msg2 "$(gettext "Could not add delta '%s'")" "$(basename "$delta")"
+ warning "$(gettext "Could not add delta '%s'")" "$(basename "$delta")"
fi
fi
done
@@ -250,6 +255,23 @@ db_write_entry()
popd 2>&1 >/dev/null
} # end db_write_entry
+# remove existing entries from the DB
+# arg1 - package name
+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
+ msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
+ rm -rf "$existing"
+ fi
+ done
+
+ popd 2>&1 >/dev/null
+} # end db_remove_entry
+
# PROGRAM START
# determine whether we have gettext; make it a no-op if we do not
@@ -277,6 +299,16 @@ if [ $# -lt 2 ]; then
exit 1
fi
+# check for and store the name of a realpath-like program
+if [ $(type -t realpath) ]; then
+ realpath='realpath'
+elif [ $(type -t readlink) ]; then
+ realpath='readlink -f'
+else
+ error "$(gettext "Either realpath or readlink are required by repo-add.")"
+ exit 1 # $E_MISSING_PROGRAM
+fi
+
# source system and user makepkg.conf
if [ -r "$confdir/makepkg.conf" ]; then
source "$confdir/makepkg.conf"
@@ -290,18 +322,29 @@ if [ -r ~/.makepkg.conf ]; then
fi
# main routine
-gstmpdir=$(mktemp -d /tmp/repo-add.XXXXXXXXXX) || (\
+gstmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
error "$(gettext "Cannot create temp directory for database building.")"; \
exit 1)
+# figure out what program we are
+cmd="$(basename $0)"
+if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then
+ error "$(gettext "Invalid command name '%s' specified.")" "$cmd"
+ exit 1
+fi
+
success=0
# parse arguments
for arg in "$@"; do
if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
- FORCE=1
+ warning "$(gettext "the -f and --force options are no longer recognized")"
+ msg2 "$(gettext "use options=(force) in the PKGBUILD instead")"
+ elif [ "$arg" == "--quiet" -o "$arg" == "-q" ]; then
+ QUIET=1
elif [ -z "$REPO_DB_FILE" ]; then
- REPO_DB_FILE=$(readlink -f "$arg")
- if ! test_repo_db_file; then
+ # store absolute path to repo DB
+ REPO_DB_FILE=$($realpath "$arg")
+ if ! test_repo_db_file $cmd; then
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
exit 1
elif [ -f "$REPO_DB_FILE" ]; then
@@ -309,25 +352,35 @@ for arg in "$@"; do
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"
+ if [ "$cmd" == "repo-add" ]; then
+ 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
- msg "$(gettext "Adding package '%s'")" "$arg"
+ error "$(gettext "Package '%s' not found.")" "$arg"
+ fi
+ elif [ "$cmd" == "repo-remove" ]; then
+ msg "$(gettext "Searching for package '%s'...")" "$arg"
- if db_write_entry "$arg"; then
- success=1
- fi
+ if db_remove_entry "$arg"; then
+ success=1
+ else
+ error "$(gettext "Package matching '%s' not found.")" "$arg"
fi
- else
- error "$(gettext "Package '%s' not found.")" "$arg"
fi
fi
done
# if all operations were a success, re-zip database
if [ $success -eq 1 ]; then
- msg "$(gettext "Creating updated database file %s")" "$REPO_DB_FILE"
+ msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
pushd "$gstmpdir" 2>&1 >/dev/null
if [ -n "$(ls)" ]; then
@@ -341,6 +394,9 @@ if [ $success -eq 1 ]; then
esac
bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" *
+ elif [ "$cmd" == "repo-remove" ]; then
+ error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE"
+ rm "$REPO_DB_FILE"
fi
popd 2>&1 >/dev/null