aboutsummaryrefslogtreecommitdiff
path: root/jail-upgrade
diff options
context:
space:
mode:
Diffstat (limited to 'jail-upgrade')
-rwxr-xr-xjail-upgrade107
1 files changed, 107 insertions, 0 deletions
diff --git a/jail-upgrade b/jail-upgrade
new file mode 100755
index 0000000..b9567fd
--- /dev/null
+++ b/jail-upgrade
@@ -0,0 +1,107 @@
+#!/bin/bash
+#
+# jail-upgrade v0.5: upgrade packages in jails
+# feedback: rhatto@riseup.net | GPL
+#
+# Jail-upgrade 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 any later version.
+#
+# Jail-upgrade 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
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+
+function swaret_jail_upgrade {
+
+ if [ ! -d "$PATCHES_DIR" ]; then
+ cd $PATCHES_DIR
+ for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do
+ if [[ $pack == `package_name $installed.tgz` ]]; then
+ if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
+ ROOT=$1 upgradepkg $file
+ fi
+ fi
+ done
+ fi
+}
+
+function simplaret_jail_upgrade {
+
+ echo upgrading jail $1...
+
+ VERSION="`cat $1/etc/slackware-version | awk '{ print $2 }' | sed -e 's/.0$//'`"
+ ARCH="`cat $1/etc/slackware-version | awk '{ print $3 }' | sed -e 's/(//' -e 's/)//'`"
+
+ if [ -z "$ARCH" ]; then
+ ARCH="i386"
+ fi
+
+ if [ -d "$PATCHES_DIR/$ARCH/$VERSION" ]; then
+ cd $PATCHES_DIR/$ARCH/$VERSION
+ for file in `ls *tgz`; do
+ pack=`package_name $file`
+ for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do
+ if [[ "$pack" == "`package_name $installed.tgz`" ]]; then
+ if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
+ ROOT=$1 upgradepkg $file
+ fi
+ fi
+ done
+ done
+ else
+ echo error: cant upgrade for arch $ARCH and version $VERSION on $1: no such patch dir $PATCHES_DIR/$ARCH/$VERSION
+ fi
+
+}
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+ eval_config `basename $0`
+else
+ echo "error: file $COMMON not found, check your `basename $0` installation"
+ exit 1
+fi
+
+if [ ! -z "$PATCHES" ]; then
+ if [ -d "$PATCHES" ]; then
+ PATCHES_DIR="$PATCHES"
+ else
+ echo "error: folder $PATCHES does not exist"
+ fi
+fi
+
+if [ "$SIMPLARET" == "simplaret" ]; then
+ upgrade_method="simplaret_jail_upgrade"
+elif [ "$SIMPLARET" == "swaret" ]; then
+ upgrade_method="swaret_jail_upgrade"
+else
+ echo invalid value $SIMPLARET for SIMPLARET, please check your $CONF
+ exit 1
+fi
+
+if [ -z "$1" ]; then
+ if [ -d "/var/log/packages" ]; then
+ $upgrade_method /
+ fi
+ for vserver in `ls $JAIL_ROOT`; do
+ if [ -d "$JAIL_ROOT/$vserver/var/log/packages" ]; then
+ $upgrade_method $JAIL_ROOT/$vserver
+ fi
+ done
+elif [ -d "$JAIL_ROOT/$1" ]; then
+ if [ -d "$JAIL_ROOT/$1/var/log/packages" ]; then
+ $upgrade_method $JAIL_ROOT/$1
+ else
+ echo error: jail $JAIL_ROOT/$1 dont looks like a slackware system
+ fi
+else
+ echo "error: jail $0 does not exist"
+ exit 1
+fi