Created
November 4, 2012 16:31
-
-
Save fsmithred/4012515 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| version="Refracta Installer 9.0.6-test (20121104)" | |
| # Copyright 2011 fsmithred@gmail.com | |
| # Based on refractainstaller-8.0.3 by Dean Linkous | |
| # License: GPL-3 | |
| # This is free software with NO WARRANTY. Use at your own risk! | |
| # DESCRIPTION | |
| # This script is used for installing a live system to a hard drive. User | |
| # input is via popup windows created by zenity. It should be run from | |
| # a terminal; if it's started from a menu item or a panel launcher, it | |
| # should be run in a persistent terminal, so that progress messages can | |
| # be seen and for user input in a few places. | |
| # | |
| # There are two modes for installation - Simple or Expert | |
| # Simple Mode: | |
| # Create rsync excludes file (without prompting user) | |
| # Ask user if they have a partition ready, and if not, they can exit. | |
| # User selects partition for installation. | |
| # Summary window asks to proceed with installation. | |
| # Stuff happens without interaction. | |
| # | |
| # Expert Mode: | |
| # User selects installation options - change username, select up to three | |
| # partitions (/, /boot, /home), select filesystem type for each partition, | |
| # choose whether to encrypt partitions or not, choose whether to write | |
| # random data or zeros to partitions. | |
| # User has option to exit and use custom excludes file. | |
| # User can run partitioner inside the installer. | |
| # Summary window asks to proceed with installation. | |
| # Stuff happens with some interaction (passwords, username, edit /etc/sudoers) | |
| # | |
| # Stuff: | |
| # Cleanup (in case of previous aborted run) | |
| # Create encrypted volumes *(Expert mode only) | |
| # Write random data or zeros * | |
| # Mount partition(s) and create filesystem(s) | |
| # Copy system with rsync | |
| # Create swapfile | |
| # Copy update-initramfs | |
| # Set up fstab | |
| # Set up crypttab * | |
| # Install bootloader | |
| # Cleanup | |
| # Change username and passwords, edit /etc/sudoers * | |
| # Re-enable update-db and freshclam, disable ssh root login. | |
| # If you want to change any defaults, change them in the configfile. | |
| # Default is /etc/refractainstaller.conf | |
| # If you want to use a different config file for testing, change this | |
| # variable. Normally, users should not edit anything in this script. | |
| configfile="/etc/refractainstaller.conf" | |
| show_help () { | |
| printf "$help_text" | |
| exit 0 | |
| } | |
| help_text=" | |
| Usage: $0 [option] | |
| Run refractainstaller-gui from a terminal with no options | |
| or select Refracta Installer from the System menu to install | |
| a running live-CD or live-usb-hdd to a hard drive. | |
| valid options: | |
| -h, --help show this help text | |
| -v, --version display the version information | |
| " | |
| while [[ $1 == -* ]]; do | |
| case "$1" in | |
| -h|--help) | |
| show_help ;; | |
| -v|--version) | |
| printf "\n$version\n\n" | |
| exit 0 ;; | |
| *) | |
| printf "\t invalid option: $1 \n\n" | |
| printf "\t Try: $0 -h for full help. \n\n" | |
| exit 1 ;; | |
| esac | |
| done | |
| # Check that xserver is running and user is root. | |
| [[ $DISPLAY ]] || { echo "There is no xserver running. Exiting..." ; exit 1 ; } | |
| if [[ $(id -u) -ne 0 ]] ; then | |
| zenity --error --text="You need to be root!" | |
| exit 1 | |
| fi | |
| refractainstaller_configuration () { | |
| if [[ -f $configfile ]]; then | |
| source $configfile | |
| else | |
| zenity --info --title="Warning" --text="Config file $configfile is missing | |
| Proceeding with default settings..." | |
| fi | |
| # Check for values in $configfile and use them. | |
| # If any are unset, these defaults will be used. | |
| error_log=${error_log:="/var/log/refractainstaller_error.log"} | |
| rsync_excludes=${rsync_excludes:="/usr/lib/refractainstaller/installer_exclude.list"} | |
| home_boot_excludes=${home_boot_excludes:="/usr/lib/refractainstaller/home_boot_exclude.list"} | |
| swapfile_blocksize=${swapfile_blocksize:="1024"} | |
| swapfile_count=${swapfile_count:="262144"} | |
| pmount_fixed=${pmount_fixed:="no"} | |
| enable_updatedb=${enable_updatedb:="yes"} | |
| enable_freshclam=${enable_freshclam:="yes"} | |
| root_ssh=${root_ssh:="no"} | |
| } | |
| refractainstaller_configuration | |
| # Record errors in a logfile. | |
| exec 2>"$error_log" | |
| # function to exit the script if there are errors | |
| check_exit () { | |
| if [[ $? -ne 0 ]] ; then | |
| zenity --error --text="Exit due to error: $? | |
| See $error_log for details." & | |
| exit 1 | |
| fi | |
| } | |
| copy_excludes () { | |
| cat > "$rsync_excludes" <<EOF | |
| # It is safe to delete this file after installation. | |
| - /dev/* | |
| - /cdrom/* | |
| - /media/* | |
| - /target | |
| - /swapfile | |
| - /mnt/* | |
| - /sys/* | |
| - /proc/* | |
| - /tmp/* | |
| - /live | |
| - /boot/grub/grub.cfg | |
| - /boot/grub/menu.lst | |
| - /boot/grub/device.map | |
| - /etc/udev/rules.d/70-persistent-cd.rules | |
| - /etc/udev/rules.d/70-persistent-net.rules | |
| - /etc/fstab | |
| - /etc/mtab | |
| - /home/snapshot/ | |
| - /home/*/.gvfs | |
| EOF | |
| check_exit | |
| chmod 666 "$rsync_excludes" | |
| } | |
| # Ask if user wants Simple Install or Expert Install | |
| install=$(zenity --list --title="Installation Mode" \ | |
| --text="Choose whether you want to do a simple install or expert install." \ | |
| --radiolist --column "Choose" --column "Num" --column "Option" \ | |
| --width=520 --height=220 \ | |
| FALSE 01 "Simple installation (one partition, few questions.)" \ | |
| FALSE 02 "Expert install (more options)" \ | |
| FALSE 03 "Exit - Get me out of here!") | |
| if $(echo $install | grep -q 01); then | |
| install="simple" | |
| fi | |
| if $(echo $install | grep -q 02); then | |
| install="expert" | |
| fi | |
| if $(echo $install | grep -q 03); then | |
| echo "Bye!" | |
| exit 0 | |
| fi | |
| echo "$install" | |
| # Check that rsync excludes file exists, or create one. | |
| if [[ $install = "expert" ]]; then | |
| if ! [[ -f $rsync_excludes ]] ; then | |
| zenity --question --ok-label=Continue --cancel-label=Exit \ | |
| --text="There is no rsync excludes file, or its name does not match what this script expects. You should let the script create one, or if you have a custom excludes file, and you know what you're doing, you can exit the script and edit the rsync_excludes variable at the top so that it matches the name and path of your custom file. | |
| If you have any other drives or partitions mounted that you don't want to be copied, unmount them or edit the excludes file to list them." | |
| if [[ $? = 0 ]] ; then | |
| rsync_excludes="$(pwd)/installer_exclude.list" | |
| copy_excludes | |
| else | |
| exit 0 | |
| fi | |
| fi | |
| else | |
| rsync_excludes="$(pwd)/installer_exclude.list" | |
| copy_excludes | |
| fi | |
| # Select expert installation options | |
| if [[ $install = "expert" ]]; then | |
| opts=$(zenity --list --title="Installation Options" \ | |
| --text="Check the options you want for the installation" \ | |
| --checklist --column "Choose" --column "Num" --column "Option" \ | |
| --width=590 --height=400 \ | |
| FALSE 01 "Change user name" \ | |
| FALSE 02 "Create a separate /home partition" \ | |
| FALSE 03 "Create a separate /boot partition" \ | |
| FALSE 04 "Encrypt the root filesystem (separate /boot required)" \ | |
| FALSE 05 "Encrypt the /home partition (separate /home required)" \ | |
| FALSE 06 "Write random data to encrypted partitions (more secure)" \ | |
| FALSE 07 "Write zeroes to all partitions (to erase previous data)" \ | |
| FALSE 08 "Do not install bootloader. I'll handle it myself." \ | |
| FALSE 09 "Use UUID in /etc/fstab. (Useful if drive order changes.)" \ | |
| FALSE 10 "Use filesystem labels (disk labels) in /etc/fstab." \ | |
| FALSE 11 "Change hostname." \ | |
| FALSE 12 "Disable automatic login to desktop." \ | |
| FALSE 13 "Disable automatic login to console. (Use stock Debian inittab" \ | |
| FALSE xx "Exit the installation now.") | |
| echo "$opts" | |
| fi | |
| if $(echo $opts | grep -q 01); then | |
| change_user="yes" | |
| fi | |
| if $(echo $opts | grep -q 02); then | |
| sep_home="yes" | |
| fi | |
| if $(echo $opts | grep -q 03); then | |
| sep_boot="yes" | |
| fi | |
| if $(echo $opts | grep -q 04); then | |
| encrypt_os="yes" | |
| fi | |
| if $(echo $opts | grep -q 05); then | |
| encrypt_home="yes" | |
| fi | |
| if $(echo $opts | grep -q 06); then | |
| write_random="yes" | |
| fi | |
| if $(echo $opts | grep -q 07); then | |
| write_zero="yes" | |
| fi | |
| if $(echo $opts | grep -q 08); then | |
| bootloader="no" | |
| else | |
| bootloader="yes" | |
| fi | |
| if $(echo $opts | grep -q 09); then | |
| if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then | |
| uuid_message="--> UUIDs in fstab won't work with encrypted filesystems and | |
| will not be used. Edit fstab manually after the installation." | |
| else | |
| use_uuid="yes" | |
| fi | |
| fi | |
| if $(echo $opts |grep -q 10); then | |
| if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then | |
| disklabel_message="--> Disk labels in fstab won't work with encrypted filesystems and | |
| will not be used. Edit fstab manually after the installation." | |
| elif [[ $use_uuid = "yes" ]]; then | |
| disklabel_message="--> This script can't do both UUIDs and disk labels for fstab. | |
| UUIDs will be used, and you can add disk labels manually, after the install." | |
| else | |
| use_labels="yes" | |
| disklabel_message="You will be given a chance to create disk labels." | |
| fi | |
| fi | |
| if $(echo $opts | grep -q 11); then | |
| change_hostname="yes" | |
| fi | |
| if $(echo $opts | grep -q 12); then | |
| disable_auto_desktop="yes" | |
| fi | |
| if $(echo $opts | grep -q 13); then | |
| disable_auto_console="yes" | |
| fi | |
| if $(echo $opts | grep -q xx); then | |
| exit 0 | |
| fi | |
| if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then | |
| # test for cryptsetup | |
| if ! [[ -f /sbin/cryptsetup ]] ; then | |
| zenity --question --title=Error \ | |
| --ok-label="Proceed without encrypting partitions" \ | |
| --cancel-label=Exit --text="You need to install cryptsetup and run the command, 'sudo modprobe dm-mod' before you can use encryption." | |
| if [[ $? = 0 ]] ; then | |
| encrypt_os="no" | |
| encrypt_home="no" | |
| else | |
| exit 1 | |
| fi | |
| fi | |
| # end test for cryptsetup | |
| fi | |
| ## Partition a disk ##### Simple install now does get to partition the disk - uncomment the conditional below to change it back. | |
| #if [[ $install = "expert" ]]; then | |
| partitioner=$(zenity --list --title=Partitioning --ok-label=Yes --cancel-label=No \ | |
| --text="You need to have at least one partition ready for the installation, plus one for | |
| each separate partition that you chose." \ | |
| --radiolist --column "Choose" --column "Option" \ | |
| --width=420 --height=240 \ | |
| FALSE "Run GParted partitioner now." \ | |
| FALSE "Run cfdisk partitioner in a terminal." \ | |
| FALSE "No thanks, I already have a partition prepared. Continue." \ | |
| FALSE "I'd like to exit the script now.") | |
| if $(echo $partitioner | grep -q GParted) ; then | |
| gparted | |
| fi | |
| if $(echo $partitioner | grep -q cfdisk) ; then | |
| xterm -fa monaco -fs 12 -geometry 90x20+0+0 -hold -e cfdisk | |
| fi | |
| if $(echo $partitioner | grep -q exit) ; then | |
| exit 0 | |
| fi | |
| #elif [[ $install = "simple" ]]; then | |
| # zenity --question --title=Partitioning --ok-label=Proceed --cancel-label=Exit the installer \ | |
| # --text="You need to have a partition ready for the installation. If you know where you're going to install the system, then proceed. Otherwise, you should exit. | |
| # | |
| #You will be asked which partition to use. The installer will show you a summary of what will be done, and it will give you a chance to exit or proceed with the installation. If you proceed at that point, the partition you chose for installation will be formatted, and any data on it will be erased." | |
| # if ! [[ $? = 0 ]]; then | |
| # exit 0 | |
| # fi | |
| #fi | |
| # # test to make sure there's a separate /boot partition | |
| if [[ $sep_boot = "no" ]]; then | |
| if [[ $encrypt_os = "yes" ]]; then | |
| zenity --question --title=Error \ | |
| --ok-label="Proceed without encrypting partition" \ | |
| --cancel-label=Exit --text="You MUST have a separate, unencrypted /boot partition if you intend to boot an encrypted operating system. You can proceed without encrypting the root filesystem, or you can exit and start over." | |
| if [[ $? = 0 ]] ; then | |
| encrypt_os="no" | |
| else | |
| exit 1 | |
| fi | |
| fi | |
| fi | |
| # Find hard drives, and choose one for grub | |
| choose_grub () { | |
| grub_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z]" \ | |
| | sort | awk '{print "FALSE\n" $0 }' \ | |
| | zenity --list --title=Bootloader --text="Choose a location to install the bootloader, or click OK without choosing a drive to skip this." \ | |
| --radiolist --multiple --column ' ' --column 'Hard Drives' --height=200) | |
| if [[ -z $grub_dev ]] ; then | |
| zenity --question --title=Error --ok-label="Yes, I'm sure." --cancel-label="Go back" \ | |
| --text="No bootloader will be installed. You will need to do some manual configuration after the install. Are you sure you want this?" | |
| if [[ $? != 0 ]] ; then | |
| choose_grub | |
| fi | |
| elif ! [[ -b $grub_dev ]] ; then | |
| zenity --question --title=Error --ok-label=Exit --cancel-label="Go back" \ | |
| --text="Something is wrong. $grub_dev is not a block device." | |
| if [[ $? = 0 ]] ; then | |
| exit 1 | |
| else | |
| choose_grub | |
| fi | |
| fi | |
| } | |
| ### Simple install gets default grub bootloader in /dev/sda | |
| if [[ $install = "expert" ]]; then | |
| if [[ $bootloader = "yes" ]]; then | |
| choose_grub | |
| fi | |
| fi | |
| if [[ $install = "simple" ]]; then | |
| grub_dev="/dev/sda" | |
| fi | |
| # Show output of blkid for reference. | |
| xterm -fa monaco -fs 12 -geometry 90x20+0+0 -hold -e 'echo "Partition list (for reference.) You may need this later." && blkid' & | |
| # Show the partition list in a menu, and choose one for /boot | |
| choose_boot () { | |
| boot_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \ | |
| | sort | awk '{print "FALSE\n" $0 }' \ | |
| | zenity --list --title="/boot partition" --text="Select a partition for /boot." \ | |
| --radiolist --multiple --column ' ' --column 'Partitions' --height=380 --width=150) | |
| echo "boot_dev is $boot_dev" | |
| } | |
| if [[ $sep_boot = "yes" ]]; then | |
| choose_boot | |
| fi | |
| # Choose filesystem type for /boot | |
| choose_fs_boot () { | |
| if [[ -n $boot_dev ]]; then | |
| fs_type_boot=$(zenity --list --title="/boot filesystem" --text="What type of filesystem would you like on $boot_dev?" \ | |
| --radiolist --column "Choose" --column "Format" --height=200\ | |
| FALSE "ext2" \ | |
| FALSE "ext3" \ | |
| FALSE "ext4") | |
| fi | |
| if [[ -z $fs_type_boot ]]; then | |
| zenity --question --title=Error --ok-label="Go back" --cancel-label=Exit \ | |
| --text="You must choose a file system type for /boot" | |
| if [[ $? = 0 ]]; then | |
| choose_fs_boot | |
| else | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| if [[ -n $boot_dev ]]; then | |
| choose_fs_boot | |
| fi | |
| # Show the partition list in a menu, and choose one for the OS | |
| choose_root () { | |
| install_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \ | |
| | sort | awk '{print "FALSE\n" $0 }' \ | |
| | zenity --list --title="Root Partition" --text="Choose a partition to use for the installation of the operating system." \ | |
| --radiolist --multiple --column ' ' --column 'Partitions' --height 380 --width 150) | |
| if [[ -z $install_dev ]] ; then | |
| zenity --question --title=Error --ok-label="Go back" --cancel-label="Exit" \ | |
| --text="Nothing was selected. You must select a partition for the installation. What would you like to do?" | |
| if [[ $? = 0 ]] ; then | |
| choose_root | |
| else | |
| exit 1 | |
| fi | |
| elif ! [[ -b $install_dev ]] ; then | |
| zenity --question --title=Error --ok-label="Go back" --cancel-label="Exit" \ | |
| --text=" Something is wrong. Maybe you checked | |
| more than one box. You said you want to install | |
| the system to $install_dev" | |
| if [[ $? = 0 ]] ; then | |
| choose_root | |
| else | |
| exit 1 | |
| fi | |
| elif | |
| [[ $install_dev = $boot_dev ]] ; then | |
| zenity --info --title=Error --text="You chose the same partition for the operating system as the one for /boot. Try again." | |
| choose_root | |
| fi | |
| } | |
| choose_root | |
| # Choose filesystem type for OS. | |
| choose_fs_os () { | |
| fs_type_os=$(zenity --list --title="Root Filesystem" --text="What type of filesystem would you like on $install_dev?" \ | |
| --radiolist --column "Choose" --column "Format" --height=200\ | |
| FALSE "ext2" \ | |
| FALSE "ext3" \ | |
| FALSE "ext4") | |
| if [[ -z $fs_type_os ]]; then | |
| zenity --question --ok-label="Go back" --cancel-label=Exit \ | |
| --text="You must choose a file system type | |
| for the operating system" | |
| if [[ $? = 0 ]]; then | |
| choose_fs_os | |
| else | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| ### Simple install gets default ext4 filesystem | |
| if [[ $install = "expert" ]]; then | |
| choose_fs_os | |
| else | |
| fs_type_os="ext4" | |
| fi | |
| # Show the partition list in a menu, and choose one for /home | |
| choose_home () { | |
| home_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \ | |
| | sort | awk '{print "FALSE\n" $0 }' \ | |
| | zenity --list --title="/home partition" --text="Select a partition for /home" \ | |
| --radiolist --multiple --column ' ' --column 'Partitions' --height=380 --width=150) | |
| if [[ -n $home_dev ]] ; then | |
| if ! [[ -b $home_dev ]] ; then | |
| zenity --question --ok-label="Go back" --cancel-label=Exit \ | |
| --text=" Something is wrong. Maybe you checked | |
| more than one box. You said you want to install | |
| the system to $home_dev" | |
| if [[ $? = 0 ]] ; then | |
| choose_home | |
| else | |
| exit 1 | |
| fi | |
| elif | |
| [[ $install_dev = $home_dev ]] ; then | |
| zenity --info --title=Error --text="You chose the same partition for /home as the one for the operating system. If you don't want a separate /home partition, then click OK without selecting one." | |
| choose_home | |
| elif | |
| [[ $boot_dev = $home_dev ]] ; then | |
| zenity --info --title=Error --text="You chose the same partition for /home as the one for /boot. Try again." | |
| choose_home | |
| fi | |
| fi | |
| } | |
| if [[ $sep_home = "yes" ]]; then | |
| choose_home | |
| fi | |
| # Choose filesystem type for /home | |
| choose_fs_home () { | |
| if [[ -n $home_dev ]]; then | |
| fs_type_home=$(zenity --list --title="/home filesystem" --text="What type of filesystem would you like on $home_dev?" \ | |
| --radiolist --column "Choose" --column "Format" --height=200\ | |
| FALSE "ext2" \ | |
| FALSE "ext3" \ | |
| FALSE "ext4") | |
| fi | |
| if [[ -z $fs_type_home ]]; then | |
| zenity --question --title=Error --ok-label="Go back" --cancel-label=Exit \ | |
| --text="You must choose a file system type for /home" | |
| if [[ $? = 0 ]]; then | |
| choose_fs_home | |
| else | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| if [[ -n $home_dev ]]; then | |
| choose_fs_home | |
| fi | |
| # Enter new hostname (or use the old hostname as the new one) | |
| if [[ $change_hostname = "yes" ]]; then | |
| new_hostname=$(zenity --entry --title="Change hostname" \ | |
| --text="Enter new hostname for installed system." \ | |
| --entry-text="$HOSTNAME") | |
| fi | |
| # In case null was entered above as hostname, then set it to $HOSTNAME | |
| new_hostname=${new_hostname:="$HOSTNAME"} | |
| # Show a summary of what will be done | |
| if [[ $change_user = "yes" ]]; then | |
| user_message="--> User name will be changed." | |
| fi | |
| if [[ -z $grub_dev ]] ; then | |
| grub_dev_message="--> Bootloader will not be installed." | |
| else | |
| grub_dev_message="--> Bootloader will be installed in $grub_dev" | |
| fi | |
| if [[ $encrypt_os = yes ]] ; then | |
| os_enc_message=", and will be encrypted." | |
| fi | |
| if [[ -z $home_dev ]] ; then | |
| home_dev_message="--> /home will not be on a separate partition." | |
| else | |
| home_dev_message="--> /home will be installed on $home_dev and formatted as $fs_type_home" | |
| fi | |
| if [[ -n $home_dev ]] && [[ $encrypt_home = yes ]] ; then | |
| home_enc_message=", and will be encrypted." | |
| fi | |
| if [[ -n $boot_dev ]] ; then | |
| boot_dev_message="--> /boot will be installed on $boot_dev and formatted as $fs_type_boot." | |
| fi | |
| if [[ $encrypt_os = yes ]] || [[ $encrypt_home = yes ]] ; then | |
| proceed_message="*** IF YOU PROCEED, YOU WILL NEED TO RESPOND TO SOME QUESTIONS IN THE TERMINAL. Be prepared to create passphrases for any encrypted partitions (several times each.) When you see the progress bar come up, you can take a break." | |
| fi | |
| if [[ $disable_auto_desktop = "yes" ]]; then | |
| desktop_message="Desktop autologin will be disabled." | |
| fi | |
| if [[ $disable_auto_console = "yes" ]]; then | |
| console_message="Console autologin will be disabled." | |
| fi | |
| zenity --question --title=Summary --ok-label="Proceed with the installation." --cancel-label="Exit" \ | |
| --text="Here is a summary of what will be done. THIS IS YOUR LAST CHANCE TO EXIT before any changes are made to the disk. | |
| $grub_dev_message | |
| --> Operating system will be installed on $install_dev and formatted as $fs_type_os$os_enc_message | |
| $home_dev_message$home_enc_message | |
| $boot_dev_message | |
| $user_message | |
| $desktop_message | |
| $console_message | |
| $uuid_message$disklabel_message | |
| Hostname: $new_hostname | |
| $proceed_message" | |
| if [[ $? != 0 ]] ; then | |
| exit 0 | |
| fi | |
| # Actual installation begins here | |
| # Unmount or close anything that might need unmounting or closing | |
| cleanup () { | |
| echo -e "\n Cleaning up...\n" | |
| if $(df | grep -q /target/proc/) ; then | |
| umount /target/proc/ | |
| fi | |
| if $(df | grep -q /target/dev/) ; then | |
| umount /target/dev/ | |
| fi | |
| if $(df | grep -q /target/sys/) ; then | |
| umount /target/sys/ | |
| fi | |
| # grep gives an error if $boot_dev is null | |
| if $(df | grep -q $boot_dev) ; then | |
| umount $boot_dev | |
| fi | |
| if $(df | grep -q /target_boot) ; then | |
| umount -l /target_boot/ | |
| fi | |
| if $(df | grep -q /target_home) ; then | |
| umount -l /target_home/ | |
| fi | |
| # grep gives an error if $home is null | |
| if $(df | grep -q $home_dev) ; then | |
| umount $home_dev | |
| fi | |
| if $(df | grep -q "\/dev\/mapper\/home-fs") ; then | |
| umount /dev/mapper/home-fs | |
| fi | |
| if [[ -h /dev/mapper/home-fs ]] ; then | |
| cryptsetup luksClose home-fs | |
| fi | |
| if $(df | grep -q /target) ; then | |
| umount -l /target/ | |
| fi | |
| if $(df | grep -q $install_dev) ; then | |
| umount $install_dev | |
| fi | |
| if $(df | grep "\/dev\/mapper\/root-fs") ; then | |
| umount /dev/mapper/root-fs | |
| fi | |
| if [[ -h /dev/mapper/root-fs ]] ; then | |
| cryptsetup luksClose /dev/mapper/root-fs | |
| fi | |
| # These next ones might be unnecessary | |
| if [[ -d /target ]] ; then | |
| rm -rf /target | |
| fi | |
| if [[ -d /target_home ]] ; then | |
| rm -rf /target_home | |
| fi | |
| if [[ -d /target_boot ]] ; then | |
| rm -rf /target_boot | |
| fi | |
| } | |
| cleanup | |
| # Write random data to OS partition | |
| if [[ $write_random = "yes" ]]; then | |
| if [[ $encrypt_os = "yes" ]]; then | |
| # # Redirect stderr so we can see the output of dd | |
| echo " | |
| Writing random data to $install_dev | |
| " | |
| exec 2>&1 | |
| dd if=/dev/urandom of="$install_dev" | |
| # # Resume logging errors in file | |
| exec 2>>"$error_log" | |
| else | |
| echo " | |
| $install_dev is not to be encrypted; skipping random data write!!! | |
| " | |
| fi | |
| fi | |
| # Write random data to /home partition | |
| if [[ $write_random = "yes" ]]; then | |
| if [[ $encrypt_home = "yes" ]]; then | |
| # # Redirect stderr so we can see the output of dd | |
| echo " | |
| Writing random data to $home_dev | |
| " | |
| exec 2>&1 | |
| dd if=/dev/zero of="$home_dev" | |
| # # Resume logging errors in file | |
| exec 2>>"$error_log" | |
| else | |
| echo " | |
| $home_dev is not to be encrypted; skipping random data write!!! | |
| " | |
| fi | |
| fi | |
| # Write zeros to partitions | |
| if [[ $write_zero = "yes" ]]; then | |
| echo " | |
| Writing zeros to erase old data on $install_dev | |
| " | |
| # # Redirect stderr so we can see the output of dd | |
| exec 2>&1 | |
| dd if=/dev/urandom of="$install_dev" | |
| if [[ $sep_home = "yes" ]]; then | |
| echo " | |
| Writing zeros to erase old data on $home_dev | |
| " | |
| dd if=/dev/zero of="$home_dev" | |
| fi | |
| if [[ $sep_boot = "yes" ]]; then | |
| echo " | |
| Writing zeros to erase old data on $boot_dev | |
| " | |
| dd if=/dev/zero of="$boot_dev" | |
| fi | |
| # # Resume logging errors in file | |
| exec 2>>"$error_log" | |
| fi | |
| # make mount point, format, adjust reserve and mount | |
| # install_dev must maintain the device name for cryptsetup | |
| # install_part will be either device name or /dev/mapper name as needed. | |
| echo -e "\n Creating filesystem on $install_dev...\n" | |
| mkdir /target ; check_exit | |
| if [[ $encrypt_os = yes ]] ; then | |
| echo " You will need to create a passphrase." | |
| cryptsetup luksFormat "$install_dev" ; check_exit | |
| echo "Encrypted partition created. Opening it..." | |
| cryptsetup luksOpen "$install_dev" root-fs ; check_exit | |
| install_part="/dev/mapper/root-fs" | |
| else | |
| install_part="$install_dev" | |
| fi | |
| mke2fs -t $fs_type_os "$install_part" ; check_exit | |
| tune2fs -r 10000 "$install_part" ; check_exit | |
| mount "$install_part" /target ; check_exit | |
| # make mount point for separate home if needed | |
| # and add /home/* to the excludes list if it's not already there | |
| if [[ -n $home_dev ]] ; then | |
| echo " | |
| Creating filesystem on $home_dev... | |
| " | |
| mkdir /target_home ; check_exit | |
| if [[ $encrypt_home = yes ]]; then | |
| echo " | |
| You will need to create a passphrase. | |
| " | |
| cryptsetup luksFormat "$home_dev" | |
| check_exit | |
| echo "Encrypted partition created. Opening it..." | |
| cryptsetup luksOpen "$home_dev" home-fs | |
| check_exit | |
| home_part="/dev/mapper/home-fs" | |
| else | |
| home_part=$home_dev | |
| fi | |
| mke2fs -t $fs_type_home "$home_part" ; check_exit | |
| tune2fs -r 10000 "$home_part" ; check_exit | |
| mount "$home_part" /target_home ; check_exit | |
| if ! $(grep -q "\/home\/\*" "$rsync_excludes"); then | |
| echo "- /home/*" >> "$rsync_excludes" | |
| fi | |
| fi | |
| # make mount point for separate /boot if needed | |
| # and add /boot/* to the excludes list if it's not already there | |
| # allow default for reserved blocks (don't need tune2fs here) | |
| if [[ -n $boot_dev ]] ; then | |
| mkdir /target_boot ; check_exit | |
| mke2fs -t $fs_type_boot $boot_dev ; check_exit | |
| mount $boot_dev /target_boot | |
| if ! $(grep -q "\/boot\/\*" "$rsync_excludes"); then | |
| echo "- /boot/*" >> "$rsync_excludes" | |
| fi | |
| fi | |
| # make sure there's not a leftover entry in excludes list for /home/* | |
| # or /boot/* from a previous run if not needed this time. | |
| if [[ -z $boot_dev ]] ; then | |
| sed -i 's:- /boot/\*::' "$rsync_excludes" | |
| fi | |
| if [[ -z $home_dev ]] ; then | |
| sed -i 's:- /home/\*::' "$rsync_excludes" | |
| fi | |
| # copy everything over except the things listed in the exclude list | |
| echo -e "\n Copying system to new partition.\n Wait...\n" | |
| rsync -av / /target/ --exclude-from="$rsync_excludes" | \ | |
| tee >(zenity --progress --pulsate --auto-close \ | |
| --text="Copying system to new partition.") | |
| check_exit | |
| # copy separate /home if needed | |
| echo -e "\n Copying home folders to new partition.\n Wait...\n" | |
| if ! [[ -z $home_dev ]] ; then | |
| rsync -av /home/ /target_home/ --exclude-from="$home_boot_excludes" | \ | |
| tee >(zenity --progress --pulsate --auto-close \ | |
| --text="Copying home folders to new partition.") | |
| check_exit | |
| fi | |
| # copy separate /boot if needed | |
| if [[ -n $boot_dev ]] ; then | |
| echo -e "\n Copying files to boot partitions...\n" | |
| rsync -av /boot/ /target_boot/ --exclude-from="$home_boot_excludes" ; check_exit | \ | |
| tee >(zenity --progress --pulsate --auto-close \ | |
| --text="Copying files to boot partition.") | |
| check_exit | |
| fi | |
| # create swap | |
| echo -e "\n Making a swap file.\n Wait...\n" | |
| dd if=/dev/zero of=/target/swapfile bs="$swapfile_blocksize" count="$swapfile_count" | \ | |
| tee >(zenity --progress --pulsate --auto-close \ | |
| --text="Making a swap file...") | |
| check_exit | |
| mkswap /target/swapfile ; check_exit | |
| # copy the real update-initramfs back in place | |
| echo -e "\n Copying update-initramfs...\n" | |
| if [[ -f /target/usr/sbin/update-initramfs.distrib ]] ; then | |
| cp /target/usr/sbin/update-initramfs.distrib /target/usr/sbin/update-initramfs | |
| fi | |
| if [[ -f /target/usr/sbin/update-initramfs.debian ]] ; then | |
| cp /target/usr/sbin/update-initramfs.debian /target/usr/sbin/update-initramfs | |
| fi | |
| # Disallow mounting of all fixed drives with pmount | |
| if [[ -f /target/etc/pmount.allow ]] ; then | |
| if [[ $pmount_fixed = "no" ]] ; then | |
| sed -i 's:/dev/sd\[a-z\]:#/dev/sd\[a-z\]:' /target/etc/pmount.allow | |
| fi | |
| fi | |
| # Re-enable updatedb if it was disabled by snapshot | |
| if [[ -e /target/usr/bin/updatedb.mlocate ]] ; then | |
| if [[ $enable_updatedb = "yes" ]] ; then | |
| chmod +x /target/usr/bin/updatedb.mlocate | |
| fi | |
| fi | |
| # Disable autologin to desktop | |
| if [[ $disable_auto_desktop = "yes" ]]; then | |
| #gdm | |
| if [[ -f /target/etc/gdm/gdm.conf ]]; then | |
| sed -i 's/^AutomaticLogin/#AutomaticLogin/' /target/etc/gdm/gdm.conf | |
| fi | |
| #gdm3 | |
| if [[ -f /target/etc/gdm3/daemon.conf ]]; then | |
| sed -i 's/^AutomaticLogin/#AutomaticLogin/' /target/etc/gdm3/daemon.conf | |
| fi | |
| #lightdm | |
| if [[ -f /target/etc/lightdm/lightdm.conf ]]; then | |
| sed -i 's/^autologin/#autologin/g' /target/etc/lightdm/lightdm.conf | |
| fi | |
| #kdm | |
| if [ -f /target/etc/default/kdm.d/live-autologin ]; then | |
| rm -f /target/etc/default/kdm.d/live-autologin | |
| fi | |
| if [ -f /target/etc/kde3/kdm/kdmrc ]; then | |
| sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/kde3/kdm/kdmrc | |
| sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/kde3/kdm/kdmrc | |
| fi | |
| if [ -f /target/etc/kde4/kdm/kdmrc ]; then | |
| sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/kde4/kdm/kdmrc | |
| sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/kde4/kdm/kdmrc | |
| fi | |
| #trinity | |
| if [[ -f /target/etc/default/kdm-trinity.d/live-autologin ]]; then | |
| sed -i 's/^AUTOLOGIN/#AUTOLOGIN/g' /target/etc/default/kdm-trinity.d/live-autologin | |
| fi | |
| if [ -f /target/etc/trinity/kdm/kdmrc ]; then | |
| sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/trinity/kdm/kdmrc | |
| sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/trinity/kdm/kdmrc | |
| fi | |
| fi | |
| # Disable console autologin | |
| if [[ $disable_auto_console = "yes" ]]; then | |
| if grep -q "respawn:/bin/login -f" /target/etc/inittab ; then | |
| mv /target/etc/inittab /target/etc/inittab.console_autologin | |
| cp /usr/lib/refractainstaller/inittab.debian /target/etc/inittab | |
| fi | |
| fi | |
| # Change hostname | |
| if ! [[ $new_hostname = $HOSTNAME ]]; then | |
| sed -i "s/$HOSTNAME/$new_hostname/" /target/etc/hostname | |
| sed -i "s/$HOSTNAME/$new_hostname/g" /target/etc/hosts | |
| fi | |
| # setup fstab | |
| # add entry for root filesystem | |
| if [[ $use_uuid = yes ]]; then | |
| install_part="$(blkid -s UUID $install_dev | awk '{ print $2 }')" | |
| fi | |
| if [[ $use_labels = yes ]]; then | |
| rootfslabel=$(zenity --entry --title="Filesystem Label" --text="Enter a disk label for $install_dev") | |
| e2label $install_dev $rootfslabel | |
| install_part="LABEL=$rootfslabel" | |
| fi | |
| echo -e "\n Creating /etc/fstab...\n" | |
| echo -e "proc\t\t/proc\tproc\tdefaults\t0\t0 | |
| /swapfile\tswap\tswap\tdefaults\t0\t0 | |
| $install_part\t/\t$fs_type_os\tdefaults,noatime\t0\t1" >> /target/etc/fstab | |
| check_exit | |
| # add entry for /home to fstab if needed | |
| if ! [[ -z $home_dev ]] ; then | |
| if [[ $use_uuid = yes ]]; then | |
| home_part="$(blkid -s UUID $home_dev | awk '{ print $2 }')" | |
| fi | |
| if [[ $use_labels = yes ]]; then | |
| homefslabel=$(zenity --entry --title="Filesystem Label" --text="Enter a disk label for $home_dev") | |
| e2label $home_dev $homefslabel | |
| home_part="LABEL=$homefslabel" | |
| fi | |
| echo -e "\n Adding /home entry to fstab...\n" | |
| echo -e "$home_part\t/home\t$fs_type_home\tdefaults,noatime\t0\t2" >> /target/etc/fstab | |
| check_exit | |
| fi | |
| # add entry for /boot to fstab if needed | |
| if [[ -n $boot_dev ]] ; then | |
| if [[ $use_uuid = yes ]]; then | |
| boot_part="$(blkid -s UUID $boot_dev | awk '{ print $2 }')" | |
| else | |
| boot_part="$boot_dev" | |
| fi | |
| echo -e "\n Adding /boot entry to fstab...\n" | |
| echo -e "$boot_part\t/boot\t$fs_type_boot\tdefaults,noatime,\t0\t2" >> /target/etc/fstab | |
| check_exit | |
| fi | |
| # Add entry for root filesystem to crypttab if needed | |
| if [[ $encrypt_os = yes ]] ; then | |
| echo -e "\n Adding $install_part entry to crypttab...\n" | |
| echo -e "root-fs\t\t$install_dev\t\tnone\t\tluks" >> /target/etc/crypttab | |
| fi | |
| # Add entry for /home to crypttab if needed | |
| if [[ $encrypt_home = yes ]] ; then | |
| echo -e "\n Adding $home_part entry to crypttab...\n" | |
| echo -e "home-fs\t\t$home_dev\t\tnone\t\tluks" >> /target/etc/crypttab | |
| fi | |
| # mount stuff so grub will behave (so chroot will work) | |
| echo -e "\n Mounting tmpfs and proc...\n" | |
| mount -t tmpfs --bind /dev/ /target/dev/ ; check_exit | |
| mount -t proc --bind /proc/ /target/proc/ ; check_exit | |
| mount -t sysfs --bind /sys/ /target/sys/ ; check_exit | |
| # Re-enable freshclam if it was disabled by snapshot ##### This ain't perfect, but it works! | |
| if type -p freshclam ; then | |
| if [[ $enable_freshclam = "yes" ]] ; then | |
| if ! [[ -h /target/etc/rc2.d/S02clamav-freshclam ]] ; then | |
| chroot /target update-rc.d clamav-freshclam defaults | |
| fi | |
| fi | |
| fi | |
| # Disable root login through ssh for the installed system | |
| if [[ -f /etc/ssh/sshd_config ]] ; then | |
| if [[ $root_ssh = "no" ]] ; then | |
| sed -i~ 's/PermitRootLogin yes/PermitRootLogin no/' /target/etc/ssh/sshd_config | |
| fi | |
| fi | |
| # Setup GRUB | |
| # If /boot is separate partition, need to mount it in chroot for grub | |
| if [[ -n $boot_dev ]] ; then | |
| chroot /target mount $boot_dev /boot | |
| fi | |
| if [[ -n $grub_dev ]]; then | |
| echo -e "\n Installing the boot loader...\n" | |
| echo -e "\n Installing the boot loader...\n" >> "$error_log" | |
| chroot /target grub-install $grub_dev >> "$error_log" ; check_exit | |
| fi | |
| # Run update-initramfs to include dm-mod if using encryption | |
| if [[ $encrypt_os = yes ]] || [[ $encrypt_home = yes ]] ; then | |
| chroot /target update-initramfs -u | |
| fi | |
| if [[ -n $grub_dev ]]; then | |
| chroot /target update-grub ; check_exit | |
| fi | |
| # INSTALLATION FINISHED - BEGIN CHANGE USERNAME | |
| # Need to mount the target home partition under the target root partition | |
| # so the commands can find it (for changing user configs gksu) | |
| if [[ $sep_home = "yes" ]]; then | |
| mount $home_part /target/home | |
| fi | |
| # Change the username ### Change PRIMARY user's name - define $oldname | |
| # even if not changing name, and use it for gksu below ################################# | |
| if [[ $change_user = "yes" ]]; then | |
| oldname=$(awk -F: '/1000:1000/ { print $1 }' /target/etc/passwd) | |
| newname=$(zenity --entry --title="Change login name" --text="The primary user's current login name is $oldname. | |
| Enter the new login name you want to use.") | |
| echo "New user name is $newname" | |
| chroot /target usermod -l $newname $oldname ; check_exit | |
| chroot /target groupmod -n $newname $oldname ; check_exit | |
| chroot /target usermod -d /home/$newname -m $newname ; check_exit | |
| for i in $(grep -r "/home/$oldname" /target/home/$newname/.config | awk -F":" '{ print $1 }'); do | |
| sed -i "s/\/home\/$oldname/\/home\/$newname/g" "$i" | |
| done | |
| for i in $(grep -r "/home/$oldname" /target/home/$newname/.local | awk -F":" '{ print $1 }'); do | |
| sed -i "s/\/home\/$oldname/\/home\/$newname/g" "$i" | |
| done | |
| fi | |
| #### Add user's real name in /etc/passwd (for Refracta) | |
| if [[ $change_user = "yes" ]]; then | |
| live_user=$(awk -v pattern="$newname" -F: '$1 ~ pattern { print $5 }' /target/etc/passwd) | |
| real_name=$(zenity --entry --title="Change real name" --text="The user's real name is currently $live_user. | |
| Enter the real name you want to use \(without | |
| the trailing commas\).") | |
| sed -i~ "s/$live_user/$real_name,,,/" /target/etc/passwd | |
| fi | |
| # Edit /etc/sudoers | |
| if [[ $install = "expert" ]]; then | |
| zenity --question --title="Edit /etc/sudoers" --ok-label=Yes --cancel-label=No \ | |
| --text="You should edit /etc/sudoers to comment out the last line, which gives \"user\" absolute power, or replace \"user\" with the new user name. A simple text-editor will open in the terminal if you do this now. | |
| Edit /etc/sudoers now?" | |
| if [[ $? = 0 ]]; then | |
| edit_sudoers="yes" | |
| chroot /target visudo | |
| fi | |
| fi | |
| # Disable sudo-mode for gksu | |
| if [[ $edit_sudoers = "yes" ]]; then | |
| zenity --question --title="Disable sudo mode for gksu" --ok-label="Yes, I commented out the line." --cancel-label="No, I replaced \"user\" with the new username." \ | |
| --text="If you commented out the last line in /etc/sudoers in the last step, one more file will be changed for you so that gksu will work properly." | |
| if [[ $? = 0 ]]; then | |
| if [[ -n $newname ]]; then | |
| sed -i~ '/sudo-mode/s/true/false/' /target/home/"$newname"/.gconf/apps/gksu/%gconf.xml | |
| else | |
| sed -i~ '/sudo-mode/s/true/false/' /target/home/user/.gconf/apps/gksu/%gconf.xml | |
| fi | |
| fi | |
| fi | |
| # Change/create root password | |
| if [[ $install = "expert" ]]; then | |
| zenity --question --title="Change/create root password" --ok-label=Yes --cancel-label=No \ | |
| --text=" | |
| The root password can now be changed. | |
| You'll need to go to the terminal again... | |
| " | |
| if [[ $? = 0 ]]; then | |
| # # Redirect stderr from the error log to the screen, | |
| # # so we can see the prompts from passwd | |
| exec 2>&1 | |
| echo "Change root passowrd" | |
| chroot /target passwd | |
| # # Resume logging errors in file | |
| exec 2>>"$error_log" | |
| fi | |
| fi | |
| # Change user password | |
| if [[ $change_user = "yes" ]]; then | |
| zenity --question --title="Change user password" --ok-label=Yes --cancel-label=No \ | |
| --text="Would you like to change the user's password? The new user still has the old user's password. You'll need to go to the terminal again to do this." | |
| if [[ $? = 0 ]]; then | |
| # # Redirect stderr from the error log to the screen, | |
| # # so we can see the prompts from passwd | |
| exec 2>&1 | |
| echo "Change user passowrd" | |
| chroot /target passwd "$newname" | |
| # # Resume logging errors in file | |
| exec 2>>"$error_log" | |
| fi | |
| fi | |
| # call cleanup function | |
| cleanup | |
| echo -e "\n\t Done!\n\n You may now reboot into the new system.\n\nRemember to remove your installation media." | |
| zenity --info --text="Done!\n\n You may now reboot into the new system.\n\nRemember to remove your installation media.\n" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment