2006-11-20 04:10:23 -05:00
|
|
|
#!/bin/bash
|
2007-01-30 19:38:13 -05:00
|
|
|
#
|
2006-11-20 04:10:23 -05:00
|
|
|
# repo-add : add a package to a given repo database file
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Aaron Griffin <aaron@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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
# USA.
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
myver='3.0.0'
|
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
FORCE=0
|
|
|
|
REPO_DB_FILE=""
|
|
|
|
|
|
|
|
DB_COMPRESSION="gz" #TODO this is gross
|
|
|
|
DB_CHECKSUMS=(md5)
|
|
|
|
TMP_DIR=""
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# print usage instructions
|
|
|
|
usage() {
|
|
|
|
echo "repo-add $myver"
|
|
|
|
echo
|
|
|
|
echo "usage: repo-add <path-to-db> [--force] <package> ..."
|
|
|
|
echo
|
|
|
|
echo "repo-add will update a package database by reading a package file."
|
|
|
|
echo "Multiple packages to add can be specified on the command line."
|
|
|
|
echo
|
|
|
|
echo "The --force flag will add a 'force' entry to the sync database, which"
|
|
|
|
echo "tells pacman to skip its internal version number checking and update"
|
|
|
|
echo "the package regardless."
|
|
|
|
echo
|
|
|
|
echo "Example:"
|
|
|
|
echo " repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz"
|
|
|
|
echo
|
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# return calculated checksum of package
|
|
|
|
# arg1 - checksum type
|
|
|
|
# arg2 - path to package
|
2006-11-20 04:10:23 -05:00
|
|
|
get_checksum () {
|
2006-12-20 20:53:40 -05:00
|
|
|
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
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# return PKGINFO string for checksum type
|
|
|
|
# arg1 - checksum type
|
2006-11-20 04:10:23 -05:00
|
|
|
checksum_name () {
|
2006-12-20 20:53:40 -05:00
|
|
|
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
|
2006-11-20 04:10:23 -05: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
|
|
|
|
[ "$(tar tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1
|
|
|
|
else
|
|
|
|
true
|
|
|
|
fi
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
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
|
2006-12-20 20:53:40 -05:00
|
|
|
pkgfile=$(readlink -f $1)
|
|
|
|
export pkgname=""
|
|
|
|
pkgver=""
|
|
|
|
pkgdesc=""
|
|
|
|
url=""
|
|
|
|
builddate=""
|
|
|
|
packager=""
|
|
|
|
csize=""
|
|
|
|
size=""
|
2007-02-22 20:29:14 -05:00
|
|
|
_groups=""
|
|
|
|
_depends=""
|
|
|
|
_backups=""
|
|
|
|
_licenses=""
|
2006-12-20 20:53:40 -05:00
|
|
|
_replaces=""
|
|
|
|
_provides=""
|
|
|
|
_conflicts=""
|
|
|
|
|
|
|
|
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
|
2006-12-20 20:53:40 -05:00
|
|
|
for i in $(tar xOf "$pkgfile" .PKGINFO | grep -v "^#" |sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
|
|
|
|
eval "${i}"
|
|
|
|
case "$i" in
|
2007-02-22 20:29:14 -05:00
|
|
|
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" ;;
|
|
|
|
conflicts=*) _conflicts="$_conflicts $conflicts" ;;
|
|
|
|
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
|
2006-12-20 20:53:40 -05:00
|
|
|
csize="$(du -b $pkgfile | cut -f1)"
|
|
|
|
|
|
|
|
cd $gstmpdir
|
|
|
|
|
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
|
|
|
|
echo " error: invalid package file"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# remove any other package in the DB with same name
|
|
|
|
for existing in *; do
|
|
|
|
if [ "${existing%-*-*}" = "$pkgname" ]; then
|
|
|
|
echo ":: removing existing package '$existing'"
|
|
|
|
rm -rf $existing
|
|
|
|
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
|
2006-12-20 20:53:40 -05:00
|
|
|
echo ":: creating 'desc' db entry"
|
2007-03-13 11:01:15 -04:00
|
|
|
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
|
|
|
|
if [ -n "$pkgdesc" ]; then
|
|
|
|
echo -e "%DESC%\n$pkgdesc\n" >>desc
|
|
|
|
fi
|
2007-02-22 20:29:14 -05:00
|
|
|
if [ -n "$_groups" ]; then
|
2006-12-20 20:53:40 -05:00
|
|
|
echo "%GROUPS%" >>desc
|
2007-02-22 20:29:14 -05:00
|
|
|
echo $_groups | tr -s ' ' '\n' >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
echo "" >desc
|
|
|
|
fi
|
|
|
|
[ -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
|
2006-12-20 20:53:40 -05:00
|
|
|
for chk in ${DB_CHECKSUMS[@]}; do
|
|
|
|
name="$(checksum_name $chk)"
|
|
|
|
echo ":: computing $name checksums"
|
|
|
|
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
|
2007-02-22 20:29:14 -05:00
|
|
|
if [ -n "$_licenses" ]; then
|
2006-12-20 20:53:40 -05:00
|
|
|
echo "%LICENSE%" >>desc
|
2007-02-22 20:29:14 -05:00
|
|
|
echo $_licenses | tr -s ' ' '\n' >>desc
|
2006-12-20 20:53:40 -05:00
|
|
|
echo "" >>desc
|
|
|
|
fi
|
|
|
|
[ -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
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# create depends entry
|
2006-12-20 20:53:40 -05:00
|
|
|
echo ":: creating 'depends' db entry"
|
2007-02-22 20:29:14 -05:00
|
|
|
if [ -n "$_depends" ]; then
|
2006-12-20 20:53:40 -05:00
|
|
|
echo "%DEPENDS%" >>depends
|
2007-02-22 20:29:14 -05:00
|
|
|
echo $_depends | tr -s ' ' '\n' >>depends
|
2006-12-20 20:53:40 -05:00
|
|
|
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
|
|
|
|
touch -r "$pkgfile" desc depends
|
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
|
|
|
|
|
|
|
|
# check for correct number of args
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-12-20 20:53:40 -05:00
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# main routine
|
2006-11-20 04:10:23 -05:00
|
|
|
if [ $# -gt 1 ]; then
|
2006-12-20 20:53:40 -05:00
|
|
|
gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\
|
|
|
|
echo "cannot create temp directory for database building"; \
|
|
|
|
exit 1)
|
|
|
|
|
|
|
|
success=0
|
2007-01-30 19:38:13 -05:00
|
|
|
# parse arguements
|
2006-12-20 20:53:40 -05:00
|
|
|
for arg in $@; do
|
|
|
|
if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
|
|
|
|
FORCE=1
|
2007-01-30 19:38:13 -05:00
|
|
|
elif [ -z "$REPO_DB_FILE" ]; then
|
2006-12-20 20:53:40 -05:00
|
|
|
REPO_DB_FILE="$(readlink -f $arg)"
|
|
|
|
if ! test_repo_db_file; then
|
2007-01-30 19:38:13 -05:00
|
|
|
echo "error: repository file '$REPO_DB_FILE' is not a proper pacman db"
|
2006-12-20 20:53:40 -05:00
|
|
|
exit 1
|
|
|
|
elif [ -f "$REPO_DB_FILE" ]; then
|
|
|
|
echo ":: extracting database to a temporary location"
|
|
|
|
tar xf "$REPO_DB_FILE" -C "$gstmpdir"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ -f "$arg" ]; then
|
2007-03-29 22:30:40 -04:00
|
|
|
if ! tar tf "$arg" .PKGINFO 2>&1 >/dev/null; then
|
2006-12-20 20:53:40 -05:00
|
|
|
echo "error: '$arg' is not a package file, skipping"
|
|
|
|
else
|
|
|
|
echo ":: adding package '$arg'"
|
|
|
|
|
|
|
|
this_dir="$(pwd)"
|
|
|
|
if db_write_entry "$arg"; then
|
|
|
|
success=1
|
|
|
|
fi
|
|
|
|
cd $this_dir
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "error: package '$arg' not found"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# if all operations were a success, rezip database
|
2006-12-20 20:53:40 -05:00
|
|
|
if [ "$success" = "1" ]; then
|
|
|
|
echo ":: creating updated database file ${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 "warning: no compression set"
|
|
|
|
tar c * >$REPO_DB_FILE;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo ":: no packages modified, nothing to do"
|
|
|
|
fi
|
2006-11-20 04:10:23 -05:00
|
|
|
fi
|
|
|
|
|
2007-01-30 19:38:13 -05:00
|
|
|
# remove the temp directory used to unzip
|
2006-11-20 04:10:23 -05:00
|
|
|
[ -d "$gstmpdir" ] && rm -rf $gstmpdir
|
2006-12-20 20:53:40 -05:00
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 noet:
|