aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2006-09-19 16:56:25 +0000
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2006-09-19 16:56:25 +0000
commit397f31fcb0b47000c6e5c5c4aaf441970ce06e3a (patch)
tree0df0e0bbc0ef9d4f2a388d4bd634e8683e9a36af /lib
parenta5ad04283516a7ff72cfd33f3221cfd3c10c3b5b (diff)
downloadsimplepkg-397f31fcb0b47000c6e5c5c4aaf441970ce06e3a.tar.gz
simplepkg-397f31fcb0b47000c6e5c5c4aaf441970ce06e3a.tar.bz2
simplepkg 0.4.9pre2
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@5 04377dda-e619-0410-9926-eae83683ac58
Diffstat (limited to 'lib')
-rw-r--r--lib/common.sh180
1 files changed, 180 insertions, 0 deletions
diff --git a/lib/common.sh b/lib/common.sh
new file mode 100644
index 0000000..af31da3
--- /dev/null
+++ b/lib/common.sh
@@ -0,0 +1,180 @@
+#!/bin/bash
+#
+# common.sh: common functions for simplepkg
+# feedback: rhatto at riseup.net | gpl
+#
+# Uses some functions from pkgtools, which license is:
+#
+# Copyright 1999 Patrick Volkerding, Moorhead, Minnesota, USA
+# Copyright 2001, 2002, 2003 Slackware Linux, Inc., Concord, California, USA
+# All rights reserved.
+#
+# Redistribution and use of this script, with or without modification, is
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of this script must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+BASE_CONF="/etc/simplepkg"
+CONF="$BASE_CONF/simplepkg.conf"
+JAIL_LIST="$BASE_CONF/jailist"
+
+# pkgtool stuff
+function package_name {
+ STRING=`basename $1 .tgz`
+ # Check for old style package name with one segment:
+ if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then
+ echo $STRING
+ else # has more than one dash delimited segment
+ # Count number of segments:
+ INDEX=1
+ while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do
+ INDEX=`expr $INDEX + 1`
+ done
+ INDEX=`expr $INDEX - 1` # don't include the null value
+ # If we don't have four segments, return the old-style (or out of spec) package name:
+ if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then
+ echo $STRING
+ else # we have four or more segments, so we'll consider this a new-style name:
+ NAME=`expr $INDEX - 3`
+ NAME="`echo $STRING | cut -f 1-$NAME -d -`"
+ echo $NAME
+ fi
+ fi
+}
+
+function install_packages {
+
+ if [[ "$SIMPLARET_CLEAN" == "1" ]]; then
+ ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge
+ elif [[ ! -z "$SIMPLARET_PURGE_WEEKS" ]] && [[ "$SIMPLARET_PURGE_WEEKS" != "0" ]]; then
+ ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge -w $SIMPLARET_PURGE_WEEKS
+ fi
+
+ for pack in `cat $TEMPLATE | grep -v -e "^#" | cut -d : -f 1`; do
+ package_downloaded="0"
+ if [ "$SIMPLARET" == "simplaret" ]; then
+ extrafolder="$ARCH/$VERSION/"
+ else
+ unset extrafolder
+ fi
+ for file in `find $STORAGE/$extrafolder -name $pack*tgz`; do
+ if [[ "`package_name $file`" == "$pack" ]]; then
+ package_downloaded="1"
+ package_file="$file"
+ break
+ fi
+ done
+ if [[ "$package_downloaded" != "1" ]]; then
+ ARCH=$ARCH VERSION=$VERSION $SIMPLARET --get $pack -a
+ for file in `find $STORAGE/$extrafolder -name $pack*tgz`; do
+ if [[ "`package_name $file`" == "$pack" ]]; then
+ package_file="$file"
+ break
+ fi
+ done
+ fi
+ if [ -z "$package_file" ]; then
+ echo error: could not install package $pack
+ else
+ installed_packs="`ls /$JAIL_ROOT/$server/var/log/packages/$pack* 2> /dev/null`"
+ if [ ! -z "$installed_packs" ]; then
+ for installed in $installed_packs; do
+ if [[ "$pack" == "`package_name $installed.tgz`" ]]; then
+ echo "package $pack already installed in $JAIL_ROOT/$server ($installed)"
+ package_installed="1"
+ break
+ fi
+ if [[ "$package_installed" != "1" ]]; then
+ installpkg -root /$JAIL_ROOT/$server $package_file
+ unset package_installed
+ if [ ! -z "$SIMPLARET_DELETE_DURING" ] && [ "$SIMPLARET_DELETE_DURING" != "0" ]; then
+ SILENT=1 ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge
+ fi
+ break
+ fi
+ done
+ else
+ installpkg -root /$JAIL_ROOT/$server $package_file
+ if [ ! -z "$SIMPLARET_DELETE_DURING" ] && [ "$SIMPLARET_DELETE_DURING" != "0" ]; then
+ SILENT=1 ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge
+ fi
+ fi
+ fi
+ unset package_file
+ done
+ if [[ "$SIMPLARET_DELETE_DOWN" == "1" ]]; then
+ ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge
+ fi
+}
+
+function remove_packages {
+ for pack in `cat $TEMPLATE | grep -v -e "^#" | cut -d : -f 1`; do
+ ROOT=/$JAIL_ROOT/$server removepkg $pack
+ done
+}
+
+function eval_config {
+ if [ -f "$CONF" ]; then
+ source $CONF
+ else
+ echo $1 error: config file $CONFIG not found
+ exit 1
+ fi
+
+ if [ -z "$SIMPLARET" ]; then
+ SIMPLARET="simplaret"
+ fi
+
+ if [ -z "$STORAGE" ]; then
+ if [ -d "/var/$SIMPLARET" ]; then
+ STORAGE="/var/$SIMPLARET"
+ else
+ echo error: please adjust value for STORAGE at $CONF
+ exit 1
+ fi
+ fi
+
+ if [ ! -z "$ROOT" ]; then
+ JAIL_ROOT="$ROOT"
+ elif [ -z "$JAIL_ROOT" ]; then
+ echo error: please adjust value for JAIL_ROOT at $CONF
+ exit 1
+ fi
+
+ if [ -z "$ARCH" ]; then
+ ARCH="$DEFAULT_ARCH"
+ fi
+
+ if [ -z "$VERSION" ]; then
+ VERSION="$DEFAULT_VERSION"
+ fi
+
+ if which $SIMPLARET &> /dev/null; then
+ if [[ "$SIMPLARET_UPDATE" == "1" ]]; then
+ if [[ "$2" == "-u" ]]; then
+ echo "updating package database..."
+ ARCH=$ARCH VERSION=$VERSION $SIMPLARET --update
+ fi
+ fi
+ else
+ echo "$SIMPLARET not found, please install it before run $0"
+ fi
+
+ if [ -z "PATCHES_DIR" ]; then
+ echo error: please adjust a value for PATCHES_DIR at $CONF
+ fi
+}
+