From: Michael Prokop Date: Wed, 12 Nov 2008 11:11:53 +0000 (+0100) Subject: Merge commit 'origin/t/tong' X-Git-Tag: v0.23~17 X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=commitdiff_plain;h=0b84da4baacdbf808e724e0119eb062da851e519;hp=fc42f013fde24d4cbc483c03fbe8f1c6738d370a Merge commit 'origin/t/tong' --- diff --git a/THANKS b/THANKS new file mode 100644 index 0000000..79c5625 --- /dev/null +++ b/THANKS @@ -0,0 +1,4 @@ +THANKS +====== + +Tong Sun [several patches/features] diff --git a/config b/config index 2ebb36e..92aff30 100644 --- a/config +++ b/config @@ -118,7 +118,7 @@ DEBCONF='yes' EXTRAPACKAGES='yes' # place of config files for debootstrap -CONFFILES='/etc/debootstrap/' +CONFFILES='/etc/debootstrap' # mount point where chroot actions should take place # MNTPOINT='/mnt/debootstrap' diff --git a/debian/changelog b/debian/changelog index e79a728..ba95205 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,8 +16,13 @@ grml-debootstrap (0.23) unstable; urgency=low debootstrap command - support KEEP_SRC_LIST to allow user to provide their own apt sources.list from /etc/debootstrap/etc/apt/sources.list + - provide cmdline processing in separate script + - added the '-d, --confdir=path' option + - added "--nodebootstrap": Skip debootstrap, only do configuration + to the target + - add -v, --verbose: Increase verbosity - -- Michael Prokop Mon, 06 Oct 2008 00:15:52 +0200 + -- Michael Prokop Mon, 20 Oct 2008 16:09:03 +0200 grml-debootstrap (0.22) unstable; urgency=low diff --git a/debian/rules b/debian/rules index 23340c9..10da65c 100755 --- a/debian/rules +++ b/debian/rules @@ -47,7 +47,7 @@ binary-indep: build install dh_testdir dh_testroot dh_installchangelogs - dh_installdocs TODO + dh_installdocs TODO THANKS dh_installman grml-debootstrap.8 dh_link dh_strip diff --git a/grml-debootstrap b/grml-debootstrap index 2fad7ee..78f70ac 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -11,6 +11,7 @@ set -e # exit on any error # variables {{{ PN="$(basename $0)" +prog_real=`readlink -f -- $0` VERSION='0.23' MNTPOINT="/mnt/debootstrap.$$" @@ -34,26 +35,44 @@ usage() { Usage: $PN [options] - -h|--help Print this usage information and exit. - -v|--version Show summary of options and exit. - - -c|--config Use specified configuration file, - defaults to /etc/debootstrap/config - --hostname Hostname of Debian system - -i|--iso Mountpoint where a Debian ISO is mounted to, - for use instead of fetching packages from a mirror - -m|--mirror Mirror which should be used for apt-get/aptitude. - -p|--mntpoint Mountpoint used for mounting the target system. - -r|--release Release of new Debian system (default: stable) - -t|--target Target partition (/dev/...) or directory. - - --boot_append Add specified appendline to kernel whilst booting - --groot Root device for usage in grub, corresponds with - \$TARGET in grub syntax, like hd0,0 for /dev/sda1 - --grub Target for grub installation. Use grub syntax - for specifying, like hd0 for /dev/sda - --interactive Use interactive mode (frontend) - --password Use specified password as password for user root. +Bootstrap options: + + -m, --mirror=URL Mirror which should be used for apt-get/aptitude. + -i, --iso=mnt Mountpoint where a Debian ISO is mounted to, for use + instead of fetching packages from a mirror. + -r, --release=name Release of new Debian system (default: stable). + -t, --target=target Target partition (/dev/...) or directory. + -p, --mntpoint=mnt Mountpoint used for mounting the target system. + --debopt=params Extra parameters passed to the debootstrap. + --interactive Use interactive mode (frontend). + --nodebootstrap Skip debootstrap, only do configuration to the target. + +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 + --packages[=f] Install packages defined in /packages. Option + arg: alternative package list file. + --debconf[=f] Pre-seed packages using /debconf-selections. + Option arg: alternative pre-seed db file. + --keep_src_list Do not overwrite user provided apt sources.list. + --hostname=name Hostname of Debian system. + --password=pwd Use specified password as password for user root. + + --bootappend=line Add specified appendline to kernel whilst booting. + --groot=device Root device for usage in grub, corresponds with + $TARGET in grub syntax, like hd0,0 for /dev/sda1. + --grub=device Target for grub installation. Use grub syntax for + specifying, like hd0 for /dev/sda. + +Other options: + + -v, --verbose Increase verbosity. + -h, --help Print this usage information and exit. + -V, --version Show summary of options and exit. Send bugreports to the grml-team: bugs@grml.org || http://grml.org/bugs/ " @@ -74,6 +93,7 @@ check4root || exit 1 # source configuration file {{{ if [ -r /etc/debootstrap/config ] ; then if [ -n "$CONFIGFILE" ] ; then + einfo "Using config file $CONFIGFILE." if ! . "$CONFIGFILE" ; then eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1 fi @@ -84,73 +104,56 @@ fi # }}} # cmdline handling {{{ +# source external command line parameter-processing script +. $prog_real.clp -while [ "$#" -gt "0" ] ; do - case $1 in - -c|--config) - shift - CONFIGFILE=$1 - ;; - --grub) - shift - GRUB=$1 - ;; - --groot) - shift - GROOT=$1 - ;; - -h|--help) - usage ; eend 0 - eend 0 - exit 0 - ;; - --hostname) - shift - HOSTNAME=$1 - ;; - --interactive) - INTERACTIVE=1 - ;; - -i|--iso) - shift - [ -n "$MIRROR" ] && unset MIRROR - ISO=$1 - ;; - -m|--mirror) - shift - MIRROR=$1 - CHROOTMIRROR=$1 - ;; - -p|--mntpoint) - shift - MNTPOINT=$1 - ;; - --password) - shift - ROOTPASSWORD=$1 - ;; - -r|--release) - shift - RELEASE=$1 - ;; - -t|--target) - shift - TARGET=$1 - ;; - -v|--version) - einfo "$PN - version $VERSION" - einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/" - eend 0 - exit 0 - ;; - *) - eerror "Syntax error." - usage ; eend 1 - exit 1 - ;; - esac - shift -done +# == business-logic of command line parameter-processing + +# source configuration file in if supplied. {{{ +[ "$_opt_confdir" ] && { + CONFFILES=$_opt_confdir + einfo "Using config files under $CONFFILES/." + 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 + # restore the command line parameter value + CONFFILES=$_opt_confdir +} +# }}} + +[ "$_opt_mirror" ] && MIRROR=$_opt_mirror +[ "$_opt_iso" ] && ISO=$_opt_iso +[ "$_opt_release" ] && RELEASE=$_opt_release +[ "$_opt_target" ] && TARGET=$_opt_target +[ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint +[ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt +[ "$_opt_interactive" ] && INTERACTIVE=1 +[ "$_opt_config" ] && CONFIGFILE=$_opt_config +[ "$_opt_packages_set" ] && PACKAGES='yes' +[ "$_opt_debconf_set" ] && DEBCONF='yes' +[ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes' +[ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname +[ "$_opt_password" ] && ROOTPASSWORD=$_opt_password +[ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend +[ "$_opt_groot" ] && GROOT=$_opt_groot +[ "$_opt_grub" ] && GRUB=$_opt_grub +[ "$_opt_verbose" ] && VERBOSE="-v" + +[ "$_opt_help" ] && { + usage ; eend 0 + eend 0 + exit 0 +} + +[ "$_opt_version" ] && { + einfo "$PN - version $VERSION" + einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/" + eend 0 + exit 0 +} # }}} # welcome screen {{{ @@ -514,7 +517,7 @@ fi if [ -n "$TARGET" ] ; then SHORT_TARGET="${TARGET##*/}" else - eerror "Please adjust /etc/debootstrap/config or..." + eerror "Please adjust $CONFFILES/config or..." eerror "... use the interactive version for configuration before running ${0}" ; eend 1 exit 1 fi @@ -693,6 +696,10 @@ debootstrap_system() { if ! grep -q $MNTPOINT /proc/mounts ; then mount_target fi + if [ "$_opt_nodebootstrap" ]; then + einfo "Skipping debootstrap as requested." + return + fi if grep -q $MNTPOINT /proc/mounts || [ -n "$DIRECTORY" ] ; then einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}" [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \ @@ -727,55 +734,57 @@ preparechroot() { [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES - cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script + cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script chmod 755 $MNTPOINT/bin/chroot-script mkdir $MNTPOINT/etc/debootstrap/ # make sure we have our files for later use via chroot-script - cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/ + cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/ # make sure we adjust the configuration variables accordingly: sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config - cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages - [ -f /etc/debootstrap/debconf-selections -a "$DEBCONF" = 'yes' ] && \ - cp /etc/debootstrap/debconf-selections $MNTPOINT/etc/debootstrap/ + cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \ + $MNTPOINT/etc/debootstrap/packages + _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections} + [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \ + cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead! - cp $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables + cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables - cp -a -L /etc/debootstrap/extrapackages/ $MNTPOINT/etc/debootstrap/ + cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/ # make sure we can access network [relevant for cdebootstrap] - [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf + [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf # provide system's /etc/hosts to the target: if ! [ -f "$MNTPOINT/etc/hosts" ] ; then - cp /etc/hosts $MNTPOINT/etc/hosts + cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts sed -i "s#127.0.0.1 .*#127.0.0.1 localhost $HOSTNAME#" /etc/hosts fi # setup default locales - [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen + [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen # MAKEDEV is just a forking bomb crap, let's do it on our own instead :) ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz ) # copy any existing files to chroot - [ -d /etc/debootstrap/bin ] && cp -a -L /etc/debootstrap/bin/* $MNTPOINT/bin/ - [ -d /etc/debootstrap/boot ] && cp -a -L /etc/debootstrap/boot/* $MNTPOINT/boot/ - [ -d /etc/debootstrap/etc ] && cp -a -L /etc/debootstrap/etc/* $MNTPOINT/etc/ - [ -d /etc/debootstrap/sbin ] && cp -a -L /etc/debootstrap/sbin/* $MNTPOINT/sbin/ - [ -d /etc/debootstrap/share ] && cp -a -L /etc/debootstrap/share/* $MNTPOINT/share/ - [ -d /etc/debootstrap/usr ] && cp -a -L /etc/debootstrap/usr/* $MNTPOINT/usr/ - [ -d /etc/debootstrap/var ] && cp -a -L /etc/debootstrap/var/* $MNTPOINT/var/ + [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/ + [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/ + [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/ + [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/ + [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/ + [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/ + [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/ # copy local network setup to chroot if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network - cp /etc/network/interfaces $MNTPOINT/etc/network/interfaces + cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces fi eend 0 diff --git a/grml-debootstrap.clp b/grml-debootstrap.clp new file mode 100644 index 0000000..496626c --- /dev/null +++ b/grml-debootstrap.clp @@ -0,0 +1,109 @@ +# -*- shell-script -*- +# Filename: grml-debootstrap.clp +# Purpose: shell script command line parameter-processing for grml-debootstrap +# Authors: grml-team (grml.org), Tong Sun +# Bug-Reports: see http://grml.org/bugs/ +# License: This file is licensed under the GPL v2 or any later version. +################################################################################ +# @WARNING: Do NOT modify this file without prior contacting the author. +# This script is use for the command line *logic* processing. It should be +# as dumb as possible. I.e., it should NOT be more complicated than +# copy-paste-and-rename from existing code. All *business-logic* processing +# should be handled in the main script, where it belongs. +################################################################################ + +_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::,debconf::,keep_src_list,hostname:,password:,bootappend:,groot:,grub:,verbose,help,version \ + -- "$@"` +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, for use instead + shift; _opt_iso="$1" + ;; + --release|-r) # Release of new Debian system (default: stable). + shift; _opt_release="$1" + ;; + --target|-t) # Target partition (/dev/...) or directory. + shift; _opt_target="$1" + ;; + --mntpoint|-p) # Mountpoint used for mounting the target system. + shift; _opt_mntpoint="$1" + ;; + --debopt) # Extra parameters passed to the debootstrap. + shift; _opt_debopt="$1" + ;; + --interactive) # Use interactive mode (frontend). + _opt_interactive=T + ;; + --nodebootstrap) # Skip debootstrap, only do configuration to the target. + _opt_nodebootstrap=T + ;; + # + + # == 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" + ;; + --packages) # Install packages defined in /packages. Option arg: + shift; _opt_packages="$1" + _opt_packages_set=T + ;; + --debconf) # Pre-seed packages using /debconf-selections. Option + shift; _opt_debconf="$1" + _opt_debconf_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" + ;; + # + --bootappend) # Add specified appendline to kernel whilst booting. + shift; _opt_bootappend="$1" + ;; + --groot) # Root device for usage in grub, corresponds with $TARGET in g + shift; _opt_groot="$1" + ;; + --grub) # Target for grub installation. Use grub syntax for specifying + shift; _opt_grub="$1" + ;; + + # == Other options + --verbose|-v) # Increase verbosity. + if [ "$_opt_verbose" ]; then _opt_verbose=`expr $_opt_verbose + 1` + else _opt_verbose=1; fi + ;; + --help|-h) # Print this usage information and exit. + _opt_help=T + ;; + --version|-V) # Show summary of options and exit. + _opt_version=T + ;; + --) + shift; break + ;; + *) + eerror "Internal getopt error!"; eend 1 ; exit 1 + ;; + esac + shift +done + +## END OF FILE #################################################################