summaryrefslogtreecommitdiff
path: root/repo-remove
diff options
context:
space:
mode:
Diffstat (limited to 'repo-remove')
-rwxr-xr-xrepo-remove204
1 files changed, 130 insertions, 74 deletions
diff --git a/repo-remove b/repo-remove
index ef6f186..c4bf96f 100755
--- a/repo-remove
+++ b/repo-remove
@@ -20,29 +20,33 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+LICENSESDIR=/home/parabolavnx/licenses
+
# gettext initialization
export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='/usr/share/locale'
-myver='3.3.3'
-confdir='/etc'
+myver='3.5.0'
+confdir='/home/parabolavnx/etc'
QUIET=0
+DELTA=0
+WITHFILES=0
REPO_DB_FILE=
LOCKFILE=
CLEAN_LOCK=0
-startdir="$PWD"
# ensure we have a sane umask set
umask 0022
msg() {
+ (( QUIET )) && return
local mesg=$1; shift
printf "==> ${mesg}\n" "$@" >&1
}
msg2() {
- [ $QUIET -ne 0 ] && return
+ (( QUIET )) && return
local mesg=$1; shift
printf " -> ${mesg}\n" "$@" >&1
}
@@ -60,7 +64,7 @@ error() {
# print usage instructions
usage() {
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
- printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package|delta> ...\n")"
+ printf "$(gettext "Usage: repo-add [-d] [-f] [-q] <path-to-db> <package|delta> ...\n")"
printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")"
printf "$(gettext "\
repo-add will update a package database by reading a package file.\n\
@@ -71,7 +75,13 @@ 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 "\
Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\
-and errors\n\n")"
+and errors.\n\n")"
+ printf "$(gettext "\
+Use the -d/--delta flag to automatically generate and add a delta file\n\
+between the old entry and the new one, if the old package file is found\n\
+next to the new one.\n\n")"
+ printf "$(gettext "\
+Use the -f/--files flag to update a database including file entries.\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")"
}
@@ -90,7 +100,7 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
# arg2 - List
# arg3 - File to write to
write_list_entry() {
- if [ -n "$2" ]; then
+ if [[ -n $2 ]]; then
echo "%$1%" >>$3
echo -e $2 >>$3
fi
@@ -102,7 +112,7 @@ find_pkgentry()
local pkgentry
for pkgentry in $tmpdir/$pkgname*; do
name=${pkgentry##*/}
- if [ "${name%-*-*}" = "$pkgname" ]; then
+ if [[ ${name%-*-*} = $pkgname ]]; then
echo $pkgentry
return 0
fi
@@ -126,27 +136,26 @@ db_write_delta()
pkgname="$(get_delta_pkgname $deltafile)"
pkgentry=$(find_pkgentry $pkgname)
- if [ -z "$pkgentry" ]; then
+ if [[ -z $pkgentry ]]; then
+ error "$(gettext "No database entry for package '%s'.")" "$pkgname"
return 1
fi
deltas="$pkgentry/deltas"
- # create deltas file if it does not already exist
- if [ ! -f "$deltas" ]; then
- msg2 "$(gettext "Creating 'deltas' db entry...")"
- echo -e "%DELTAS%" >>$deltas
+ if [[ ! -f $deltas ]]; then
+ echo -e "%DELTAS%" >$deltas
fi
# get md5sum and compressed size of package
- md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')"
+ md5sum="$(openssl dgst -md5 "$deltafile")"
+ md5sum="${md5sum##* }"
csize=$(stat -L -c %s "$deltafile")
oldfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (source)" | sed 's/.*: *//')
newfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (output)" | sed 's/.*: *//')
if grep -q "$oldfile.*$newfile" $deltas; then
- warning "$(gettext "An entry for '%s' already existed")" "$deltafile"
sed -i.backup "/$oldfile.*$newfile/d" $deltas && rm -f $deltas.backup
- msg2 "$(gettext "Removing existing entry '%s'...")" "$deltafile"
fi
+ msg2 "$(gettext "Adding 'deltas' entry : %s -> %s")" "$oldfile" "$newfile"
echo ${deltafile##*/} $md5sum $csize $oldfile $newfile >> $deltas
return 0
@@ -161,11 +170,11 @@ db_remove_delta()
pkgname="$(get_delta_pkgname $deltafile)"
pkgentry=$(find_pkgentry $pkgname)
- if [ -z "$pkgentry" ]; then
+ if [[ -z $pkgentry ]]; then
return 1
fi
deltas="$pkgentry/deltas"
- if [ ! -f "$deltas" ]; then
+ if [[ ! -f $deltas ]]; then
return 1
fi
if grep -q "$filename" $deltas; then
@@ -183,7 +192,7 @@ db_write_entry()
{
# blank out all variables
local pkgfile="$1"
- local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager force \
+ local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager \
_groups _licenses _replaces _depends _conflicts _provides _optdepends
local OLDIFS="$IFS"
@@ -213,19 +222,27 @@ db_write_entry()
IFS=$OLDIFS
# get md5sum and compressed size of package
- md5sum="$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')"
+ md5sum="$(openssl dgst -md5 "$pkgfile")"
+ md5sum="${md5sum##* }"
csize=$(stat -L -c %s "$pkgfile")
# ensure $pkgname and $pkgver variables were found
- if [ -z "$pkgname" -o -z "$pkgver" ]; then
+ if [[ -z $pkgname || -z $pkgver ]]; then
error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
return 1
fi
- cd "$tmpdir"
-
- if [ -d "$pkgname-$pkgver" ]; then
+ pushd "$tmpdir" >/dev/null
+ if [[ -d $pkgname-$pkgver ]]; then
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
+ else
+ if (( DELTA )); then
+ pkgentry=$(find_pkgentry $pkgname)
+ if [[ -n $pkgentry ]]; then
+ local oldfilename=$(grep -A1 FILENAME $pkgentry/desc | tail -n1)
+ local oldfile="$(dirname $1)/$oldfilename"
+ fi
+ fi
fi
# remove an existing entry if it exists, ignore failures
@@ -233,36 +250,35 @@ db_write_entry()
# create package directory
mkdir "$pkgname-$pkgver"
- cd "$pkgname-$pkgver"
+ pushd "$pkgname-$pkgver" >/dev/null
# restore an eventual deltas file
- [ -f "../$pkgname.deltas" ] && mv "../$pkgname.deltas" deltas
+ [[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas
# create desc entry
- msg2 "$(gettext "Creating 'desc' db entry...")"
+ msg2 "$(gettext "Creating '%s' db entry...")" 'desc'
echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
echo -e "%NAME%\n$pkgname\n" >>desc
- [ -n "$pkgbase" ] && echo -e "%BASE%\n$pkgbase\n" >>desc
+ [[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc
echo -e "%VERSION%\n$pkgver\n" >>desc
- [ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc
+ [[ -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
+ [[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc
+ [[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc
# compute checksums
msg2 "$(gettext "Computing md5 checksums...")"
echo -e "%MD5SUM%\n$md5sum\n" >>desc
- [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
+ [[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc
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
+ [[ -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
write_list_entry "REPLACES" "$_replaces" "desc"
- [ -n "$force" ] && echo -e "%FORCE%\n" >>desc
# create depends entry
- msg2 "$(gettext "Creating 'depends' db entry...")"
+ msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
# create the file even if it will remain empty
touch "depends"
write_list_entry "DEPENDS" "$_depends" "depends"
@@ -270,9 +286,48 @@ db_write_entry()
write_list_entry "PROVIDES" "$_provides" "depends"
write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
- cd "$startdir"
+ popd >/dev/null
+ popd >/dev/null
- return 0
+ # create files file if wanted
+ if (( WITHFILES )); then
+ msg2 "$(gettext "Creating '%s' db entry...")" 'files'
+ local files_path="$tmpdir/$pkgname-$pkgver/files"
+ echo "%FILES%" >$files_path
+ bsdtar --exclude='.*' -tf "$pkgfile" >>$files_path
+ fi
+
+ # create a delta file
+ if (( DELTA )); then
+ if [[ -n $oldfilename ]]; then
+ if [[ -f $oldfile ]]; then
+ delta=$(pkgdelta -q $oldfile $1)
+ if [[ -f $delta ]]; then
+ db_write_delta $delta
+ fi
+ else
+ warning "$(gettext "Old package file not found: %s")" "$oldfilename"
+ fi
+ fi
+ fi
+
+ # Extracts licenses to a common license dir
+ msg "Extracting license"
+ if bsdtar -xOf ${pkgfile} .PKGINFO | grep "license" | grep "custom" ; then
+ if [ -d ${LICENSESDIR}/${pkgname} ]; then
+ rm -r ${LICENSESDIR}/${pkgname}
+ fi
+
+ # Change dir to licenses, and extract them stripping the first part of the path
+ bsdtar -C ${LICENSESDIR}/ --include="usr/share/licenses/" \
+ --strip-components 3 -xf ${pkgfile} >/dev/null 2>&1
+
+ if [ $? -ne 0 ]; then
+ warning "This package doesn't contain a license dir"
+ fi
+ fi
+
+ return 0
} # end db_write_entry
# remove existing entries from the DB
@@ -281,9 +336,9 @@ db_remove_entry() {
local pkgname=$1
local notfound=1
local pkgentry=$(find_pkgentry $pkgname)
- while [ -n "$pkgentry" ]; do
+ while [[ -n $pkgentry ]]; do
notfound=0
- if [ -f "$pkgentry/deltas" ]; then
+ if [[ -f $pkgentry/deltas ]]; then
mv "$pkgentry/deltas" "$tmpdir/$pkgname.deltas"
fi
msg2 "$(gettext "Removing existing entry '%s'...")" \
@@ -291,6 +346,12 @@ db_remove_entry() {
rm -rf $pkgentry
pkgentry=$(find_pkgentry $pkgname)
done
+
+ msg "Removing license"
+ if [ -d ${LICENSESDIR}/${pkgname} ]; then
+ rm -r ${LICENSESDIR}/${pkgname}
+ fi
+
return $notfound
} # end db_remove_entry
@@ -301,16 +362,16 @@ check_repo_db()
CLEAN_LOCK=1
else
error "$(gettext "Failed to acquire lockfile: %s.")" "$LOCKFILE"
- [ -f "$LOCKFILE" ] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)"
+ [[ -f $LOCKFILE ]] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)"
exit 1
fi
- if [ -f "$REPO_DB_FILE" ]; then
+ if [[ -f $REPO_DB_FILE ]]; then
# there are two situations we can have here- a DB with some entries,
# or a DB with no contents at all.
if ! bsdtar -tqf "$REPO_DB_FILE" '*/desc' >/dev/null 2>&1; then
# check empty case
- if [ -n "$(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null)" ]; then
+ if [[ -n $(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null) ]]; then
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
exit 1
fi
@@ -337,15 +398,15 @@ check_repo_db()
add()
{
- if [ ! -f "$1" ]; then
+ if [[ ! -f $1 ]]; then
error "$(gettext "File '%s' not found.")" "$1"
return 1
fi
- if [ "${1##*.}" == "delta" ]; then
+ if [[ ${1##*.} == "delta" ]]; then
deltafile=$1
msg "$(gettext "Adding delta '%s'")" "$deltafile"
- if [ ! "$(type -p xdelta3)" ]; then
+ if ! type xdelta3 &>/dev/null; then
error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
exit 1
fi
@@ -357,7 +418,7 @@ add()
fi
pkgfile=$1
- if ! bsdtar -tqf "$pkgfile" .PKGINFO 2>&1 >/dev/null; then
+ if ! bsdtar -tqf "$pkgfile" .PKGINFO >/dev/null 2>&1; then
error "$(gettext "'%s' is not a package file, skipping")" "$pkgfile"
return 1
fi
@@ -369,7 +430,7 @@ add()
remove()
{
- if [ "${1##*.}" == "delta" ]; then
+ if [[ ${1##*.} == "delta" ]]; then
deltafile=$1
msg "$(gettext "Searching for delta '%s'...")" "$deltafile"
if db_remove_delta "$deltafile"; then
@@ -402,9 +463,8 @@ trap_exit()
clean_up() {
local exit_code=$?
- cd "$startdir"
- [ -d "$tmpdir" ] && rm -rf "$tmpdir"
- [ $CLEAN_LOCK -eq 1 -a -f "$LOCKFILE" ] && rm -f "$LOCKFILE"
+ [[ -d $tmpdir ]] && rm -rf "$tmpdir"
+ (( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE"
exit $exit_code
}
@@ -412,7 +472,7 @@ clean_up() {
# PROGRAM START
# determine whether we have gettext; make it a no-op if we do not
-if [ ! $(type -t gettext) ]; then
+if ! type gettext &>/dev/null; then
gettext() {
echo "$@"
}
@@ -423,15 +483,9 @@ case "$1" in
-V|--version) version; exit 0;;
esac
-# check for correct number of args
-if [ $# -lt 2 ]; then
- usage
- exit 1
-fi
-
# figure out what program we are
cmd="$(basename $0)"
-if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then
+if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then
error "$(gettext "Invalid command name '%s' specified.")" "$cmd"
exit 1
fi
@@ -450,14 +504,10 @@ success=0
for arg in "$@"; do
case "$arg" in
-q|--quiet) QUIET=1;;
-
- -f|--force)
- warning "$(gettext "the -f and --force options are no longer recognized")"
- msg2 "$(gettext "use options=(force) in the PKGBUILD instead")"
- ;;
-
+ -d|--delta) DELTA=1;;
+ -f|--files) WITHFILES=1;;
*)
- if [ -z "$REPO_DB_FILE" ]; then
+ if [[ -z $REPO_DB_FILE ]]; then
REPO_DB_FILE="$arg"
LOCKFILE="$REPO_DB_FILE.lck"
check_repo_db
@@ -472,7 +522,7 @@ for arg in "$@"; do
done
# if at least one operation was a success, re-zip database
-if [ $success -eq 1 ]; then
+if (( success )); then
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
case "$REPO_DB_FILE" in
@@ -485,20 +535,26 @@ if [ $success -eq 1 ]; then
filename=$(basename "$REPO_DB_FILE")
- cd "$tmpdir"
- if [ -n "$(ls)" ]; then
+ pushd "$tmpdir" >/dev/null
+ if [[ -n $(ls) ]]; then
bsdtar -c${TAR_OPT}f "$filename" *
else
# we have no packages remaining? zip up some emptyness
warning "$(gettext "No packages remain, creating empty database.")"
bsdtar -c${TAR_OPT}f "$filename" -T /dev/null
fi
- cd "$startdir"
-
- [ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
- [ -f "$tmpdir/$filename" ] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
+ popd >/dev/null
+
+ [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
+ dblink="${REPO_DB_FILE%.tar.*}"
+ target=${REPO_DB_FILE##*/}
+ ln -sf "$target" "$dblink" 2>/dev/null || \
+ ln -f "$target" "$dblink" 2>/dev/null || \
+ cp "$REPO_DB_FILE" "$dblink"
else
msg "$(gettext "No packages modified, nothing to do.")"
+ exit 1
fi
exit 0