Release new version 0.100
[grml-debootstrap.git] / chroot-script
index a5f92c4..101764d 100755 (executable)
@@ -75,8 +75,8 @@ askpass() {
 
 # define chroot mirror {{{
 chrootmirror() {
-  if [ -n "$KEEP_SRC_LIST" ] ; then
-    echo "KEEP_SRC_LIST has been set, skipping chrootmirror stage."
+  if [ "$KEEP_SRC_LIST" = "yes" ] ; then
+    echo "KEEP_SRC_LIST has been enabled, skipping chrootmirror stage."
     return
   fi
 
@@ -129,8 +129,8 @@ chrootmirror() {
 
 # remove local chroot mirror {{{
 remove_chrootmirror() {
-  if [ -n "$KEEP_SRC_LIST" ] ; then
-    echo "KEEP_SRC_LIST has been set, skipping remove_chrootmirror stage."
+  if [ "$KEEP_SRC_LIST" = "yes" ] ; then
+    echo "KEEP_SRC_LIST has been enabled, skipping remove_chrootmirror stage."
     return
   fi
 
@@ -152,48 +152,46 @@ remove_chrootmirror() {
 
 # set up grml repository {{{
 grmlrepos() {
-  if [ -n "$GRMLREPOS" ] ; then
-     # user might have provided their own apt sources.list
-     if ! grep -q grml /etc/apt/sources.list.d/grml.list 2>/dev/null ; then
-        cat >> /etc/apt/sources.list.d/grml.list << EOF
+  if [ -z "$GRMLREPOS" ] ; then
+    return 0
+  fi
+
+  # user might have provided their own apt sources configuration
+  if [ -r /etc/apt/sources.list.d/grml.list ] ; then
+    echo "File /etc/apt/sources.list.d/grml.list exists already, not modifying."
+  else
+    echo "Setting up /etc/apt/sources.list.d/grml.list."
+    cat > /etc/apt/sources.list.d/grml.list << EOF
 # grml: stable repository:
-  deb     http://deb.grml.org/ grml-stable  main
-  deb-src http://deb.grml.org/ grml-stable  main
+  deb     [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-stable main
+  deb-src [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-stable main
 
 # grml: testing/development repository:
-  deb     http://deb.grml.org/ grml-testing main
-  deb-src http://deb.grml.org/ grml-testing main
+  deb     [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-testing main
+  deb-src [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-testing main
 EOF
-     fi
-
-     # shellcheck disable=SC2086
-     if apt-get update $DPKG_OPTIONS; then
-       # shellcheck disable=SC2086
-       apt-get -y --allow-unauthenticated install grml-debian-keyring $DPKG_OPTIONS
-       # shellcheck disable=SC2086
-       apt-get update $DPKG_OPTIONS
-     else
-       # make sure we have the keys available for aptitude
-       gpg --keyserver subkeys.pgp.net --recv-keys 709BCE51568573EBC160E590F61E2E7CECDEA787
-       gpg --export 709BCE51568573EBC160E590F61E2E7CECDEA787 | apt-key add - || true # not yet sure
-       # why it's necessary, sometimes we get an error even though it works [mika]
-     fi
-
-     # make sure we install packages from Grml's pool only if not available
-     # from Debian!
-     if ! grep -q grml /etc/apt/preferences 2>/dev/null ; then
-        cat >> /etc/apt/preferences << EOF
-// debian pool (default):
-Package: *
-Pin: release o=Debian
-Pin-Priority: 996
+  fi
 
-// main grml-repository:
+  # make sure we install packages from Grml's pool only if not available from Debian
+  if [ -r /etc/apt/preferences.d/grml.pref ] ; then
+    echo "File /etc/apt/preferences.d/grml.pref exists already, not modifying."
+  else
+    echo "Setting up /etc/apt/preferences.d/grml.pref."
+    cat > /etc/apt/preferences.d/grml.pref << EOF
+Explanation: use Grml repository only after Debian ones
 Package: *
 Pin: origin deb.grml.org
-Pin-Priority: 991
+Pin-Priority: 100
 EOF
-     fi
+  fi
+
+  apt-get update -o Acquire::AllowInsecureRepositories=1
+  apt-get -y --allow-unauthenticated install grml-debian-keyring
+  apt-get update
+
+  if [ "$(dpkg-query -f "\${db:Status-Status} \${db:Status-Eflag}" -W grml-debian-keyring 2>/dev/null)" != 'installed ok' ]; then
+    echo "Error: installation of grml-debian-keyring failed." >&2
+    exit 1
   fi
 }
 # }}}
@@ -481,7 +479,15 @@ createfstab(){
 EOF
 
   if [ -n "$TARGET_UUID" ] ; then
-    echo "/dev/disk/by-uuid/${TARGET_UUID} /  auto    defaults,errors=remount-ro 0   1" >> /etc/fstab
+    local rootfs_mount_options=",errors=remount-ro"
+    case "${FILESYSTEM}" in
+      f2fs)
+        # errors=remount-ro is unsupported, see https://github.com/grml/grml-debootstrap/issues/163
+        rootfs_mount_options=""
+        ;;
+    esac
+
+    echo "/dev/disk/by-uuid/${TARGET_UUID} /  auto    defaults${rootfs_mount_options} 0   1" >> /etc/fstab
   else
     echo "Warning: couldn't identify target UUID for rootfs, your /etc/fstab might be incomplete."
   fi
@@ -587,6 +593,13 @@ efi_setup() {
   echo "Mounting $EFI on /boot/efi"
   mount "$EFI" /boot/efi || return 1
 
+  # if efivarfs kernel module is loaded, but efivars isn't,
+  # then we need to mount efivarfs for efibootmgr usage
+  if ! ls /sys/firmware/efi/efivars/* &>/dev/null ; then
+    echo "Mounting efivarfs on /sys/firmware/efi/efivars"
+    mount -t efivarfs efivarfs /sys/firmware/efi/efivars
+  fi
+
   echo "Invoking efibootmgr"
   efibootmgr || return 1
 }
@@ -707,6 +720,8 @@ finalize() {
 
   [ -n "$POLICYRCD" ] && rm -f /usr/sbin/policy-rc.d
 
+  umount /sys/firmware/efi/efivars &>/dev/null || true
+
   umount /sys >/dev/null 2>/dev/null || true
   umount /proc >/dev/null 2>/dev/null || true
 }