Resync with Debian git
authorMichael Prokop <mika@grml.org>
Thu, 23 Apr 2009 09:23:30 +0000 (11:23 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 23 Apr 2009 09:32:05 +0000 (11:32 +0200)
Makefile
bin/live-swapfile [new file with mode: 0755]
debian/control
scripts/live-bottom/12fstab
scripts/live-helpers

index 40ce7af..e01ae9b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ install: test build
 
        # Installing executables
        mkdir -p $(DESTDIR)/sbin
-       cp bin/live-getty bin/live-login bin/live-new-uuid bin/live-snapshot $(DESTDIR)/sbin
+       cp bin/live-getty bin/live-login bin/live-new-uuid bin/live-snapshot bin/live-swapfile $(DESTDIR)/sbin
 
        mkdir -p $(DESTDIR)/usr/share/live-initramfs
        cp bin/live-preseed bin/live-reconfigure contrib/languagelist $(DESTDIR)/usr/share/live-initramfs
@@ -76,7 +76,7 @@ uninstall:
        rm -f $(DESTDIR)/etc/live.conf
 
        # Uninstalling executables
-       rm -f $(DESTDIR)/sbin/live-getty $(DESTDIR)/sbin/live-login $(DESTDIR)/sbin/live-snapshot
+       rm -f $(DESTDIR)/sbin/live-getty $(DESTDIR)/sbin/live-login $(DESTDIR)/sbin/live-snapshot $(DESTDIR)/sbin/live-swapfile
        rm -rf $(DESTDIR)/usr/share/live-initramfs
        rm -f $(DESTDIR)/usr/share/initramfs-tools/hooks/live
        rm -rf $(DESTDIR)/usr/share/initramfs-tools/scripts/live*
diff --git a/bin/live-swapfile b/bin/live-swapfile
new file mode 100755 (executable)
index 0000000..2c61036
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+# File: live-swapfile - create and use a swap file
+# Copyright: (C) 2009 Daniel Baumann <daniel@debian.org>
+# License: GPL-3+
+
+set -e
+
+# Options
+_SWAP_DIRECTORY="${_SWAP_DIRECTORY:-/live/swap}"
+_SWAP_FILE="${_SWAP_FILE:-swapfile.img}"
+
+_SWAP_SIZE="${_SWAP_SIZE:-auto}"
+_SWAP_FACTOR="${_SWAP_FACTOR:-2}"
+
+_SWAP_PURGE="${_SWAP_PURGE:-true}"
+_FORCE="${_FORCE:-true}"
+
+case "${1}" in
+       add)
+               # Reading size of physical memory
+               _MEM_TOTAL_KB="$(awk '/^MemTotal: / { print $2 }' /proc/meminfo)"
+               _MEM_TOTAL_MB="$(expr ${_MEM_TOTAL_KB} / 1024)"
+
+               echo "Found ${_MEM_TOTAL_MB} MB physical memory."
+
+               # Setting size of new swapfile
+               if [ -z "${_SWAP_SIZE}" ] || [ "${_SWAP_SIZE}" = "auto" ]
+               then
+                       _SWAP_SIZE_KB="$(expr ${_MEM_TOTAL_KB} '*' ${_SWAP_FACTOR})"
+                       _SWAP_SIZE_MB="$(expr ${_SWAP_SIZE_KB} / 1024)"
+               else
+                       _SWAP_SIZE_MB="${_SWAP_SIZE}"
+               fi
+
+               echo "Requesting ${_SWAP_SIZE_MB} MB swapfile."
+
+               # Reading size of old swapfile
+               if [ -e "${_SWAP_DIRECTORY}/${_SWAP_FILE}" ]
+               then
+                       _SWAP_FILESIZE="$(ls -hl ${_SWAP_DIRECTORY}/${_SWAP_FILE} | awk '{ print $5 }')"
+
+                       echo "Found ${_SWAP_FILESIZE} MB swapfile."
+               fi
+
+               # Creating new swap file
+               if [ "${_SWAP_FILESIZE}" != "${_SWAP_SIZE_MB}M" ]
+               then
+                       if [ "${_FORCE}" = "true" ]
+                       then
+                               # Removing old swapfile
+                               rm -f "${_SWAP_DIRECTORY}/${_SWAP_FILE}"
+
+                               echo "Creating ${_SWAP_SIZE_MB} MB swapfile."
+
+                               mkdir -p "${_SWAP_DIRECTORY}"
+
+                               # Unfortunately, swapon does not support files
+                               # with holes, therefore we cannot preallocate.
+                               dd if=/dev/zero of="${_SWAP_DIRECTORY}/${_SWAP_FILE}"  bs=1024k count="${_SWAP_SIZE_MB}"
+                       else
+                               echo "Exit."
+                               return 1
+                       fi
+               fi
+
+               echo "Enabling ${_SWAP_DIRECTORY}/${_SWAP_FILE}."
+
+               mkswap "${_SWAP_DIRECTORY}/${_SWAP_FILE}"
+               swapon "${_SWAP_DIRECTORY}/${_SWAP_FILE}"
+               ;;
+
+       rm|remove)
+               if grep -qs "${_SWAP_DIRECTORY}/${_SWAP_FILE}" /proc/swaps
+               then
+                       echo "Disabling ${_SWAP_DIRECTORY}/${_SWAP_FILE}."
+
+                       swapoff "${_SWAP_DIRECTORY}/${_SWAP_FILE}"
+               fi
+
+               if [ "${_SWAP_PURGE}" = "true" ]
+               then
+                       echo "Removing ${_SWAP_DIRECTORY}/${_SWAP_FILE}."
+
+                       rm -f "${_SWAP_DIRECTORY}/${_SWAP_FILE}"
+
+                       __DIRECTORY="${_SWAP_DIRECTORY}"
+                       while [ "${__DIRECTORY}" != "/" ]
+                       do
+                               rmdir --ignore-fail-on-non-empty "${__DIRECTORY}"
+                               __DIRECTORY="$(dirname ${__DIRECTORY})"
+                       done
+               fi
+               ;;
+
+       *)
+               echo "Usage: ${0} {add|remove}"
+               exit 1
+               ;;
+esac
index 367cde5..4583715 100644 (file)
@@ -13,7 +13,7 @@ XS-Upstream-Depends: git-core
 Package: live-initramfs
 Architecture: all
 Depends: ${misc:Depends}, busybox, file, initramfs-tools, sudo, udev, user-setup
