summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/gensync203
1 files changed, 52 insertions, 151 deletions
diff --git a/scripts/gensync b/scripts/gensync
index daac7e84..07c102d0 100755
--- a/scripts/gensync
+++ b/scripts/gensync
@@ -20,7 +20,7 @@
# USA.
#
-myver='2.9.8'
+myver='3.0.0'
usage() {
echo "gensync $myver"
@@ -45,143 +45,29 @@ usage() {
exit 0
}
+BUILDSCRIPT="PKGBUILD"
+PKGEXT="pkg.tar.gz"
+
source /etc/makepkg.conf
-die() {
- echo "gensync: $*" >&2
- rm -rf $gstmpdir
+error () {
+ echo "==> ERROR: $*" >&2
+}
+
+die () {
+ error $*
exit 1
}
-check_option() {
+check_force () {
local i
for i in ${options[@]}; do
- local uc=`echo $i | tr [:lower:] [:upper:]`
- local lc=`echo $i | tr [:upper:] [:lower:]`
- if [ "$uc" = "$1" -o "$lc" = "$1" ]; then
- echo $1
- return
+ local lc=$(echo $i | tr [:upper:] [:lower:])
+ if [ "$lc" = "force" ]; then
+ true
fi
done
-}
-
-get_md5checksum()
-{
- if [ -f $pkgfile ]; then
- md5line=`md5sum $pkgfile`
- [ ! -z "$md5line" ] && pkgmd5sum=${md5line% *}
- echo $pkgmd5sum
- fi
- return 0
-}
-
-get_sha1checksum()
-{
- if [ -f $pkgfile ]; then
- sha1line=`sha1sum $pkgfile`
- [ ! -z "$sha1line" ] && pkgsha1sum=${sha1line% *}
- echo $pkgsha1sum
- fi
- return 0
-}
-
-db_write_entry()
-{
- if [ "$pkgdir" != "" ]; then
- pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT"
- else
- pkgfile="$destdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT"
- fi
- if [ ! -f $pkgfile ]; then
- die "Package '$pkgfile' not found"
- fi
-
- csize=$(du -b $pkgfile | cut -f1)
- usize=$(LANG= LC_ALL= pacman -Qi -p $pkgfile 2>/dev/null|grep ^Size|sed 's/.*: \(.*\)/\1/')
-
- pkgmd5sum=`get_md5checksum $pkgfile`
- [ -z $pkgmd5sum ] && die "error generating checksum for $pkgfile"
-
- unset pkgname pkgver pkgrel pkgdesc force
- unset groups replaces provides depends conflicts options
- source $1 || return 1
- cd $gstmpdir
- mkdir $pkgname-$pkgver-$pkgrel || return 1
- cd $pkgname-$pkgver-$pkgrel
- # desc
- : >desc
- echo "%NAME%" >>desc
- echo "$pkgname" >>desc
- echo "" >>desc
- echo "%VERSION%" >>desc
- echo "$pkgver-$pkgrel" >>desc
- echo "" >>desc
- if [ -n "$pkgdesc" ]; then
- echo "%DESC%" >>desc
- echo "$pkgdesc" >>desc
- echo "" >>desc
- fi
- if [ ${#groups[*]} -gt 0 ]; then
- echo "%GROUPS%" >>desc
- for it in "${groups[@]}"; do
- echo "$it" >>desc
- done
- echo "" >>desc
- fi
- echo "%ARCH%" >>desc
- echo "$arch" >>desc
- echo "" >>desc
- if [ -n $csize ]; then
- echo "%CSIZE%" >>desc
- echo "$csize" >>desc
- echo "" >>desc
- fi
- if [ -n $usize ]; then
- echo "%USIZE%" >>desc
- echo "$usize" >>desc
- echo "" >>desc
- fi
- if [ ! -z $pkgmd5sum ]; then
- echo "%MD5SUM%" >>desc
- echo "$pkgmd5sum" >>desc
- echo "" >>desc
- fi
- if [ ${#replaces[*]} -gt 0 ]; then
- echo "%REPLACES%" >>desc
- for it in "${replaces[@]}"; do
- echo "$it" >>desc
- done
- echo "" >>desc
- fi
- if [ "$force" = "y" -o "$force" = "Y" -o "`check_option FORCE`" ]; then
- echo "%FORCE%" >>desc
- echo "" >>desc
- fi
- # depends
- : >depends
- if [ ${#depends[*]} -gt 0 ]; then
- echo "%DEPENDS%" >>depends
- for it in "${depends[@]}"; do
- echo "$it" >>depends
- done
- echo "" >>depends
- fi
- if [ ${#conflicts[*]} -gt 0 ]; then
- echo "%CONFLICTS%" >>depends
- for it in "${conflicts[@]}"; do
- echo "$it" >>depends
- done
- echo "" >>depends
- fi
- if [ ${#provides[*]} -gt 0 ]; then
- echo "%PROVIDES%" >>depends
- for it in "${provides[@]}"; do
- echo "$it" >>depends
- done
- echo "" >>depends
- fi
- # preserve the modification time
- touch -r $1 desc depends
+ false
}
if [ $# -lt 2 ]; then
@@ -194,34 +80,49 @@ if [ "$1" = "-h" -o "$1" = "--help" ]; then
exit 0
fi
-d=`dirname $1`
-rootdir=`cd $d && pwd`/`basename $1`
-d=`dirname $2`
-destdir=`cd $d && pwd`
-destfile="$destdir/`basename $2`"
-pkgdir=
+d=$(dirname $1)
+rootdir="$(cd $d && pwd)/$(basename $1)"
+d="$(dirname $2)"
+destdir="$(cd $d && pwd)"
+destfile="$destdir/$(basename $2)"
+pkgdir=""
if [ "$3" != "" ]; then
- pkgdir=$3
+ pkgdir="$3"
fi
-gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || exit 1
-[ ! -d $rootdir ] && die "invalid root dir: $rootdir"
+[ ! -d "$rootdir" ] && die "invalid root dir: $rootdir"
+
echo "gensync: building database entries, generating md5sums..." >&2
-cd `dirname $2`
-for file in `find $rootdir/* -name PKGBUILD`; do
- source $file || die "errors parsing $file"
- db_write_entry $file || die "error writing entry for $file"
-else
- echo "gensync: missing package: $pkgfile" >&2
-fi
+cd "$destdir"
+
+pkgs=""
+forcepkgs=""
+
+for file in $(find "$rootdir"/* -name "$BUILDSCRIPT"); do
+ unset pkgname pkgver pkgrel options
+
+ source $file || die "failed to parse parse $file"
+ if [ "$pkgdir" != "" ]; then
+ pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT"
+ else
+ pkgfile="$destdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT"
+ fi
+
+ if [ ! -f "$pkgfile" ]; then
+ error "$BUILDSCRIPT does not have a corresponding package"
+ else
+ if check_force; then
+ forcepkgs="$forcepkgs $pkgfile"
+ else
+ pkgs="$pkgs $pkgfile"
+ fi
+ fi
done
-echo "gensync: compressing to $destfile..." >&2
-cd $gstmpdir
-tar c * | gzip -9 >$destfile
-[ $? -gt 0 ] && die "error writing to $destfile"
+echo "successfuly found all packages, creating repo DB..."
-rm -rf $gstmpdir
-exit 0
+# we'll trim the output just a tad, as gensync may be used on large repos
+repo-add $destfile $pkgs --force $force_pkgs \
+ | grep -e "package" -e "database"
# vim: set ts=2 sw=2 noet: