Created
July 6, 2015 00:38
-
-
Save fsmithred/f15665561e517d8b2050 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# update-init-crypt.sh | |
set -x | |
select_device () { | |
usbdevlist=$(/usr/sbin/hwinfo --usb --short|grep "/dev/sd"|awk '{print $1}') | |
usbdevfulllist=$(/usr/sbin/hwinfo --usb --short|grep "/dev/sd"|awk '{print $0}') | |
echo -e "\n\tLIST OF USB DEVICES\n\n$usbdevfulllist\n\nSelect by number" | |
select opt in $usbdevlist ; do | |
device="$opt" | |
break | |
done | |
} | |
update_initrd () { | |
# Create /lib/live/mount/medium and/or /live | |
if ! [ -d /lib/live/mount/medium ] ; then | |
medium="no" | |
ln -s /lib/live/mount/persistence/"${device##*/}1"/ /lib/live/mount/medium | |
fi | |
#if ! [ -d /lib/live/mount/medium/live ] ; then | |
# live_dir="no" | |
# mkdir /lib/live/mount/medium/live | |
#fi | |
# if live-tools is installed, use the original update-initramfs | |
if [ -f /usr/sbin/update-initramfs.orig.initramfs-tools ] ; then | |
CRYPTSETUP=y /usr/sbin/update-initramfs.orig.initramfs-tools -u | |
else | |
CRYPTSETUP=y update-initramfs -u | |
fi | |
} | |
# Select target_dir | |
select_target () { | |
dirlist=$(ls /lib/live/mount/medium | awk '{ print $0 }') | |
echo -e "\nSelect the target directory for the updated initrd.\n" | |
select dir in $dirlist ; do | |
target_dir="$dir" | |
break | |
done | |
### if using findiso, there is no target_dir/live | |
if [ -d "/lib/live/mount/medium/${target_dir}/live" ] ; then | |
target="/lib/live/mount/medium/${target_dir}/live" | |
else | |
target="/lib/live/mount/medium/$target_dir" | |
fi | |
} | |
### The work starts here. | |
# Check for cryptsetup, check that root is running the script. | |
if ! type -p cryptsetup ; then | |
echo "cryptsetup is not installed. You can only use unencrypted persistence. | |
See the Help section on Encryption | |
" | |
exit 1 | |
fi | |
if [[ $(id -u) -ne 0 ]] ; then | |
echo -e "\n\tYou need to be root!\n" | |
exit 1 | |
fi | |
select_device | |
update_initrd | |
select_target | |
# Copy/Rename updated initrd to target_dir | |
read -p " Enter or change the name of the updated initrd: " -i initrd.crypt -e initrd_name | |
updated_initrd=$(ls -l /initrd.img | awk -F"> " '{ printf $2 }') | |
cp "$updated_initrd" ${target}/${initrd_name} | |
# add option to patch the updated initrd for user-rw-media? | |
# edit boot menu. | |
filelist=$(ls /lib/live/mount/medium/syslinux | awk '{ print $0 }') | |
echo -e "\nSelect the boot menu. (maybe live.cfg or menu.txt)\n" | |
select file in $filelist ; do | |
boot_menu="$file" | |
break | |
done | |
nano /lib/live/mount/medium/syslinux/"$boot_menu" | |
# remove symlink and/or /live dir. | |
#if [ "$live_dir" = "no" ] ; then | |
# rm -r /lib/live/mount/medium/live | |
#fi | |
if [ "$medium" = "no" ] ; then | |
rm /lib/live/mount/medium | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment