Merge branch 'mika/wheezy_release'
[grml-debootstrap.git] / grml-debootstrap
index 06632cd..6b5fa17 100755 (executable)
@@ -20,17 +20,18 @@ DEBCONF='yes'
 DEBIAN_FRONTEND='noninteractive'
 DEBOOTSTRAP='debootstrap'
 EXTRAPACKAGES='yes'
+FALLBACK_MIRROR='http://cdn.debian.net/debian'
 FORCE=''
 HOSTNAME='grml'
 INITRD='yes'
 INSTALL_NOTES='/etc/debootstrap/install_notes'
 LOCALES='yes'
-MIRROR='http://cdn.debian.net/debian'
+MIRROR="$FALLBACK_MIRROR"
 MKFS='mkfs.ext3'
 PACKAGES='yes'
 PRE_SCRIPTS='yes'
 RECONFIGURE='console-data'
-RELEASE='squeeze'
+RELEASE='wheezy'
 RM_APTCACHE='yes'
 SCRIPTS='yes'
 SECURE='yes'
@@ -59,7 +60,7 @@ 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: squeeze).
+  -r, --release <name>   Release of new Debian system (default: wheezy).
   -t, --target <target>  Target partition (/dev/...) or directory where the
                          system should be installed to.
   -p, --mntpoint <mnt>   Mountpoint used for mounting the target system,
