aboutsummaryrefslogtreecommitdiff
path: root/src/templatepkg
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 /src/templatepkg
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 'src/templatepkg')
-rwxr-xr-xsrc/templatepkg90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/templatepkg b/src/templatepkg
new file mode 100755
index 0000000..9c1f8bc
--- /dev/null
+++ b/src/templatepkg
@@ -0,0 +1,90 @@
+#!/bin/bash
+#
+# templatepkg v0.2: create a simplepkg package list from
+# a legacy slackware /var/log/packages
+#
+# feedback: rhatto at riseup.net | gpl
+#
+# Templatepkg 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.
+#
+# Templatepkg 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"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+ eval_config `basename $0`
+else
+ echo "error: file $COMMON found, check your `basename $0` installation"
+ exit 1
+fi
+
+APPEND="0"
+if [[ ! -z "$3" && "$1" == "-a" ]]; then
+ ROOT="$3"
+ TEMPLATE="$BASE_CONF/$2.template"
+ APPEND="1"
+elif [[ ! -z "$2" && "$1" == "-a" ]]; then
+ ROOT="/"
+ TEMPLATE="$BASE_CONF/$2.template"
+ APPEND="1"
+elif [[ ! -z "$2" ]]; then
+ ROOT="$2"
+ TEMPLATE="$BASE_CONF/$1.template"
+elif [[ ! -z "$1" ]]; then
+ TEMPLATE="$BASE_CONF/$1.template"
+ ROOT="/"
+else
+ echo "usage: `basename $0` [-a] <template> [root-dir]"
+ echo -e "\t-a: append packages into <$BASE_CONF/template.template>"
+ exit 1
+fi
+
+if [ ! -d "$ROOT/var/log/packages" ]; then
+ echo $ROOT/var/log/packages: directory not found
+ exit 1
+elif [[ -f "$TEMPLATE" && "$APPEND" == "0" ]]; then
+ rm -f $TEMPLATE
+fi
+
+for package in `ls -1 $ROOT/var/log/packages/`; do
+ pack=`package_name $package`
+ if [ -f $TEMPLATE ]; then
+ if ! `grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | grep -q -e "^$pack\$"`; then
+ package_name $package >> $TEMPLATE
+ fi
+ else
+ package_name $package >> $TEMPLATE
+ fi
+done
+
+# checks if each package from the template is installed
+grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | while read pack; do
+
+ if [ ! -z "$pack" ]; then
+ unset found
+ for candidate in `ls $ROOT/var/log/packages/$pack* 2> /dev/null`; do
+ candidate="`package_name $candidate`"
+ if [ "$pack" == "$candidate" ]; then
+ found="1"
+ break
+ fi
+ done
+ if [ "$found" != "1" ]; then
+ # removes a non-installed package from the template
+ sed "/^$pack$/d" $TEMPLATE | sed "/^$pack $/d" | sed "/^$pack:*/d" > $TEMPLATE.tmp
+ cat $TEMPLATE.tmp > $TEMPLATE
+ rm -f $TEMPLATE.tmp
+ fi
+ fi
+
+done