Add missing vim folding markers
[grml-debootstrap.git] / grml-debootstrap
index 0637089..78e6dc4 100755 (executable)
@@ -339,19 +339,171 @@ fi
 # }}}
 
 # cmdline handling {{{
-# source external command line parameter-processing script
-self_dir="$(dirname "$(which "$0")")"
-if [ -r "${self_dir}"/cmdlineopts.clp ] ; then
-  # shellcheck source=cmdlineopts.clp
-  . "${self_dir}"/cmdlineopts.clp
-elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
-  # shellcheck source=cmdlineopts.clp
-  . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
-else
-  eerror "Error: cmdline function file not found, exiting."
-  eend 1
-  bailout 1
+CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs
+
+_opt_temp=$(getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \
+  $CMDLINE_OPTS -- "$@")
+
+if [ $? != 0 ]; then
+  eerror "Try 'grml-debootstrap --help' for more information."; eend 1; exit 1
 fi
+eval set -- "$_opt_temp"
+
+while :; do
+  case "$1" in
+
+  # == Bootstrap options
+  --mirror|-m)         # Mirror which should be used for apt-get/aptitude
+    shift; _opt_mirror="$1"
+    ;;
+  --iso|-i)            # Mountpoint where a Debian ISO is mounted to
+    shift; _opt_iso="$1"
+    ;;
+  --release|-r)        # Release of new Debian system
+    shift; _opt_release="$1"
+    ;;
+  --target|-t)         # Target partition (/dev/...) or directory
+    shift; _opt_target="$1"
+    ;;
+  --vm)                # Virtual machine image (no file)
+    _opt_vm="T"
+    ;;
+  --vmfile)            # Virtual machine file
+    _opt_vmfile="T"
+    ;;
+  --vmsize)            # size of Virtual machine file
+    shift; _opt_vmsize="$1"
+    ;;
+  --mntpoint|-p)       # Mountpoint used for mounting the target system
+    shift; _opt_mntpoint="$1"
+    ;;
+  --debopt)            # Extra parameters passed to the debootstrap command
+    shift; _opt_debopt="$1"
+    ;;
+  --filesystem)        # Filesystem that should be used
+    shift; _opt_filesystem="$1"
+    ;;
+  --interactive)       # Use interactive mode (frontend)
+    _opt_interactive=T
+    ;;
+  --nodebootstrap)     # Skip debootstrap, only do configuration to the target
+    _opt_nodebootstrap=T
+    ;;
+  --nopackages)        # Skip installation of packages defined in /etc/debootstrap/packages
+    _opt_nopackages=T
+    ;;
+  --arch)              # Target architecutre
+    shift; _opt_arch="$1"
+    ;;
+  # just for backwards compatibility
+  --insecure)
+    _opt_insecure=T
+    ;;
+  #
+
+  # == Configuration options
+  --config|-c)         # Use specified configuration file, defaults to /etc/debootstrap
+    shift; _opt_config="$1"
+    ;;
+  --confdir|-d)        # Place of config files for debootstrap, defaults to /etc/debootstrap
+    shift; _opt_confdir="$1"
+    ;;
+  --packages)          # Install packages defined in specified file
+    shift; _opt_packages="$1"
+    _opt_packages_set=T
+    ;;
+  --debconf)           # Pre-seed packages using specified file
+    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 [NOTE: deprecated, replaced via --post-scripts]
+    shift; _opt_scripts="$1"
+    _opt_scripts_set=T
+    ;;
+  --post-scripts)       # Execute scripts from specified directory
+    shift; _opt_post_scripts="$1"
+    _opt_post_scripts_set=T
+    ;;
+  --chroot-scripts)   # Execute chroot scripts from specified directory
+    shift; _opt_chroot_scripts="$1"
+    _opt_chroot_scripts_set=T
+    ;;
+  --keep_src_list)     # Do not overwrite user provided apt sources.list
+    _opt_keep_src_list=T
+    ;;
+  --hostname)          # Hostname of Debian system
+    shift; _opt_hostname="$1"
+    ;;
+  --password)          # Use specified password as password for user root
+    shift; _opt_password="$1"
+    ;;
+  --defaultinterfaces) # Install default /etc/network/interfaces
+    _opt_defaultinterfaces=T
+    ;;
+  --nointerfaces)      # Skip installation of /etc/network/interfaces
+    _opt_nointerfaces=T
+    ;;
+  --nokernel)          # Skip installation of default kernel images
+    _opt_nokernel=T
+    ;;
+  --nopassword)        # Skip password dialog
+    _opt_nopassword=T
+    ;;
+  --grmlrepos)         # Enable Grml repository
+    _opt_grmlrepos=T
+    ;;
+  --backportrepos)     # Enable Debian backports repository
+    _opt_backportrepos=T
+    ;;
+  --bootappend)        # Add specified appendline to kernel whilst booting
+    shift; _opt_bootappend="$1"
+    ;;
+  --grub)              # Target for grub installation. Use grub syntax for specifying
+    shift; _opt_grub="$1"
+    ;;
+  --efi)               # Target for EFI boot installation
+    shift; _opt_efi="$1"
+    ;;
+  --contrib)           # Add 'contrib' to list of components
+    _opt_contrib=T
+    ;;
+  --non-free)          # Add 'non-free' to list of components
+    _opt_non_free=T
+    ;;
+  --remove-configs)    # Drop config files from installed system
+    _opt_remove_configs=T
+    ;;
+
+  # == Other options
+  --verbose|-v)        # Increase verbosity
+    if [ "$_opt_verbose" ]; then _opt_verbose=`expr $_opt_verbose + 1`
+    else _opt_verbose=1; fi
+    ;;
+  --debug)             # Execute in debug mode
+    _opt_debug=T
+    ;;
+  --help|-h)           # Print usage information and exit
+    _opt_help=T
+    ;;
+  --version|-V)        # Show version information and exit
+    _opt_version=T
+    ;;
+  --force)             # Do not prompt for user input
+    _opt_force=T
+    ;;
+  --)
+    shift; break
+    ;;
+  *)
+    eerror "Internal getopt error!"; eend 1 ; exit 1
+    ;;
+  esac
+  shift
+done
 
 # == business-logic of command line parameter-processing
 
@@ -773,6 +925,7 @@ Do you want to stop now?" 0 0 2>/dev/null
 }
 # }}}
 
+# format efi partition {{{
 format_efi_partition() {
   if [ -z "$EFI" ] ; then
     return 0
@@ -798,6 +951,7 @@ format_efi_partition() {
     fi
   fi
 }
+# }}}
 
 # check for EFI support or try to enable it {{{
 efi_support() {
@@ -1132,6 +1286,7 @@ mkfs() {
 }
 # }}}
 
+# retrieve ID_FS_UUID {{{
 identify_target_uuid() {
   local device="$1"
 
@@ -1147,7 +1302,9 @@ identify_target_uuid() {
     return 1
   fi
 }
+# }}}
 
+# identify TARGET_UUID {{{
 mountpoint_to_blockdevice() {
   TARGET_UUID=''
 
@@ -1172,6 +1329,7 @@ mountpoint_to_blockdevice() {
     fi
   done
 }
+# }}}
 
 # modify filesystem settings {{{
 tunefs() {
@@ -1599,6 +1757,7 @@ execute_post_scripts() {
 }
 # }}}
 
+# unmount mountpoint {{{
 try_umount() {
   local tries=$1
   local mountpoint="$2"
@@ -1618,6 +1777,7 @@ try_umount() {
   done
   return 1  # Tried enough
 }
+# }}}
 
 # execute chroot-script {{{
 chrootscript() {