]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
templatepkg now splited between -a and -u options
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Fri, 9 Feb 2007 19:43:55 +0000 (19:43 +0000)
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Fri, 9 Feb 2007 19:43:55 +0000 (19:43 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@168 04377dda-e619-0410-9926-eae83683ac58

doc/CHANGELOG
src/jail-commit
src/templatepkg

index 8797935b9f367aba09e3c5b7d7fca4e741ed927c..cd9001a15cc5102720b530f9b72ec0e013bccf97 100644 (file)
@@ -1,7 +1,8 @@
 simplepkg changelog
 -------------------
 
-0.4.9pre24: simplaret:
+0.4.9pre24: subversion repository support for templates
+            simplaret:
             - new config variables:
               - STORE_ROOT_PATCHES_ON_PATCHES_DIR
               - SIGNATURE_CHECKING
@@ -13,6 +14,8 @@ simplepkg changelog
                - /etc/simplepkg/templates/template_name.template
                - /etc/simplepkg/templates/template_name/template_name.template
             jail-update: renamed to jail-commit
+            templatepkg: -a option changed to add files into a template
+                         -u option now updated a template
 
 0.4.9pre18-23: simplaret:
                - enhanced http retrieval: curl support
index b48a0f923d09969f0e1bbcfe466a0bbe04bb826f..1013c88a53b0a22ecb96298d5cbdb24a81b9f295 100755 (executable)
@@ -72,7 +72,7 @@ if [ -f $JAIL_LIST ]; then
     if [ "$?" == "0" ]; then
       echo updating $jailpath...
       if [ -d "$TEMPLATE_BASE.d" ] || [ -a "$TEMPLATE_BASE.template" ]; then
-        templatepkg -a $jail $jailpath
+        templatepkg -u $jail $jailpath
         template_merge $jailpath
         template_svn_commit $TEMPLATE_BASE
       fi
@@ -85,7 +85,7 @@ search_template main --update
 if [ "$?" == "0" ]; then
   if [ -a "$TEMPLATE_BASE.template" ] || [ -a "$TEMPLATE_BASE.template" ]; then
     echo updating main installation...
-    templatepkg -a main
+    templatepkg -u main
     template_merge /
     template_svn_commit $TEMPLATE_BASE
   fi
index 0029dcdf50c9910c90971139967aa27c198bb981..fb22e624704fce0eb64beb8b0e6bf45c1cdb0b32 100755 (executable)
@@ -1,7 +1,6 @@
 #!/bin/bash
 #
-# templatepkg v0.2: create a simplepkg package list from
-#                   a legacy slackware /var/log/packages
+# templatepkg v0.3: template maintenance script from simplepkg suite
 #
 # feedback: rhatto at riseup.net | gpl
 # 
@@ -29,65 +28,167 @@ else
   exit 1
 fi
 
-APPEND="0"
-if [[ ! -z "$3" && "$1" == "-a" ]]; then
-  ROOT="$3"
-  search_template $2 --new
-  APPEND="1"
-elif [[ ! -z "$2" && "$1" == "-a" ]]; then
-  ROOT="/"
-  search_template $2 --new
-  APPEND="1"
-elif [[ ! -z "$2" ]]; then
-  ROOT="$2"
-  search_template $1 --new
-elif [[ ! -z "$1" ]]; then
-  search_template $1 --new
-  ROOT="/"
-else
-  echo "usage: $BASENAME [-a] <template> [root-dir]"
-  echo -e "\t-a: append packages into a template"
+function usage {
+
+  echo "usage: $BASENAME <option> <template> [arguments]"
+  echo "options:"
+  echo ""
+  echo "  -u: update a template acording a jail; arguments:"
+  echo ""
+  echo "      $BASENAME -u <template> [jail-root]"
+  echo ""
+  echo "      (if ommited, jail-root defaults to /)"
+  echo ""
+  echo "  -a: add files into a template; arguments:"
+  echo ""
+  echo "      $BASENAME -a <template> <file-name> [jail-root]"
+  echo ""
+  echo "      file-name: the file or directory to be added"
+  echo "      jail-root: the jail under file-name is located"
+  echo ""
   exit 1
-fi
 
-TEMPLATE="$TEMPLATE_BASE.template"
+}
 
-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
+function template_update {
+
+  # update the template package list
 
-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
+  if [ ! -d "$ROOT/var/log/packages" ]; then
+    echo $ROOT/var/log/packages: directory not found
+    exit 1
+  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
-  else
-    package_name $package >> $TEMPLATE
+  done
+
+  # check 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
+        # remove 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
+
+}
+
+function template_add {
+
+  # add a file in a template
+  # usage: template_add <jail-root> <file>
+
+  local info_commit
+
+  mkdir -p $TEMPLATE_BASE.d
+
+  if [ -z "$1" ] || [ -z "$2" ]; then
+    return 1
   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
+
+  jail="/$1" 
+  file="$2"
+
+  if [ -a "$TEMPLATE_BASE.d/$file" ]; then
+    if [ -d "$TEMPLATE_BASE.d/$file" ]; then
+
+      echo $BASENAME: folder $file already on $TEMPLATE_BASE.d, checking for contents
+      cd $jail/$file
+      for candidate in `find`; do
+        if [ ! -a "$TEMPLATE_BASE.d/$candidate" ]; then
+          mkdir -p $TEMPLATE_BASE.d/`dirname $candidate`
+          cp -a $candidate $TEMPLATE_BASE.d/$candidate
+
+          if [ "$TEMPLATES_UNDER_SVN" == "1" ]; then
+            ( cd $TEMPLATE_BASE.d && svn add $candidate )
+            info_commit="yes"
+          fi
+
+        fi
+      done
+
+      if [ "$info_commit" == "yes" ]; then
+        echo $BASENAME: please run jail-commit to add files under $file into the svn repository
       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
+
+    else
+      echo $BASENAME: file $file already on $TEMPLATE_BASE.d
+      exti 1
+    fi
+  else
+    if [ -a "$jail/$file" ]; then
+
+      mkdir -p $TEMPLATE_BASE.d/`dirname $file`/
+      cp -a $jail/$file $TEMPLATE_BASE.d/$file
+      if [ "$TEMPLATES_UNDER_SVN" == "1" ]; then
+        ( cd $TEMPLATE_BASE.d && svn add $file )
+        echo $BASENAME: please run jail-commit to add $file into the svn repository
+        true
+      fi
+
+    else
+      echo $BASENAME: $jail/$file: file not found
+      exit 1
     fi
   fi
 
-done
+}
+
+# command line parsing
+
+if [ -z "$2" ]; then
+  usage
+fi
+
+search_template $2 --new
+TEMPLATE="$TEMPLATE_BASE.template"
+
+if [ "$1" == "-u" ] || [ "$1" == "--update" ]; then
+
+  if [ -z "$3" ]; then
+    ROOT="/"
+  else
+    ROOT="/$3"
+  fi
+
+  template_update
+
+elif [ "$1" == "-a" ] || [ "$1" == "--add" ]; then
+
+  if [ -z "$3" ]; then
+    usage
+  else
+    if [ -z "$4" ]; then
+      ROOT="/"
+    else
+      ROOT="$4"
+    fi
+  fi
+
+  template_add $ROOT $3
+
+else
+  usage
+fi
+