@@ -493,13 +494,13 @@ prompt_for_bootmanager()
 # ask for Debian release {{{
 prompt_for_release()
 {
-  [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='squeeze'
+  [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='wheezy'
   RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
             "Please enter the Debian release you would like to use for installation:" \
             0 50 4 \
-            lenny    Debian/old-stable \
-            squeeze  Debian/stable \
-            wheezy   Debian/testing \
+            lenny    Debian/5.0 \
+            squeeze  Debian/6.0 \
+            wheezy   Debian/7.0 \
             sid      Debian/unstable)"
   [ $? -eq 0 ] || bailout
 }
@@ -689,11 +690,13 @@ elif [ -n "$INTERACTIVE" ] ; then
    [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
    Using release:   $RELEASE"
    [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
-   Using hostname   $HOSTNAME"
+   Using hostname:  $HOSTNAME"
    [ -n "$MIRROR" ]  && INFOTEXT="$INFOTEXT
    Using mirror:    $MIRROR"
    [ -n "$ISO" ]  && INFOTEXT="$INFOTEXT
    Using ISO:       $ISO"
+   [ -n "$ARCH" ]  && INFOTEXT="$INFOTEXT
+   Using arch:      $ARCH"
 
    INFOTEXT="$INFOTEXT
 
@@ -704,7 +707,7 @@ Is this ok for you? Notice: selecting 'No' will exit ${PN}."
    [ $? -eq 0 ] || bailout 0
 
 else # if not running automatic installation display configuration and prompt for execution:
-   einfo "$PN - Please recheck configuration before execution:"
+   einfo "$PN [${VERSION}] - Please recheck configuration before execution:"
    echo
    echo "   Target:          $TARGET"
 
@@ -718,9 +721,10 @@ else # if not running automatic installation display configuration and prompt fo
    fi
 
    [ -n "$RELEASE" ]  && echo "   Using release:   $RELEASE"
-   [ -n "$MIRROR" ]   && echo "   Using mirror:    $MIRROR"
    [ -n "$HOSTNAME" ] && echo "   Using hostname:  $HOSTNAME"
+   [ -n "$MIRROR" ]   && echo "   Using mirror:    $MIRROR"
    [ -n "$ISO" ]      && echo "   Using ISO:       $ISO"
+   [ -n "$ARCH" ]     && echo "   Using arch:      $ARCH"
    if [ -n "$VIRTUAL" ] ; then
       echo "   Deploying as Virtual Machine."
       [ -n "$VMSIZE" ] && echo "   Using Virtual Disk file with size of ${VMSIZE}."
@@ -774,6 +778,17 @@ if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
 fi
 # }}}
 
+# architecture setup {{{
+if [ -n "$ARCH" ] ; then
+   ARCHCMD="--arch $ARCH"
+   ARCHINFO=" (${ARCH})"
+else
+   ARCH="$(dpkg --print-architecture)"
+   ARCHCMD="--arch $ARCH"
+   ARCHINFO=" (${ARCH})"
+fi
+# }}}
+
 checkconfiguration
 
 # finally make sure at least $TARGET is set [the partition for the new system] {{{
@@ -825,24 +840,13 @@ else
 fi
 # }}}
 
-# architecture setup {{{
-if [ -n "$ARCH" ] ; then
-   ARCHCMD="--arch $ARCH"
-   ARCHINFO=" (${ARCH})"
-else
-   ARCH="$(dpkg --print-architecture)"
-   ARCHCMD="--arch $ARCH"
-   ARCHINFO=" (${ARCH})"
-fi
-# }}}
-
 # make sure we have the right syntax when using an iso image {{{
 if [ -n "$ISO" ] ; then
    case $ISO in
       file*) # do nothing
       ;;
       *)
-      ISO=file:$1
+      ISO=file:$ISO
       ;;
    esac
 fi
@@ -850,6 +854,12 @@ ISODIR=${ISO##file:}
 ISODIR=${ISODIR%%/}
 # }}}
 
+# Debian ISOs do not contain signed Release files {{{
+if [ -n "$ISO" ] ; then
+    DEBOOTSTRAP_OPT="$DEBOOTSTRAP_OPT --no-check-gpg"
+fi
+# }}}
+
 # create filesystem {{{
 mkfs() {
   if [ -n "$DIRECTORY" ] ; then
@@ -942,7 +952,7 @@ prepare_vm() {
 
   # if dm-mod isn't available then kpartx will fail with
   # "Is device-mapper driver missing from kernel? [...]"
-  if ! kpartx -av $TARGET >/dev/null 2>&1 ; then
+  if ! kpartx -av $TARGET >/dev/null 2>&1 || ! grep -q device-mapper /proc/misc >/dev/null 2>&1 ; then
     einfo "Device-mapper not ready yet, trying to load dm-mod module."
     modprobe dm-mod ; eend $?
   fi
@@ -1008,6 +1018,9 @@ finalize_vm() {
   rm -f "${MNTPOINT}/tmp/core.img"
 
   einfo "Updating grub configuration file."
+  if [ -n "$BOOT_APPEND" ] ; then
+     sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/ s#\"\$# ${BOOT_APPEND}\"#" "${MNTPOINT}"/etc/default/grub
+  fi
   chroot "${MNTPOINT}" update-grub
 
   umount "${MNTPOINT}"/proc
@@ -1038,15 +1051,16 @@ debootstrap_system() {
     eend 1 ; exit 1
   fi
 
-  einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
-  if [ -n "$MIRROR" ] ; then
-    einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
-    $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
-    RC=$?
-  else
+  if [ -n "$ISO" ] ; then
+    einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${ISO}"
     einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
     $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
     RC=$?
+  else
+    einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}"
+    einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
+    $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
+    RC=$?
   fi
 
   if [ $RC -ne 0 ] ; then
@@ -1078,6 +1092,7 @@ preparechroot() {
   [ -n "$DEBIAN_FRONTEND" ]     && echo "DEBIAN_FRONTEND=\"$DEBIAN_FRONTEND\""         >> $CHROOT_VARIABLES
   [ -n "$DEBOOTSTRAP" ]         && echo "DEBOOTSTRAP=\"$DEBOOTSTRAP\""                 >> $CHROOT_VARIABLES
   [ -n "$EXTRAPACKAGES" ]       && echo "EXTRAPACKAGES=\"$EXTRAPACKAGES\""             >> $CHROOT_VARIABLES
+  [ -n "$FALLBACK_MIRROR" ]     && echo "FALLBACK_MIRROR=\"$FALLBACK_MIRROR\""         >> $CHROOT_VARIABLES
   [ -n "$FORCE" ]               && echo "FORCE=\"$FORCE\""                             >> $CHROOT_VARIABLES
   [ -n "$GRMLREPOS" ]           && echo "GRMLREPOS=\"$GRMLREPOS\""                     >> $CHROOT_VARIABLES
   [ -n "$GRUB" ]                && echo "GRUB=\"$GRUB\""                               >> $CHROOT_VARIABLES