summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Dasgupta <abhidg@gmail.com>2009-03-11 09:27:06 -0700
committerAaron Griffin <aaronmgriffin@gmail.com>2009-03-11 09:27:06 -0700
commit2c0ac7367b317e641ff0a0f228087ba3befc9eff (patch)
treea577ba00709d6c28a51888ecc1bf860264065a59
parent9b7b2a7e774f307b6b5ab398908e883364af7247 (diff)
Add convert-to-any script
Converts an arch-specific package to the "any" arch [Aaron: converted cd to pushd/popd] Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
-rw-r--r--convert-to-any108
1 files changed, 108 insertions, 0 deletions
diff --git a/convert-to-any b/convert-to-any
new file mode 100644
index 0000000..b8d298c
--- /dev/null
+++ b/convert-to-any
@@ -0,0 +1,108 @@
+#!/bin/bash
+# Converts an existing package into an
+# architecture-independent package and updates
+# the repositories accordingly.
+
+# -- Abhishek Dasgupta <abhidg@gmail.com>
+
+. "$(dirname $0)/db-functions"
+[ "$UID" = "" ] && UID=$(uid)
+
+if [ $# -ne 1 ]; then
+ echo "Syntax: $(basename $0) <reponame/pkgname>"
+ exit 1
+fi
+
+repo=$(echo $1 | sed "s#\(.*\)/.*#\1#g")
+pkg=$(echo $1 | sed "s#.*/\(.*\)#\1#g")
+
+if [ -f "$(dirname $0)/config" ]; then
+ . "$(dirname $0)/config"
+else
+ TMPDIR=/srv/tmp
+ FTP_BASE=/srv/ftp
+fi
+
+if [ -f /etc/makepkg.conf ]; then
+ . /etc/makepkg.conf
+else
+ echo "W: /etc/makepkg.conf does not exist."
+ DB_COMPRESSION=gz
+ PKGEXT=".pkg.tar.gz"
+fi
+
+repo_lock $repo any
+WORKDIR="$TMPDIR/convert-to-any.$pkg.$UID"
+ftppath="$FTP_BASE/$repo/os"
+
+cleanup() {
+ trap '' 0 2
+ # unlock
+ repo_unlock $repo any
+ rm -rf "$WORKDIR"
+ [ "$1" ] && exit $1
+}
+
+ctrl_c() {
+ echo "Interrupted" >&2
+ cleanup 0
+}
+
+die() {
+ echo "$*" >&2
+ cleanup 1
+}
+
+# Enter the temporary build directory
+# and convert the i686 package into an
+# architecture-independent package.
+mkdir -p "$WORKDIR/build"
+pushd "$WORKDIR/build" >/dev/null
+
+oldpkgname=$ftppath/i686/$pkg*
+if [ -f "$oldpkgname" ]; then
+ cp "$oldpkgname" .
+else
+ die "E: Package $oldpkgname not found in $ftppath/i686"
+fi
+
+for architecture in i686 x86_64; do
+ if [ -f "$ftppath/$architecture/$repo.db.tar.$DB_COMPRESSION" ]; then
+ cp $ftppath/$architecture/$repo.db.tar.$DB_COMPRESSION \
+ $repo-$architecture.db.tar.$DB_COMPRESSION
+ else
+ touch $repo-$architecture.db.tar.$DB_COMPRESSION
+ fi
+done
+
+if [ ! -d "$ftppath/any" ]; then mkdir -p "$ftppath/any"; fi
+
+# Conversion of i686 package into "any" package.
+echo -n "Extracting $pkg..."
+mkdir -p package
+tar zxf $pkg*i686$PKGEXT -C package
+echo " done."
+
+sed -i "s/arch = i686/arch = any/g" package/.PKGINFO
+newpkgname=$(ls $pkg*i686$PKGEXT | sed "s/i686/any/g")
+pushd package >/dev/null
+tar czf "$newpkgname" * .PKGINFO
+popd >/dev/null
+mv "package/$newpkgname" .
+echo "Created $newpkgname."
+
+# New package is ready, move it into place and update db.
+mv "$newpkgname" "$ftppath/any/"
+for architecture in i686 x86_64; do
+ # rm -f $ftppath/$architecture/$pkg*$PKGEXT
+ ln -s "$ftppath/any/$newpkgname" "$ftppath/$architecture/$newpkgname"
+ repo-remove -q $repo-$architecture.db.tar.$DB_COMPRESSION $pkg
+ repo-add -q $repo-$architecture.db.tar.$DB_COMPRESSION $newpkgname
+ mv $repo-$architecture.db.tar.$DB_COMPRESSION "$ftppath/os/$architecture"
+ echo "Updated $repo-$architecture for $pkg."
+done
+
+echo -n "Cleaning up..."
+popd >/dev/null
+cleanup
+echo " done."