Re-think the confdir logic
authorTong Sun <suntong@cpan.org>
Fri, 17 Oct 2008 21:23:44 +0000 (17:23 -0400)
committerMichael Prokop <mika@grml.org>
Mon, 20 Oct 2008 14:04:51 +0000 (16:04 +0200)
the default configuration file should always be /etc/debootstrap/config,
regardless whether --confdir=path is supplied or not.
However, if --confdir=path is supplied, everything should be based on it,
including the configuration file.

grml-debootstrap
grml-debootstrap.clp

index 809e9e4..908aad9 100755 (executable)
@@ -49,10 +49,10 @@ Bootstrap options:
 Configuration options:
 
 
 Configuration options:
 
 
+  -c, --config=file      Use specified configuration file, defaults to
+                           /etc/debootstrap/config
   -d, --confdir=path     Place of config files for debootstrap, defaults to
                            /etc/debootstrap
   -d, --confdir=path     Place of config files for debootstrap, defaults to
                            /etc/debootstrap
-  -c, --config=file      Use specified configuration file, defaults to
-                           <confdir>/config
       --packages[=f]     Install packages defined in <confdir>/packages. Option
                            arg: alternative package list file.
       --debconf[=f]      Pre-seed packages using <confdir>/debconf-selections.
       --packages[=f]     Install packages defined in <confdir>/packages. Option
                            arg: alternative package list file.
       --debconf[=f]      Pre-seed packages using <confdir>/debconf-selections.
@@ -104,7 +104,20 @@ fi
 # source external command line parameter-processing script
 . $prog_real.clp
 
 # source external command line parameter-processing script
 . $prog_real.clp
 
-# business-logic of command line parameter-processing
+# == business-logic of command line parameter-processing
+
+# source configuration file in <confdir> if supplied. {{{
+[ "$_opt_confdir" ] && {
+  CONFFILES=$_opt_confdir
+  if ! [ -r "$CONFFILES/config" ] ; then
+    eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
+  fi
+  if ! . "$CONFFILES/config" ; then
+    eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
+  fi
+}
+# }}}
+
 [ "$_opt_mirror" ]             && MIRROR=$_opt_mirror
 [ "$_opt_iso" ]                        && ISO=$_opt_iso
 [ "$_opt_release" ]            && RELEASE=$_opt_release
 [ "$_opt_mirror" ]             && MIRROR=$_opt_mirror
 [ "$_opt_iso" ]                        && ISO=$_opt_iso
 [ "$_opt_release" ]            && RELEASE=$_opt_release
@@ -112,7 +125,6 @@ fi
 [ "$_opt_mntpoint" ]           && MNTPOINT=$_opt_mntpoint
 [ "$_opt_debopt" ]             && DEBOOTSTRAP_OPT=$_opt_debopt
 [ "$_opt_interactive" ]                && INTERACTIVE=1
 [ "$_opt_mntpoint" ]           && MNTPOINT=$_opt_mntpoint
 [ "$_opt_debopt" ]             && DEBOOTSTRAP_OPT=$_opt_debopt
 [ "$_opt_interactive" ]                && INTERACTIVE=1
-[ "$_opt_confdir" ]            && CONFFILES=$_opt_confdir
 [ "$_opt_config" ]             && CONFIGFILE=$_opt_config
 [ "$_opt_packages_set" ]       && PACKAGES='yes'
 [ "$_opt_debconf_set" ]                && DEBCONF='yes'
 [ "$_opt_config" ]             && CONFIGFILE=$_opt_config
 [ "$_opt_packages_set" ]       && PACKAGES='yes'
 [ "$_opt_debconf_set" ]                && DEBCONF='yes'
index 4e43b4a..2038db8 100644 (file)
 
 
 
 
 
 
-_opt_temp=`getopt --name grml-debootstrap -o +m:i:r:t:p:d:c:hv --long \
-    mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,confdir:,config:,packages::,debconf::,keep_src_list,hostname:,password:,bootappend:,groot:,grub:,help,version \
+_opt_temp=`getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:hv --long \
+    mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,config:,confdir:,packages::,debconf::,keep_src_list,hostname:,password:,bootappend:,groot:,grub:,help,version \
   -- "$@"`
 if [ $? != 0 ]; then
   -- "$@"`
 if [ $? != 0 ]; then
-  eerror "Try `grml-debootstrap --help' for more information."; eend 1; exit 1
+  eerror "Try 'grml-debootstrap --help' for more information."; eend 1; exit 1
 fi
 eval set -- "$_opt_temp"
 
 fi
 eval set -- "$_opt_temp"
 
@@ -55,12 +55,12 @@ while :; do
   #
 
   # == Configuration options
   #
 
   # == Configuration options
+  --config|-c)         # Use specified configuration file, defaults to /etc/debootstr
+    shift; _opt_config="$1"
+    ;;
   --confdir|-d)        # Place of config files for debootstrap, defaults to /etc/debo
     shift; _opt_confdir="$1"
     ;;
   --confdir|-d)        # Place of config files for debootstrap, defaults to /etc/debo
     shift; _opt_confdir="$1"
     ;;
-  --config|-c)         # Use specified configuration file, defaults to <confdir>/conf
-    shift; _opt_config="$1"
-    ;;
   --packages)          # Install packages defined in <confdir>/packages. Option arg:
     shift; _opt_packages="$1"
     _opt_packages_set=T
   --packages)          # Install packages defined in <confdir>/packages. Option arg:
     shift; _opt_packages="$1"
     _opt_packages_set=T