introduce --pre-scripts to be executed before chroot-scripts
authorMichael Gebetsroither <michael@mgeb.org>
Sat, 5 Dec 2009 16:16:19 +0000 (17:16 +0100)
committerMichael Gebetsroither <michael@mgeb.org>
Sat, 5 Dec 2009 17:21:56 +0000 (18:21 +0100)
cmdlineopts.clp
grml-debootstrap

index 9d481b4..5d259a5 100644 (file)
@@ -13,7 +13,7 @@
 ################################################################################
 
 _opt_temp=`getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \
-    mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,nodebootstrap,config:,confdir:,packages:,chroot-scripts:,scripts:,debconf:,keep_src_list,hostname:,password:,bootappend:,grub:,arch:,insecure,verbose,help,version \
+    mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,nodebootstrap,config:,confdir:,packages:,chroot-scripts:,scripts:,pre-scripts:,debconf:,keep_src_list,hostname:,password:,bootappend:,grub:,arch:,insecure,verbose,help,version \
   -- "$@"`
 if [ $? != 0 ]; then
   eerror "Try 'grml-debootstrap --help' for more information."; eend 1; exit 1
@@ -71,6 +71,10 @@ while :; do
     shift; _opt_debconf="$1"
     _opt_debconf_set=T
     ;;
+  --pre-scripts)       # Execute scripts from specified directory (before chroot-scripts).
+    shift; _opt_pre_scripts="$1"
+    _opt_pre_scripts_set=T
+    ;;
   --scripts)           # Execute scripts from specified directory
     shift; _opt_scripts="$1"
     _opt_scripts_set=T
index 0409092..53f1e20 100755 (executable)
@@ -64,7 +64,8 @@ Configuration options:
       --password <pwd>     Use specified password as password for user root.
       --bootappend <line>  Add specified appendline to kernel whilst booting.
       --chroot-scripts <d> Execute chroot scripts from specified directory.
-      --scripts <dir>      Execute scripts from specified directory.
+      --pre-scripts <dir>  Execute scripts from specified directory (before chroot-scripts).
+      --scripts <dir>      Execute scripts from specified directory (after chroot-scripts).
 
 Other options:
 
@@ -141,6 +142,7 @@ fi
 [ "$_opt_packages_set" ]        && PACKAGES='yes'
 [ "$_opt_debconf_set" ]         && DEBCONF='yes'
 [ "$_opt_scripts_set" ]         && SCRIPTS='yes'
+[ "$_opt_pre_scripts_set" ]     && PRE_SCRIPTS='yes'
 [ "$_opt_chroot_scripts_set" ]  && CHROOT_SCRIPTS='yes'
 [ "$_opt_keep_src_list" ]       && KEEP_SRC_LIST='yes'
 [ "$_opt_hostname" ]            && HOSTNAME=$_opt_hostname
@@ -856,6 +858,22 @@ preparechroot() {
 }
 # }}}
 
+# execute all scripts in /etc/debootstrap/pre-scripts/ {{{
+execute_pre_scripts() {
+   # make sure we have $MNTPOINT available for our scripts
+   export MNTPOINT
+   if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
+      [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
+      for script in ${pre_scripts}/* ; do
+         if [ -x "$script" ] ; then
+            einfo "Executing pre-script $script"
+            $script ; eend $?
+         fi
+      done
+   fi
+}
+# }}}
+
 # execute all scripts in /etc/debootstrap/scripts/ {{{
 execute_scripts() {
    # make sure we have $MNTPOINT available for our scripts
@@ -954,7 +972,7 @@ fscktool() {
 
 # now execute all the functions {{{
 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
-         chrootscript execute_scripts grub_install umount_chroot   \
+         execute_pre_scripts chrootscript execute_scripts grub_install umount_chroot   \
          fscktool ; do
     if stage "${i}" ; then
        $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"