# variables {{{
PN="$(basename $0)"
-VERSION='0.33-pre1'
+VERSION='0.33'
MNTPOINT="/mnt/debootstrap.$$"
# inside the chroot system locales might not be available, so use minimum:
--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:
# cmdline handling {{{
# source external command line parameter-processing script
-if [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
- . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
-elif [ -r ./cmdlineopts.clp ] ; then
+if [ -r ./cmdlineopts.clp ] ; then
. ./cmdlineopts.clp
+elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
+ . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
else
echo "Error: cmdline function file not found, exiting.">&2
exit 1
[ "$_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
PARTITION=''
DIRECTORY=''
-case $TARGET in
- /dev/*)
- PARTITION=1
- ;;
- *)
+set_target_directory(){
# assume we are installing into a directory, don't run mkfs and grub related stuff therefore
DIRECTORY=1
MNTPOINT="$TARGET"
TUNE2FS=''
FSCK=''
GRUB=''
- ;;
-esac
+ # make sure we normalise the path to an absolute directory name so something like:
+ # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
+ # works
+ TARGET="$(readlink -f $TARGET)"
+}
+
+if [ -b "$TARGET" ] ; then
+ PARTITION=1
+else
+ set_target_directory
+fi
# }}}
# architecture setup {{{
# make sure nothing is left inside chroot so we can unmount it
[ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
[ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
- # ugly, but make sure we really don't leav anything
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
- [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
+ # ugly, but make sure we really don't leav anything (/proc /proc is intended)
+ for ARG in /sys -a /proc /proc ; do
+ [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG 1>/dev/null 2>&1 || true
+ done
+ umount "$MNTPOINT"/dev 1>/dev/null 2>&1 || true
+
+ [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1 || true
if [ -n "$DIRECTORY" ] ; then
einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
}
# }}}
+# 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
# 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"