#!/bin/bash # Load configuration parameter source config.sh # Varidate whether script is executed as sourced or not (return 0 2>/dev/null) && sourced=1 || sourced=0 if [ $sourced -eq 0 ] ; then cat <&2 ***** ERROR : Must execute as source ***** Execute as following : source ubuntu-kaiten-yaki.sh Installation terminated. HEREDOC exit # use "exit" instead of "return", if not "sourced" execusion fi # "sourced" validation # This is the mount point of the install target. # Refered in the para-install stage export TARGETMOUNTPOINT="/target" # Distribution check if ! uname -a | grep ubuntu -i > /dev/null ; then # "Ubuntu" is not found in the OS name. echo "*******************************************************************************" uname -a cat <&2 Installation terminated. HEREDOC return fi # if YES fi # "Ubuntu" is not found in the OS name. # ******************************************************************************* # Confirmation before installation # ******************************************************************************* # Common part of the parameter confirmation source _confirmation.sh # ******************************************************************************* # Pre-install stage # ******************************************************************************* # Common part of the pre-install stage source _preinstall.sh # ******************************************************************************* # Para-install stage # ******************************************************************************* # Show common message to let the operator focus on the critical part source _parainstall_msg.sh # Ubuntu dependent message cat <> /etc/cryptsetup-initramfs/conf-hook echo "UMASK=0077" >> /etc/initramfs-tools/initramfs.conf # Prepare a key file to embed in to the ramfs. echo "...Prepair key file." mkdir /etc/luks dd if=/dev/urandom of=/etc/luks/boot_os.keyfile bs=4096 count=1 status=none chmod u=rx,go-rwx /etc/luks chmod u=r,go-rwx /etc/luks/boot_os.keyfile # Add a key to the key file. Use the passphrase in the environment variable. echo "...Add a key to the key file." printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile # Add the LUKS volume information to /etc/crypttab to decrypt by kernel. echo "...Add LUKS volume info to /etc/crypttab." echo "${CRYPTPARTNAME} UUID=$(blkid -s UUID -o value ${DEV}${CRYPTPARTITION}) /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab # Finally, update the ramfs initial image with the key file. echo "...Upadte initramfs." update-initramfs -uk all # Leave chroot HEREDOC # Unmount all echo "...Unmount all." umount -R /mnt/target # Finishing message cat <