2006-11-20 04:10:23 -05:00
|
|
|
#!/bin/bash
|
2007-01-30 19:38:13 -05:00
|
|
|
#
|
2007-05-30 11:04:49 -04:00
|
|
|
# repo-add - add a package to a given repo database file
|
|
|
|
# @configure_input@
|
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# Copyright (c) 2006 Aaron Griffin <aaron@archlinux.org>
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2007-05-30 11:04:49 -04:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2007-05-30 11:04:49 -04:00
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
2006-11-20 04:10:23 -05:00
|
|
|
# USA.
|
|
|
|
|
2007-06-04 01:21:14 -04:00
|
|
|
# gettext initialization
|
|
|
|
export TEXTDOMAIN='pacman'
|
|
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
|
2007-04-11 17:02:56 -04:00
|
|
|
myver='@PACKAGE_VERSION@'
|
2007-08-29 05:49:24 -04:00
|
|
|
confdir='@sysconfdir@'
|
2007-01-30 19:38:13 -05:00
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
FORCE=0
|
|
|
|
REPO_DB_FILE=""
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# print usage instructions
|
|
|
|
usage() {
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "repo-add (pacman) %s\n\n" "$myver"
|
|
|
|
printf "$(gettext "Usage: %s <path-to-db> [--force] <package> ...\n\n")" "$0"
|
|
|
|
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")"
|
|
|
|
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
|
2007-01-30 19:38:13 -05:00
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-04-11 17:02:56 -04:00
|
|
|
version() {
|
|
|
|
printf "repo-add (pacman) %s\n" "$myver"
|
2007-07-06 19:35:32 -04:00
|
|
|
printf "$(gettext "\
|
|
|
|
Copyright (C) 2006 Aaron Griffin <aaron@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")"
|
2007-04-11 17:02:56 -04:00
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# test if a file is a repository DB
|
2006-11-20 04:10:23 -05:00
|
|
|
test_repo_db_file () {
|
2006-12-20 20:53:40 -05:00
|
|
|
if [ -f "$REPO_DB_FILE" ]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
|
|
|
|
return 0 # YES
|
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
else
|
2007-08-29 05:49:24 -04:00
|
|
|
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
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-10-19 13:17:50 -04:00
|
|
|
# write a delta entry to the pacman database
|
|
|
|
# arg1 - path to delta
|
|
|
|
db_write_delta()
|
|
|
|
{
|
|
|
|
# blank out all variables and set deltafile
|
|
|
|
local deltafile=$(readlink -f "$1")
|
|
|
|
local filename=$(basename "$deltafile")
|
|
|
|
local deltavars pkgname fromver tover arch csize md5sum
|
|
|
|
|
|
|
|
# format of the delta filename:
|
|
|
|
# (package)-(fromver)_to_(tover)-(arch).delta
|
|
|
|
deltavars=( $(echo "$filename" | sed -e 's/\(.*\)-\(.*-.*\)_to_\(.*-.*\)-\(.*\).delta/\1 \2 \3 \4/') )
|
|
|
|
pkgname=${deltavars[0]}
|
|
|
|
fromver=${deltavars[1]}
|
|
|
|
tover=${deltavars[2]}
|
|
|
|
arch=${deltavars[3]}
|
|
|
|
|
|
|
|
# get md5sum and size of delta
|
|
|
|
md5sum="$(md5sum "$deltafile" | cut -d ' ' -f 1)"
|
|
|
|
csize=$(du -b -L "$deltafile" | cut -f 1)
|
|
|
|
|
|
|
|
# ensure variables were found
|
|
|
|
if [ -z "$pkgname" -o -z "$fromver" -o -z "$tover" -o -z "$arch" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add the entry for this delta file
|
|
|
|
echo -e "$fromver $tover $csize $filename $md5sum" >>deltas
|
|
|
|
} # end db_write_delta
|
|
|
|
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# write an entry to the pacman database
|
|
|
|
# arg1 - path to package
|
2006-11-20 04:10:23 -05:00
|
|
|
db_write_entry()
|
|
|
|
{
|
2007-01-30 19:38:13 -05:00
|
|
|
# blank out all variables and set pkgfile
|
2007-08-29 05:49:24 -04:00
|
|
|
local pkgfile=$(readlink -f "$1")
|
|
|
|
local pkgname pkgver pkgdesc url builddate packager csize size \
|
|
|
|
group depend backup license replaces provides conflict \
|
2007-10-19 13:17:50 -04:00
|
|
|
_groups _depends _backups _licenses _replaces _provides _conflicts \
|
|
|
|
startdir
|
2007-08-29 05:49:24 -04:00
|
|
|
|
|
|
|
local OLDIFS="$IFS"
|
2007-01-30 19:38:13 -05:00
|
|
|
# IFS (field seperator) is only the newline character
|
2007-02-22 20:29:14 -05:00
|
|
|
IFS="
|
|
|
|
"
|
2007-01-30 19:38:13 -05:00
|
|
|
|
|
|
|
# read info from the zipped package
|
2007-08-29 05:49:24 -04:00
|
|
|
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" ;;
|
2006-12-20 20:53:40 -05:00
|
|
|
replaces=*) _replaces="$_replaces $replaces" ;;
|
|
|
|
provides=*) _provides="$_provides $provides" ;;
|
2007-06-17 12:57:15 -04:00
|
|
|
conflict=*) _conflicts="$_conflicts $conflict" ;;
|
2006-12-20 20:53:40 -05:00
|
|
|
esac
|
|
|
|
done
|
2007-01-30 19:38:13 -05:00
|
|
|
|
2006-12-20 20:53:40 -05:00
|
|
|
IFS=$OLDIFS
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# get compressed size of package
|
2007-08-29 05:49:24 -04:00
|
|
|
csize=$(du -b -L "$pkgfile" | cut -f 1)
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-10-19 13:17:50 -04:00
|
|
|
startdir=$(pwd)
|
2007-08-29 05:49:24 -04:00
|
|
|
pushd "$gstmpdir" 2>&1 >/dev/null
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# ensure $pkgname and $pkgver variables were found
|
2006-12-20 20:53:40 -05:00
|
|
|
if [ -z "$pkgname" -o -z "$pkgver" ]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
|
|
|
|
popd 2>&1 >/dev/null
|
2006-12-20 20:53:40 -05:00
|
|
|
return 1
|
2007-05-30 11:04:49 -04:00
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# remove any other package in the DB with same name
|
2007-08-29 05:49:24 -04:00
|
|
|
local existing
|
2007-01-30 19:38:13 -05:00
|
|
|
for existing in *; do
|
|
|
|
if [ "${existing%-*-*}" = "$pkgname" ]; then
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
|
|
|
|
rm -rf "$existing"
|
2007-01-30 19:38:13 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# create package directory
|
|
|
|
mkdir "$pkgname-$pkgver"
|
|
|
|
cd "$pkgname-$pkgver"
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create desc entry
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Creating 'desc' db entry...")"
|
|
|
|
echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
echo -e "%NAME%\n$pkgname\n" >>desc
|
|
|
|
echo -e "%VERSION%\n$pkgver\n" >>desc
|
2007-08-29 05:49:24 -04:00
|
|
|
[ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc
|
|
|
|
write_list_entry "GROUPS" "$_groups" "desc"
|
2006-12-20 20:53:40 -05:00
|
|
|
[ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc
|
|
|
|
[ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# compute checksums
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Computing md5 checksums...")"
|
|
|
|
echo -e "%MD5SUM%\n$(md5sum "$pkgfile" | cut -d ' ' -f 1)\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
|
|
|
|
[ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
|
2007-08-29 05:49:24 -04:00
|
|
|
write_list_entry "LICENSE" "$_licenses" "desc"
|
2006-12-20 20:53:40 -05:00
|
|
|
[ -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
|
2007-08-29 05:49:24 -04:00
|
|
|
write_list_entry "REPLACES" "$_replaces" "desc"
|
|
|
|
[ $FORCE -eq 1 ] && echo -e "%FORCE%\n" >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create depends entry
|
2007-08-29 05:49:24 -04:00
|
|
|
msg2 "$(gettext "Creating 'depends' db entry...")"
|
|
|
|
write_list_entry "DEPENDS" "$_depends" "depends"
|
|
|
|
write_list_entry "CONFLICTS" "$_conflicts" "depends"
|
|
|
|
write_list_entry "PROVIDES" "$_provides" "depends"
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-10-19 13:17:50 -04:00
|
|
|
# create deltas entry if there are delta files
|
|
|
|
for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do
|
|
|
|
if [ -f "$delta" ]; then
|
|
|
|
# create deltas file if it does not already exist
|
|
|
|
if [ ! -f "deltas" ]; then
|
|
|
|
msg2 "$(gettext "Creating 'deltas' db entry...")"
|
|
|
|
echo -e "%DELTAS%" >>deltas
|
|
|
|
fi
|
|
|
|
|
|
|
|
# write this delta entry
|
|
|
|
if db_write_delta "$delta"; then
|
|
|
|
msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")"
|
|
|
|
else
|
|
|
|
msg2 "$(gettext "Could not add delta '%s'")" "$(basename "$delta")"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# add the final newline
|
|
|
|
[ -f "deltas" ] && echo -e "" >>deltas
|
|
|
|
|
2006-12-20 20:53:40 -05:00
|
|
|
# preserve the modification time
|
|
|
|
touch -r "$pkgfile" desc depends
|
2007-10-19 13:17:50 -04:00
|
|
|
[ -f "deltas" ] && touch -r "$pkgfile" deltas
|
2007-08-29 05:49:24 -04:00
|
|
|
|
|
|
|
popd 2>&1 >/dev/null
|
2007-01-30 19:38:13 -05:00
|
|
|
} # end db_write_entry
|
|
|
|
|
|
|
|
# PROGRAM START
|
|
|
|
|
|
|
|
# check for help flags
|
|
|
|
if [ "$1" = "-h" -o "$1" = "--help" ]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2007-04-11 17:02:56 -04:00
|
|
|
# check for version flags
|
|
|
|
if [ "$1" = "-V" -o "$1" = "--version" ]; then
|
|
|
|
version
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# check for correct number of args
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-04-01 19:55:01 -04:00
|
|
|
# source system and user makepkg.conf
|
2007-08-29 05:49:24 -04:00
|
|
|
if [ -r "$confdir/makepkg.conf" ]; then
|
|
|
|
source "$confdir/makepkg.conf"
|
2007-04-01 19:55:01 -04:00
|
|
|
else
|
2007-08-29 05:49:24 -04:00
|
|
|
error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
|
2007-06-04 01:21:14 -04:00
|
|
|
exit 1 # $E_CONFIG_ERROR
|
2007-04-01 19:55:01 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -r ~/.makepkg.conf ]; then
|
|
|
|
source ~/.makepkg.conf
|
|
|
|
fi
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# main routine
|
2007-08-29 05:49:24 -04:00
|
|
|
gstmpdir=$(mktemp -d /tmp/repo-add.XXXXXXXXXX) || (\
|
|
|
|
error "$(gettext "Cannot create temp directory for database building.")"; \
|
2006-12-20 20:53:40 -05:00
|
|
|
exit 1)
|
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
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"
|
2006-12-20 20:53:40 -05:00
|
|
|
else
|
2007-08-29 05:49:24 -04:00
|
|
|
msg "$(gettext "Adding package '%s'")" "$arg"
|
|
|
|
|
|
|
|
if db_write_entry "$arg"; then
|
|
|
|
success=1
|
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
else
|
|
|
|
error "$(gettext "Package '%s' not found.")" "$arg"
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
fi
|
|
|
|
done
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-08-29 05:49:24 -04:00
|
|
|
# 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" *
|
2006-12-20 20:53:40 -05:00
|
|
|
fi
|
2007-08-29 05:49:24 -04:00
|
|
|
|
|
|
|
popd 2>&1 >/dev/null
|
|
|
|
else
|
|
|
|
msg "$(gettext "No packages modified, nothing to do.")"
|
2006-11-20 04:10:23 -05:00
|
|
|
fi
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# remove the temp directory used to unzip
|
2007-08-29 05:49:24 -04:00
|
|
|
[ -d "$gstmpdir" ] && rm -rf "$gstmpdir"
|
2006-12-20 20:53:40 -05:00
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 noet:
|