-Recommends: eject, uuid-runtime, wget
+Recommends: cryptsetup, eject, uuid-runtime, wget
 Suggests: loop-aes-utils, curlftpfs, genext2fs (>= 1.4.1), httpfs2, squashfs-tools, mtd-tools
 Description: Debian Live initramfs hook
  live-initramfs is a hook for the initramfs-tools, used to generate a initramfs
index d246a59..22c11a0 100755 (executable)
@@ -55,6 +55,42 @@ then
        echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> "${FSTAB}"
 fi
 
+if [ -z "${NOSWAP}" ]
+then
+       devices=""
+
+       for device in /dev/[hs]d[a-z][0-9]*
+       do
+               if ! [ -b "${device}" ]
+               then
+                       continue
+               fi
+
+               /lib/udev/vol_id ${device%%[0-9]*} 2>/dev/null | grep -q "^ID_FS_USAGE=raid" && continue
+
+               magic=$(/bin/dd if="${device}" bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null) || continue
+
+               if [ "${magic}" = "SWAPSPACE2" -o "${magic}" = "SWAP-SPACE" ]
+               then
+                       #log "Found ${device}"
+                       devices="${devices} ${device}"
+               fi
+       done
+
+       # Remove all auto swap entries
+       if grep -qs  "swap swap" "${FSTAB}"
+       then
+               grep -v "swap swap" "${FSTAB}" > "${FSTAB}".tmp
+               mv "${FSTAB}".tmp "${FSTAB}"
+       fi
+
+       # Add new swap entries
+       for device in ${devices}
+       do
+               echo "${device} swap swap defaults 0 0" >> "${FSTAB}"
+       done
+fi
+
 # disabled for now
 #rm -f /root/etc/rcS.d/S*checkroot.sh
 
index 59bdb4f..c4fca95 100644 (file)
@@ -327,6 +327,43 @@ find_cow_device ()
                                break
                        fi
 
+                       # Checking for a luks device
+                       if [ -e /sbin/cryptsetup ] && /sbin/cryptsetup isLuks ${devname}
+                       then
+                               while true
+                               do
+                                       load_keymap
+
+                                       echo -n "Enter passphrase for ${pers_label} on ${devname}: " >&6
+                                       read -s passphrase
+                                       echo "${passphrase}" > /tmp/passphrase
+                                       unset passphrase
+                                       exec 9</tmp/passphrase
+                                       /sbin/cryptsetup luksOpen ${devname} $(basename ${devname})
+                                       error=${?}
+                                       exec 9<&-
+                                       rm -f /tmp/passphrase
+
+                                       devname="/dev/mapper/$(basename ${devname})"
+
+                                       if [ 0 -eq ${error} ]
+                                       then
+                                               unset error
+                                               break
+                                       fi
+
+                                       echo
+                                       echo -n "There was an error decrypting ${devname} ... Retry? [Y/n] " >&6
+                                       read answer
+
+                                       if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
+                                       then
+                                               unset answer
+                                               break
+                                       fi
+                               done
+                       fi
+
                        if [ "$(/lib/udev/vol_id -l ${devname} 2>/dev/null)" = "${pers_label}" ]
                        then
                                echo "${devname}"