Created
July 23, 2012 03:59
-
-
Save fsmithred/3161926 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 (Yad) 9.0.5-4 (20120722)" | |
| # 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 | |
| # Greeting window | |
| mode=$(yad --info --title="$version" --button="Simple installation":0 \ | |
| --button="Expert installation":1 --button=Exit:2 \ | |
| --text=" This utility will install a running live-CD or live-USB to your hard drive. | |
| This is free software that comes with no warranty or guarantee of any type, | |
| including but not limited to express, implied, merchantability or fitness of purpose. | |
| Copyright 2011 fsmithred@gmail.com, based on refractainstaller-8.0.3 by Dean Linkous. ") | |
| case $mode in | |
| 0) install="simple" ;; | |
| 1) install="expert" ;; | |
| 2) exit 0 ;; | |
| esac | |
| # 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 | |
| yad --info --title=Error --window-icon=error --text=" | |
| You need to be root! | |
| " | |
| exit 1 | |
| fi | |
| refractainstaller_configuration () { | |
| if [[ -f $configfile ]]; then | |
| source $configfile | |
| else | |
| yad --info --title=Warning --window-icon=error \ | |
| --button=Continue:0 --button=Exit:1 \ | |
| --text=" Config file $configfile is missing | |
| Continue with default settings? " | |
| if [[ $? = 1 ]] ; then | |
| exit 0 | |
| fi | |
| 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"} | |
| 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 | |
| yad --info --title="Error" --window-icon=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 | |
| chmod 666 "$rsync_excludes" | |
| } | |
| # Check that rsync excludes file exists, or create one. | |
| if ! [[ -f $rsync_excludes ]] ; then | |
| yad --info --title=Warning --window-icon=error \ | |
| --button=Continue:0 --button=Exit:1 \ | |
| --text=" There is no rsync excludes file, or its name does not match what this script expects. | |
| You should continue and 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 in $configfile 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 | |
| echo "copied excludes to $(pwd)" | |
| else | |
| echo "Exiting ---" | |
| exit 0 | |
| fi | |
| fi | |
| # Select expert installation options | |
| if [[ $install = "expert" ]]; then | |
| opts=$(yad --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 "Change hostname." \ | |
| FALSE 11 "Disable automatic login." \ | |
| 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 | |
| change_hostname="yes" | |
| fi | |
| if $(echo $opts | grep -q 11); then | |
| disable_auto_desktop="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 | |
| yad --info --title=Error \ | |
| --button="Proceed without encrypting partitions":0 \ | |
| --button=Exit:1 --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 does not get to partition the disk - proceed or exit | |
| #if [[ $install = "expert" ]]; then | |
| ans=$(yad --info --title=Partitioning --button="Run GParted":0 --button="Run cfdisk":1 \ | |
| --button="Skip this step":2 --button=Exit:3 \ | |
| --text=" You need to have at least one partition ready for the installation, plus one for each separate | |
| partition that you chose. If you already have the partition(s) ready, you can skip this step. | |
| Run the partitioner now?") | |
| case $ans in | |
| 0) gparted ;; | |
| 1) cfdisk ;; | |
| 2) ;; | |
| 3) exit 0 ;; | |
| esac | |
| # # test to make sure there's a separate /boot partition | |
| if [[ $sep_boot = "no" ]]; then | |
| if [[ $encrypt_os = "yes" ]]; then | |
| yad --info --window-icon=error --title=Error \ | |
| --button="Proceed without encrypting partition":0 \ | |
| --button=Exit:1 --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 () { | |
| yad --info --title="Install GRUB bootloader" --text=" Choose a location to install the bootloader. The usual choice is to | |
| put it in the master boot record of the first hard drive (/dev/sda). | |
| Choose MBR to install to the mbr of any hard disk. | |
| Choose Partition to install to a partition. | |
| Choose No Bootloader to proceed without a bootloader. | |
| Choose Exit to exit this program. | |
| " \ | |
| --button=MBR:0 --button=Partition:1 --button="No Bootloader":2 --button=Exit:3 | |
| answer="$?" | |
| if [[ $answer = 0 ]] ; then | |
| grub_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z]" \ | |
| | sort | awk '{print "\n" $0 }' \ | |
| | yad --list --separator="" --title=Bootloader --text="Choose a location to install the bootloader. | |
| " \ | |
| --column ' ' --column 'Hard Drives' --height=200) | |
| if [[ -z $grub_dev ]] ; then | |
| yad --info --title=Error --button="Yes, I'm sure.":0 --button="Go back":1 \ | |
| --text="No bootloader will be installed. Are you sure you want this?" | |
| if [[ $? = 1 ]] ; then | |
| choose_grub | |
| fi | |
| elif ! [[ -b $grub_dev ]] ; then | |
| yad --info --title=Error --button=Exit:0 --button="Go back":1 \ | |
| --text="Something is wrong. Maybe you checked more than one box. You said you want to install the bootloader in $grub_dev" | |
| if [[ $? = 0 ]] ; then | |
| exit 1 | |
| else | |
| choose_grub | |
| fi | |
| fi | |
| #fi | |
| elif [[ $answer = 1 ]] ; then | |
| yad --info --title=Bootloader --text="This option not implemented yet. | |
| Someday, you'll be able to install grub to a partition." \ | |
| --button="Proceed without bootloader":0 --button="Go back":1 --button=Exit:2 | |
| ans="$?" | |
| if [[ $ans = 1 ]] ; then | |
| choose_grub | |
| fi | |
| if [[ $ans = 2 ]] ; then | |
| exit 0 | |
| fi | |
| #fi | |
| elif [[ $answer = 2 ]] ; then | |
| yad --info --title=Bootloader --text=" Proceeding without a bootloader. | |
| You will need to do special things to boot your operating system. Be sure | |
| that you know what you're doing." \ | |
| --button=Proceed:0 --button=Exit:1 | |
| if [[ $? = 1 ]] ; then | |
| exit 0 | |
| fi | |
| #fi | |
| elif [[ $answer = 3 ]] ; then | |
| exit 0 | |
| 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 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 "\n" $0 }' \ | |
| | yad --list --title="/boot partition" --text="Select a partition for /boot." \ | |
| --separator="" --column ' ' --column 'Partitions' --height=380 --width=150) | |
| } | |
| if [[ $sep_boot = "yes" ]]; then | |
| choose_boot | |
| fi | |
| # Choose filesystem type for /boot | |
| choose_fs_boot () { | |
| if [[ -n $boot_dev ]]; then | |
| fs_type_boot=$(yad --list --title="/boot filesystem" --text="What type of filesystem would you like on $boot_dev?" \ | |
| --separator="" --column "Format" --height=200\ | |
| "ext2" \ | |
| "ext3" \ | |
| "ext4") | |
| fi | |
| if [[ -z $fs_type_boot ]]; then | |
| yad --info --title=Error --button="Go back":0 --button=Exit:1 \ | |
| --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 "\n" $0 }' \ | |
| | yad --list --title="Root Partition" --text="Choose a partition to use for the installation of the operating system." \ | |
| --separator="" --column ' ' --column 'Partitions' --height 380 --width 150) | |
| echo "$install_dev" | |
| if [[ -z $install_dev ]] ; then | |
| yad --info --title=Error --button="Go back":0 --button=Exit:1 \ | |
| --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 | |
| yad --info --title=Error --button="Go back":0 --button=Exit:1 \ | |
| --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 | |
| yad --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=$(yad --list --title="Root Filesystem" --text="What type of filesystem would you like on $install_dev?" \ | |
| --separator="" --column "Format" --height=200\ | |
| "ext2" \ | |
| "ext3" \ | |
| "ext4") | |
| if [[ -z $fs_type_os ]]; then | |
| yad --info --title=Error --button="Go back":0 --button=Exit:1 \ | |
| --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 "\n" $0 }' \ | |
| | yad --list --title="/home partition" --text="Select a partition for /home" \ | |
| --separator="" --column ' ' --column 'Partitions' --height=380 --width=150) | |
| if [[ -n $home_dev ]] ; then | |
| if ! [[ -b $home_dev ]] ; then | |
| yad --info --title=Error --button="Go back":0 --button=Exit:1 \ | |
| --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 | |
| yad --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 | |
| yad --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=$(yad --list --title="/home filesystem" --text="What type of filesystem would you like on $home_dev?" \ | |
| --separator="" --column "Format" --height=200\ | |
| "ext2" \ | |
| "ext3" \ | |
| "ext4") | |
| fi | |
| if [[ -z $fs_type_home ]]; then | |
| yad --info --title=Error --button="Go back":0 --button=Exit:1 \ | |
| --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=$(yad --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 | |
| yad --info --title=Summary --button="Proceed with the installation.":0 --button="Exit":1 \ | |
| --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 | |
| $uuid_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_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 >(yad --progress --pulsate --width=350 --auto-close --title="Copying system to new partition.") | |
| # 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="$rsync_excludes" | \ | |
| tee >(yad --progress --pulsate --width=350 --auto-close --title="Copying home folders to new partition.") | |
| fi | |
| # copy separate /boot if needed | |
| if [[ -n $boot_dev ]] ; then | |
| echo -e "\n Copying files to boot partition...\n" | |
| rsync -av /boot/ /target_boot/ --exclude-from="$rsync_excludes" | \ | |
| tee >(yad --progress --pulsate --width=350 --auto-close --title="Copying files to boot partition.") | |
| 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 >(yad --progress --pulsate --width=350 --auto-close --title="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 | |
| sed -i 's:/dev/sd\[a-z\]:#/dev/sd\[a-z\]:' /target/etc/pmount.allow | |
| fi | |
| # Re-enable updatedb if it was disabled by snapshot | |
| [[ -x /target/usr/bin/updatedb.mlocate ]] || chmod +x /target/usr/bin/updatedb.mlocate | |
| # Disable autologin | |
| 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 | |
| # console autologin | |
| 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 | |
| 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 | |
| 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 ! [[ -h /target/etc/rc2.d/S02clamav-freshclam ]] ; then | |
| chroot /target update-rc.d clamav-freshclam defaults | |
| fi | |
| fi | |
| ######## This goes in refractasnapshot !!!!!!!!!! | |
| #for link in /target/etc/rc*.d/*clamav-freshclam ; do | |
| # rm $link | |
| #done | |
| # Disable root login through ssh | |
| if [[ -f /etc/ssh/sshd_config ]] ; then | |
| sed -i~ 's/PermitRootLogin yes/PermitRootLogin no/' /target/etc/ssh/sshd_config | |
| 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 | |
| if [[ $change_user = "yes" ]]; then | |
| oldname=$(awk -F: '/1000:1000/ { print $1 }' /target/etc/passwd) | |
| newname=$(yad --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=$(yad --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 | |
| yad --info --title="Edit /etc/sudoers" --button=Yes:0 --button=No:1 \ | |
| --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 | |
| yad --info --title="Disable sudo mode for gksu" --button="Yes, I commented out the line.":0 --button="No, I replaced \"user\" with the new username.":1 \ | |
| --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 | |
| yad --info title="Change/create root password" --button=Yes:0 --button=No:1 \ | |
| --text="The root password is currently \"root\" and should be changed to something more secure. | |
| You'll need to go to the terminal again... | |
| Change root password? (I really shouldn't give you a choice here.)" | |
| 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 | |
| yad --info --title="Change user password" --button=Yes:0 --button=No:1 \ | |
| --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." | |
| yad --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