Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # exegnu-installer
- # HD installer for a generic Debian Live system OR a refractasnapshot-type Live system
- # depends: zenity | yad, gparted
- # Copyright: David Hare, April 2011
- # Copyright 2011 fsmithred@gmail.com
- # License: GPL-3
- # Credits to: fsmithred (refracta) and fragadelic (remastersys) for some parts of code used here.
- # Both have written good working installers.
- # Traducción (espanol): Alexis Puente Montiel, < alexispm_stellaluna@yahoo.es >
- # Trinity (kde3 fork) desktop and grub-legacy are supported
- # It will alsu support a refracta-snapshot type ISO in "clone" or "new user config" mode (a file "/etc/snapshotid" must exist or be created)
- # "new user config" mode means, it will behave as a normal debian-live image with whatever defaults are in /etc/skel
- # The intention is to minimise extra steps and cli work for the user (one script does all)
- # Script written for squeeze; wheezy/sid support....... depends who is on the case of maintaining it!
- # It should be run from a root terminal session. Zenity|yad dialogs are used.
- # TODO : support for seperate /home /boot and encryption
- # TODO : write log file (without verbose rsync output)
- # (for now) any customisation to new user's ~ need to be set in /etc/skel else you get Debian and desktop manager defaults
- TEXTDOMAIN=exegnu-installer
- TEXTDOMAINDIR=/usr/share/locale/
- ##USER EDITABLE VARS ##
- # set the title for zenity|yad dialogs to whatever you want here but keep the quotes
- TITLE=$"Exe GNU/Linux Installer"
- # if it's a snapshot, /etc/snapshotid must exist. (uncomment the next line if original refractasnapshot was used)
- # echo "Generated by $TITLE for temporary use" > /etc/snapshotid
- # use yad if exists else use zenity
- if [ -f /usr/bin/yad ]; then
- DIALOG=yad
- INFO="image=gtk-dialog-info"
- QUESTION="image=gtk-dialog-question"
- WARNING="image=gtk-dialog-warning"
- ERROR="image=gtk-dialog-error"
- #buttons
- BUTTON0="button"
- BUTTON1="button"
- BUTTON0NUM=":0"
- BUTTON1NUM=":1"
- else
- DIALOG=zenity
- INFO=info
- QUESTION=question
- WARNING=warning
- ERROR=error
- #buttons
- BUTTON0="ok-label"
- BUTTON1="cancel-label"
- BUTTON0NUM=""
- BUTTON1NUM=""
- fi
- #################################################################################
- # detect system language
- SCRIPTLANG=$(env | egrep 'LC|LANG' | grep -o 'es_')
- #* check for root
- if [[ $EUID -ne 0 ]]; then
- $DIALOG --$ERROR --width=400 --height=160 --title="$TITLE" --text=$"\nThis installer must be run as Root\! \n\nCannot continue."
- exit 1
- fi
- # LIVESESSIONCHECK
- #LIVESESSIONCHECK=$(cat /etc/passwd|grep 1000|grep Live)
- LIVESESSIONCHECK=$(cat /proc/cmdline | grep "boot=live")
- # Make sure script can't run from a fixed installation
- #if [ "$LIVESESSIONCHECK" = "" ] && [ "$LIVESNAP" = "" ]; then
- if [ "$LIVESESSIONCHECK" = "" ]; then
- $DIALOG --$ERROR --width=400 --height=160 --title="$TITLE" --text=$"\nThis does not seem to be a Debian Live session\!\n\nCannot continue."
- exit 1
- fi
- # identify if it's a snapshot, (/etc/snapshotid must exist)
- if [ -f /etc/snapshotid ]; then
- LIVESNAP=yes
- fi
- #*************************************************************
- #* intro
- TEXT=$"\n\nThis Live system will be installed to hard disk.\n\nPartitioning and formatting will be necessary.\n\nDo you want to continue?"
- $DIALOG --$QUESTION --width=460 --height=240 --title="$TITLE" --${BUTTON0}=$"Continue"${BUTTON0NUM} --${BUTTON1}=$"Exit now"${BUTTON1NUM} --text="$TEXT"
- if [ "$?" = "1" ]; then
- exit 1
- fi
- #*************************************************************
- # write errors to log
- ERRORLOG="/var/log/installer_errors.log"
- if [ -f "$ERRORLOG" ]; then truncate -s 0 $ERRORLOG; fi
- exec 2>>"$ERRORLOG"
- # FUTURE USE: zinstaller (thanks fsmithred) used this maybe something similar here?
- # exit on errors
- check_exit () {
- [[ $? -eq 0 ]] || { echo "
- Exit due to error: $?
- See $ERRORLOG for details.
- " ; $DIALOG --$ERROR --text="Exit due to error: $?
- See $ERRORLOG for details." &
- exit 1 ; }
- }
- # for zenity boxes, if no input was given, "try again or exit" box
- input_error () {
- $DIALOG --$QUESTION --width=460 --title="$TITLE" --${BUTTON0}=$"Try again"${BUTTON0NUM} --${BUTTON1}=$"Quit the installer"${BUTTON1NUM} --text=$"Input error! Please try again"
- if [[ $? -eq 1 ]]; then
- rm -f userinput
- exit 1
- else
- $REPEAT_FUNCTION
- fi
- }
- #*************************************************************
- # if it's a live snapshot, set snapshot install method
- snap_method () {
- TEXT=$"A \"Live Snapshot\" system is detected.\n\nPlease select the installation method:"
- OPTION1=$"Install to fixed disk with existing user configurations"
- OPTION2=$"Install to fixed disk with a new default user"
- SNAPMETHOD=$($DIALOG --width=640 --height=200 --title="$TITLE" --list --column="" --column="" --hide-column=1 --print-column=1 --separator="" --text="$TEXT" "01" "$OPTION1" "02" "$OPTION2")
- # if it did not get set (is blank)
- if [ "$SNAPMETHOD" = "" ]; then
- # set a new repeat_function for input_error function
- REPEAT_FUNCTION=snap_method
- # call "input error" function and repeat the dialog (or exit)
- input_error
- fi
- }
- if [ "$LIVESNAP" = "yes" ]; then
- snap_method
- if [ "$SNAPMETHOD" = "01" ]; then
- SNAPMETHOD=clone
- else
- SNAPMETHOD=newconfig
- fi
- # if it's a live snapshot, some or all of these will be in /proc/cmdline
- CMDNOAUTOLOGIN=$(egrep noautologin /proc/cmdline)
- CMDNOSUDO=$(egrep nosudo /proc/cmdline)
- CMDNOUSER=$(egrep nouser /proc/cmdline)
- # else it's a generic debian-live
- fi
- #*************************************************************
- # before partitioning, find out now if a swap partition already exists
- EXISTINGSWAP=$(blkid -o list |grep /dev |grep swap| awk '{print $1}' |sort)
- #partitioning question
- TEXT=$"A disk partition formatted EXT2/3/4 and at least 3GB is required for this installation.\n\n\
- Optionally, a swap partition may be created at this time or an existing swap may be used \n\n\
- Optionally, a separate /home partition may be created \n\n\
- Even if partitions are already prepared, you should run GParted now to review their location and device names.\n\n\
- Run GParted Partition Editor now?"
- $DIALOG --$QUESTION --width=460 --height=320 --title=$"Partitioning" --${BUTTON0}=$"Yes"${BUTTON0NUM} --${BUTTON1}="No"${BUTTON1NUM} --text="$TEXT"
- if [[ $? = 0 ]] ; then
- gparted
- fi
- ##########################################
- # get user input for the installer variables to a file 'userinput'
- # it will get copied to and used in chroot later
- # start with what's in the conf file
- echo "">userinput
- while read line; do echo "$line"|sed "s~^#.*~~">>userinput; done </etc/exegnu/exegnu-installer.conf
- # get partition lists for zenity
- # blkid can be unreliable used with awk if some devices have a label and some not... awk '{print $1}' always gets the device
- # blkid -o value -s TAG ('/dev/sdbx' to specify a device) works, where TAG can be TYPE LABEL or UUID
- # "grep /dev/sd" excludes the headers
- # set / ($INSTALLPARTITION) function
- set_installpartition () {
- INSTALLPARTITIONLIST=$(blkid -o list |grep /dev/sd|grep -v ntfs|grep -v vfat|grep -v swap|awk '{print $1}'|sort)
- # check the partition is large enough?
- INSTALLPARTITION=$($DIALOG --width=460 --height=320 --title="$TITLE" --list --separator="" --column="" --text=$"Please select the root partition for the installed system" $INSTALLPARTITIONLIST)
- # if it did not get set (is blank)
- if [ "$INSTALLPARTITION" = "" ]; then
- # set a new repeat_function for input_error function
- REPEAT_FUNCTION=set_installpartition
- # call "input error" function and repeat the dialog (or exit)
- input_error
- fi
- }
- #run that function
- set_installpartition
- # write it to config file
- echo "INSTALLPARTITION=\"$INSTALLPARTITION\"" >>userinput
- ##########################################
- # set / ($HOMEPARTITION) function
- set_homepartition () {
- HOMEPARTITIONLIST=$(blkid -o list |grep /dev/sd|grep -v ntfs|grep -v vfat|grep -v swap|grep -v "${INSTALLPARTITION} "|awk '{print $1}'|sort)
- # check the partition is large enough?
- NO_HOME=$"Do not use a separate /home partition"
- HOMEPARTITION=$($DIALOG --width=460 --height=320 --title="/home setup.." --list --separator="" --column="" --text=$"A partition in this list may be used for a separate /home. \nFormatting is necessary. \n\nWARNING: This option is experimental and untested\!\n\nPlease select 'Do not use a separate /home partition' if this is not required or if unsure" "$NO_HOME" $HOMEPARTITIONLIST)
- }
- set_homepartition
- # write it to config file
- if echo $HOMEPARTITION|grep -q "/dev/sd[a-z][0-9]"; then
- echo "HOMEPARTITION=\"$HOMEPARTITION\"" >>userinput
- else
- # /home will be set on rootfs even if the dialog was cancelled without annswer
- HOMEPARTITION=${NO_HOME}
- fi
- ##########################################
- # set swap ($SWAPPARTITION)
- set_swappartition () {
- SWAPPARTITIONLIST=$(blkid -o list|grep /dev/sd |grep swap|awk '{print $1}'|sort)
- USE_SWAPFILE=$"Use a swap file"
- NO_SWAP=$"Do not configure swap"
- SWAPPARTITION=$($DIALOG --width=460 --height=360 --title="$TITLE" --list --separator="" --column="" --text=$"Please select swap configuration for the installed system \n\nAn existing swap partition in this list may be used \n\nIf unsure select 'Use a swap file'" "$USE_SWAPFILE" "$NO_SWAP" $SWAPPARTITIONLIST)
- if [ "$SWAPPARTITION" = "" ]; then
- # set a new repeat_function for input_error function
- REPEAT_FUNCTION=set_swappartition
- # call "input error" function and repeat the dialog (or exit)
- input_error
- fi
- }
- #run that function
- set_swappartition
- # write it to config file
- if [ "$SWAPPARTITION" != "$NO_SWAP" ] ; then
- echo "SWAPPARTITION=\"$SWAPPARTITION\"" >>userinput
- fi
- ##########################################
- # set filesystem root
- set_filesystem () {
- FSTYPE=$($DIALOG --width=460 --height=200 --title="$TITLE" --list --separator="" --column="" --text=$"Please select the required root filesystem" "ext3" "ext4")
- if [ "$FSTYPE" = "" ]; then
- REPEAT_FUNCTION=set_filesystem
- input_error
- fi
- }
- set_filesystem
- echo "FSTYPE=\"$FSTYPE\"" >>userinput
- ##########################################
- # set filesystem home
- set_filesystem_home () {
- FSTYPEHOME=$($DIALOG --width=460 --height=200 --title="$TITLE" --list --separator="" --column="" --text=$"Please select the required /home filesystem" "ext3" "ext4")
- if [ "$FSTYPEHOME" = "" ]; then
- REPEAT_FUNCTION=set_filesystem_home
- input_error
- fi
- }
- if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
- set_filesystem_home
- echo "FSTYPEHOME=\"$FSTYPEHOME\"" >>userinput
- fi
- ##########################################
- # set fs label root
- set_fslabelroot () {
- FSLABELROOT=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nYou may enter a label for the new system partition \n\n(Lowercase letters and/or numbers only, no symbols or spaces) \n\nThis may be left blank if not required\n ")
- if ! [ "$FSLABELROOT" = "" ]; then
- CHECK_LABEL_ROOT=$(blkid|grep LABEL=\"$FSLABELROOT\"|grep -v $INSTALLPARTITION)
- if ! [ "$CHECK_LABEL_ROOT" = "" ]; then
- REPEAT_FUNCTION=set_fslabelroot
- TEXT=$"This label is already in use! Please try again"
- $DIALOG --$QUESTION --${BUTTON0}=$"Try again"${BUTTON0NUM} --${BUTTON1}=$"Quit the installer"${BUTTON1NUM} --text="$TEXT"
- if [[ $? -eq 1 ]]; then
- rm -f userinput
- exit 1
- else
- $REPEAT_FUNCTION
- fi
- fi
- fi
- }
- set_fslabelroot
- echo "FSLABELROOT=\"$FSLABELROOT\"" >>userinput
- ##########################################
- # set fs label home
- set_fslabelhome () {
- FSLABELHOME=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nYou may enter a label for the new /home partition \n\n(Lowercase letters and/or numbers only, no symbols or spaces) \n\nThis may be left blank if not required\n ")
- if ! [ "$FSLABELHOME" = "" ]; then
- CHECK_LABEL_HOME=$(blkid|grep LABEL=\"$FSLABELHOME\"|grep -v $HOMEPARTITION)
- if ! [ "$CHECK_LABEL_HOME" = "" ]; then
- REPEAT_FUNCTION=set_fslabelhome
- TEXT=$"This label is already in use! Please try again"
- $DIALOG --$QUESTION ---${BUTTON0}=$"Try again"${BUTTON0NUM} --${BUTTON1}=$"Quit the installer"${BUTTON1NUM} --text="$TEXT"
- if [[ $? -eq 1 ]]; then
- rm -f userinput
- exit 1
- else
- $REPEAT_FUNCTION
- fi
- fi
- fi
- }
- if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
- set_fslabelhome
- echo "FSLABELHOME=\"$FSLABELHOME\"" >>userinput
- fi
- ##########################################
- # set user input configs, (but some not for a snapshot clone)
- if ! [ "$SNAPMETHOD" = "clone" ]; then
- # set hostname
- set_hostname () {
- NEWHOSTNAME=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nPlease enter a hostname for the installed system \n\n(Lowercase letters and/or numbers only, no symbols or spaces)\n ")
- if [ "$NEWHOSTNAME" = "" ]; then
- REPEAT_FUNCTION=set_hostname
- input_error
- fi
- }
- set_hostname
- echo "NEWHOSTNAME=\"$NEWHOSTNAME\"" >>userinput
- ##########################################
- # set username
- set_username () {
- NEWUSERNAME=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nPlease enter a username for the installed system \n\n(Lowercase letters and/or numbers only, no symbols or spaces)\n ")
- if [ "$NEWUSERNAME" = "" ]; then
- REPEAT_FUNCTION=set_username
- input_error
- fi
- }
- set_username
- echo "NEWUSERNAME=\"$NEWUSERNAME\"" >>userinput
- ##########################################
- # set "user full name"
- set_userfullname () {
- NEWUSERREALNAME=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nPlease enter your new user's Full Name \n\n(Uppercase letters and spaces allowed)\n ")
- if [ "$NEWUSERREALNAME" = "" ]; then
- REPEAT_FUNCTION=set_userfullname
- input_error
- fi
- }
- set_userfullname
- echo "NEWUSERREALNAME=\"$NEWUSERREALNAME\"" >>userinput
- ##########################################
- # set user password
- set_userpass () {
- # what is the point of starring out passwords now? the config file gets deleted later
- NEWUSERPASS=$($DIALOG --width=460 --height=160 --title="$TITLE" --entry --text=$"\nPlease enter a password for your new user\n")
- if [ "$NEWUSERPASS" = "" ]; then
- REPEAT_FUNCTION=set_userpass
- input_error
- fi
- }
- set_userpass
- echo "NEWUSERPASS=\"$NEWUSERPASS\"" >>userinput
- ##########################################
- # set root password
- set_rootpass () {
- NEWROOTPASS=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nPlease enter a root password for the installed system\n")
- if [ "$NEWROOTPASS" = "" ]; then
- REPEAT_FUNCTION=set_rootpass
- input_error
- fi
- }
- set_rootpass
- echo "NEWROOTPASS=\"$NEWROOTPASS\"" >>userinput
- # set user choice for su/sudo (unless it's a snapshot "clone")
- TEXT=$"\n\nThis Live CD uses sudo, gksudo, kdesudo or tdesudo for Root access. No password is required.\n\\nDebian installations normally default to su, gksu, kdesu or tdesu. ROOT'S password is required to open root applications. Sudo (if required) is a post-install user option. \n\n\Disable default sudo in the installed system (recommended)?"
- $DIALOG --$QUESTION --width=460 --height=320 --title="$TITLE" --${BUTTON0}=$"Disable sudo"${BUTTON0NUM} --${BUTTON1}=$"Use sudo"${BUTTON1NUM} --text="$TEXT"
- if [ "$?" = 0 ]; then
- SUDOCONFIG=disabled
- SUDOCONFIG_TEXT=$"will be disabled"
- else
- SUDOCONFIG=enabled
- SUDOCONFIG_TEXT=$"will be enabled"
- fi
- echo "SUDOCONFIG=\"$SUDOCONFIG\"" >>userinput
- # end snapshot-clone conditional
- fi
- ## tzdata ################################
- TZ=$(cat /etc/timezone)
- TEXT=$"The current default timezone is set to $TZ. \n\n\
- Local timezone can now be set in the terminal window. \n\n\
- Please cancel this dialog to use the current default"
- $DIALOG --$QUESTION --width=460 --height=240 --title="$TITLE" --${BUTTON0}=$"Cancel"${BUTTON0NUM} --${BUTTON1}=$"Change timezone"${BUTTON1NUM} --text="$TEXT"
- if [ "$?" = "1" ]; then
- dpkg-reconfigure tzdata
- fi
- ##########################################
- ##########################################
- # set grub install location
- configure_grub () {
- # get grub version, we want to support all
- GRUBVERSION=$(dpkg -l|grep ii|awk '{print $2}'|grep -v bin|grep -v theme|grep -E grub-legacy\|grub-gfxboot\|grub-pc\|grub-efi-amd64)
- # detect uefi
- if [ -d /sys/firmware/efi ] && [ "$GRUBVERSION" = "grub-efi-amd64" ]; then
- booted_efi=yes
- EFI_PART=$(fdisk -l|grep "^/dev/sd[a-z][0-9]"|grep -m 1 "EFI"|awk '{print $1}')
- EFI_DISK=$(fdisk -l|grep "^/dev/sd[a-z][0-9]"|grep -m 1 "EFI"|sed 's~/dev/~~'|awk '{print $1}')
- TEXT=$"A UEFI system is detected and configured at $EFI_PART. \n\nPlease choose how the GRUB bootloader will be installed. \n\nIf this fails you will later need to sort the bootloader manually. \n "
- GRUBINST=$($DIALOG --width=460 --height=400 --title="$TITLE" --list --separator="" --column="" --text="$TEXT" $"UEFI mode" $"Do not install Grub")
- else
- TEXT=$"Grub bootloader should normally be installed to the MBR of the first hard disk \n\nPlease select 'MBR of first hard disk'\n\nIf you want to keep an existing bootloader and configure it manually later, you may select an alternative location to install Grub\n "
- GRUBINST=$($DIALOG --width=460 --height=400 --title="$TITLE" --list --separator="" --column="" --text="$TEXT" $"MBR of first hard disk" $"MBR of installation disk" $"Installation partition" $"Do not install Grub")
- fi
- if [ -z "$GRUBINST" ]; then
- REPEAT_FUNCTION=configure_grub
- input_error
- fi
- }
- configure_grub
- # echo "GRUBVERS=\"$GRUBVERS\"" >>userinput
- echo "GRUBINST=\"$GRUBINST\"" >>userinput
- ###################################################
- # verify chosen settings
- # last chance to exit before something gets buggered (hopefully not)!
- if [ "$SNAPMETHOD" = "clone" ]; then
- TEXT=$"\nThe system will be installed to $INSTALLPARTITION, formatted to $FSTYPE\n\n\
- Usernames and passwords will be as in the live session\n\n\
- Grub bootloader will be installed to $GRUBINST\n\n\
- Disk formatting and Installation will now begin.\n\
- Please EXIT NOW if not ready to do this\!"
- $DIALOG --$QUESTION --width=460 --height=240 --title=$"Please Review Settings" --${BUTTON0}=$"Continue"${BUTTON0NUM} --${BUTTON1}="Exit now"${BUTTON1NUM} --text="$TEXT"
- if ! [[ $? = 0 ]] ; then
- rm -f userinput
- exit
- fi
- else
- if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
- # only include this if separate /home
- HOMECONFIG_TEXT=$"The /home partition will be $HOMEPARTITION, formatted to $FSTYPEHOME\n\n\
- The /home partition label will be '$FSLABELHOME'\n\n"
- fi
- TEXT=$"\nThe system will be installed to $INSTALLPARTITION, formatted to $FSTYPE\n\n\
- The system partition label will be '$FSLABELROOT'\n\n\
- ${HOMECONFIG_TEXT}\
- The hostname will be '$NEWHOSTNAME'\n\n\
- The user name will be '$NEWUSERNAME'\n\n\
- The user's full name will be '$NEWUSERREALNAME'\n\n\
- The user password will be '$NEWUSERPASS'\n\n\
- The root password will be '$NEWROOTPASS'\n\n\
- Grub bootloader will be installed to $GRUBINST\n\n\
- Sudo $SUDOCONFIG_TEXT\n\n\
- Disk formatting and Installation will now begin.\n\n\
- Please EXIT NOW if not ready to do this\!\n"
- $DIALOG --$QUESTION --width=640 --title=$"Please Review Settings" --${BUTTON0}=$"Continue"${BUTTON0NUM} --${BUTTON1}=$"Exit now"${BUTTON1NUM} --text="$TEXT"
- if ! [[ $? = 0 ]] ; then
- rm -f userinput
- exit
- fi
- # end "clone" conditional
- fi
- # Settings are now in file "./userinput" to be used later
- #*************************************************************
- # read chosen settings set by dialogs from file
- source ./userinput
- # format /
- mke2fs -t $FSTYPE "$INSTALLPARTITION"
- #tune2fs
- tune2fs -r 10000 "$INSTALLPARTITION"
- # do labels
- if ! [ "$FSLABELROOT" = "" ]; then
- e2label $INSTALLPARTITION $FSLABELROOT
- fi
- # make mountpoint and mount it
- mkdir /target
- mount "$INSTALLPARTITION" /target
- # separate /home only
- if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
- mke2fs -t $FSTYPEHOME "$HOMEPARTITION"
- tune2fs -r 10000 "$HOMEPARTITION"
- if ! [ "$FSLABELHOME" = "" ]; then
- e2label $HOMEPARTITION $FSLABELHOME
- fi
- # mkdir /targethome
- # mount "$HOMEPARTITION" /targethome
- mkdir /target/home
- mount "$HOMEPARTITION" /target/home
- fi
- #*************************************************************
- # sort swap
- case "$SWAPPARTITION" in
- ${NO_SWAP})
- sleep 0
- ;;
- ${USE_SWAPFILE})
- # make a swapfile now
- # bollocks! "if" used like this makes the script think it's a conditional.....try it in quotes
- dd "if=/dev/zero" of=/target/swapfile bs=1048 count=256000
- mkswap /target/swapfile
- ;;
- *)
- # we are using a partition
- # what if swap exists? Why format? also, it might be already mounted and used in live session
- # if it is formatted the uuid will change, then fstab will be wrong in another OS that uses it
- # but could still format with old uuid, first swapoff -a then mkswap $SWAPPARTITION -U <old_uuid>
- if ! [ "$(blkid -o value -s TYPE $SWAPPARTITION)" = "swap" ]; then
- mkswap $SWAPPARTITION
- fi
- ;;
- esac
- #*************************************************************
- # make rsync excludes file
- cat > ./rsyncexcludes <<EOF
- - /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/
- - /etc/snapshotid/
- - /var/tmp/*
- - /lib/live/mount/*
- - /etc/fstab.d/*
- - /run/*
- - /lib/live/overlay
- - /lib/live/image
- - /lib/live/rootfs
- - /lib/live/mount
- - /lib/live/findiso
- EOF
- # copy the system
- rsync -a --progress / /target/ --exclude-from ./rsyncexcludes
- #*************************************************************
- # make some basic entries in myfs/dev so the system can boot properly before udev starts
- # rsync excluded /dev/*
- mknod -m 622 /target/dev/console c 5 1
- mknod -m 666 /target/dev/null c 1 3
- mknod -m 666 /target/dev/zero c 1 5
- mknod -m 666 /target/dev/ptmx c 5 2
- mknod -m 666 /target/dev/tty c 5 0
- mknod -m 444 /target/dev/random c 1 8
- mknod -m 444 /target/dev/urandom c 1 9
- chown -v root:tty /target/dev/{console,ptmx,tty}
- ln -sv /proc/self/fd /target/dev/fd
- ln -sv /proc/self/fd/0 /target/dev/stdin
- ln -sv /proc/self/fd/1 /target/dev/stdout
- ln -sv /proc/self/fd/2 /target/dev/stderr
- ln -sv /proc/kcore /target/dev/core
- ln -sv /run/shm /target/dev/shm
- mkdir -v /target/dev/pts
- #*************************************************************
- # post-install fixes start here
- # get uuids for new fstab
- INSTALLPARTITIONUUID=$(blkid -o value -s UUID $INSTALLPARTITION)
- HOMEPARTITIONUUID=$(blkid -o value -s UUID $HOMEPARTITION)
- SWAPPARTITIONUUID=$(blkid -o value -s UUID $SWAPPARTITION)
- if [ "$HOMEPARTITION" = "$NO_HOME" ]; then
- sleep 0
- else
- HOMEHASH="# $HOMEPARTITION ( /home )"
- HOMECONFIG="UUID=$HOMEPARTITIONUUID /home $FSTYPEHOME relatime,errors=remount-ro 0 1"
- fi
- if [ "$SWAPPARTITION" = "$NO_SWAP" ]; then
- sleep 0
- elif [ "$SWAPPARTITION" = "$USE_SWAPFILE" ]; then
- SWAPHASH="# /swapfile ( swap )"
- SWAPCONFIG="/swapfile swap swap defaults 0 0"
- else
- SWAPHASH="# $SWAPPARTITION ( swap )"
- SWAPCONFIG="UUID=$SWAPPARTITIONUUID none swap sw 0 0"
- fi
- #make new fstab
- # not sure about the cdrom entry... should it be /dev/sr0? what if more than one exists? is cdrom entry necessary at all?
- cat > /target/etc/fstab <<EOF
- # /etc/fstab: static file system information.
- #
- # Generated by $TITLE
- #
- # <file system> <mount point> <type> <options> <dump> <pass>
- proc /proc proc defaults 0 0
- # $INSTALLPARTITION ( / )
- UUID=$INSTALLPARTITIONUUID / $FSTYPE relatime,errors=remount-ro 0 1
- $HOMEHASH
- $HOMECONFIG
- $SWAPHASH
- $SWAPCONFIG
- # cdrom
- /dev/cdrom /media/cdrom udf,iso9660 user,noauto,exec,utf8 0 0
- EOF
- # restore original inittab
- cp /target/usr/share/sysvinit/inittab /target/etc/inittab
- # do hostname and hosts
- echo "$NEWHOSTNAME" > /target/etc/hostname
- echo "127.0.0.1 localhost" > /target/etc/hosts
- echo "127.0.0.1 $NEWHOSTNAME" >> /target/etc/hosts
- touch /target/etc/resolv.conf
- # remove autologin (was set by live-config)
- # UNLESS it's a snapshot then "noxautoconfig nosudo noautologin nouser" will be in cmdline
- #
- # "egrep noautologin /proc/cmdline" to find out
- if [ "$CMDNOAUTOLOGIN" = "" ];then
- #gdm2
- if [ -f /target/etc/gdm/gdm.conf ]; then
- sed -i -e 's/AutomaticLogin/#AutomaticLogin/g' /target/etc/gdm/gdm.conf
- sed -i -e 's/TimedLogin/#TimedLogin/g' /target/etc/gdm/gdm.conf
- fi
- #gdm3
- if [ -f /target/etc/gdm/gdm.conf ]; then
- sed -i -e 's/AutomaticLogin/#AutomaticLogin/g' /target/etc/gdm3/daemon.conf
- sed -i -e 's/TimedLogin/#TimedLogin/g' /target/etc/gdm3/daemon.conf
- fi
- #lightdm
- if [ -f /target/etc/lightdm/lightdm.conf ]; then
- sed -i -e 's/autologin/#autologin/g' /target/etc/lightdm/lightdm.conf
- fi
- #kde
- 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
- #kdm-trinity (=< TDE R13)
- if [ -f /target/etc/default/kdm-trinity.d/live-autologin ]; then
- rm -f /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
- #tdm-trinity (=> TDE R14)
- if [ -f /target/etc/default/tdm-trinity.d/live-autologin ]; then
- rm -f /target/etc/default/tdm-trinity.d/live-autologin
- fi
- if [ -f /target/etc/trinity/tdm/tdmrc ]; then
- sed -i -e 's/AutoLogin/#AutoLogin/g' /target/etc/trinity/tdm/tdmrc
- sed -i -e 's/AutoReLogin/#AutoReLogin/g' /target/etc/trinity/tdm/tdmrc
- fi
- # console autologin
- # if grep -q "respawn:/bin/login -f" /target/etc/inittab ; then
- # mv /target/etc/inittab /target/etc/inittab.$(date +%Y%m%d_%H%M)
- # cp /usr/lib/refractainstaller/inittab.debian /target/etc/inittab
- # fi
- fi
- #*************************************************************
- #*************************************************************
- # prepare for chroot
- #mount --bind /dev/ /target/dev/
- #mount --bind /proc/ /target/proc/
- #mount --bind /sys/ /target/sys/
- for i in dev devpts proc sys; do
- mount --bind /$i/ /target/$i/
- done
- ##########################################
- # do grub later, one machine hung doing grub now, then the rest of the install was incomplete
- #*************************************************************
- #*************************************************************
- #get more stuff in /target ready for chroot
- # add some extra vars to "userinput"
- OLDUSERNAME=""`grep '^[^:]*:[^:]*:1000:' /target/etc/passwd | awk -F ":" '{ print $1 }' | sed s/,,,//`""
- echo "OLDUSERNAME=$OLDUSERNAME" >>userinput
- # this may not be needed
- OLDUSERGROUP=$(cat /target/etc/group |grep 1000 | awk -F ":" '{ print $1 }')
- echo "OLDUSERGROUP=$OLDUSERGROUP" >>userinput
- # groups for new user
- # DEFAULTGROUPS="audio,cdrom,crontab,dialout,disk,floppy,fuse,lp,video,plugdev,netdev,powerdev,scanner,ssh,video,users"
- DEFAULTGROUPS="audio,cdrom,dialout,floppy,plugdev,users,video"
- echo "DEFAULTGROUPS=$DEFAULTGROUPS" >>userinput
- #
- # do we still need this for 3.5.13 ?
- # compatibility for older tde versions
- if [ -f /opt/trinity/bin/kdesu ]; then
- TDESU_CONFIGFILE=kdesurc
- fi
- if [ -f /opt/trinity/bin/tdesu ]; then
- TDESU_CONFIGFILE=tdesurc
- fi
- echo "TDESU_CONFIGFILE=$TDESU_CONFIGFILE" >>userinput
- # our userconfig file with the vars for chroot script
- cp -a userinput /target/userinput
- #*************************************************************
- # make a script for chroot and copy it to there
- cat > /target/chrootscript <<EOF
- #!/bin/bash
- # this all to run in a chroot
- # these vars, get from config file made with zenity dialogs and copied to the chroot
- # read the vars from the copied userinput file
- source ./userinput
- # sort dpkg-divert done by live-config
- # must remove divert live files else errors overwriting them
- if [ -f /usr/sbin/update-initramfs.debian ]; then
- rm -f /usr/sbin/update-initramfs
- dpkg-divert --remove --rename --quiet /usr/sbin/update-initramfs
- fi
- if [[ -f /usr/sbin/update-initramfs.distrib ]] ; then
- rm -f /usr/sbin/update-initramfs
- dpkg-divert --remove --rename --quiet /usr/sbin/update-initramfs
- fi
- if [ -f /usr/sbin/anacron.debian ]; then
- rm -f /usr/sbin/anacron
- dpkg-divert --remove --rename --quiet /usr/sbin/anacron
- fi
- dpkg-divert --remove --rename --quiet /usr/lib/update-notifier/apt-check
- update-initramfs -u
- shadowconfig on
- ######################################################
- EOF
- # append these to chroot script, except in snapshot-clone mode
- if ! [ "$SNAPMETHOD" = "clone" ]; then
- cat >> /target/chrootscript <<EOF
- # delete old user, make new
- userdel -f -r $OLDUSERNAME
- # userdel should have done this but it did not
- if cat /etc/group|grep -v users|grep $OLDUSERGROUP; then
- groupdel $OLDUSERGROUP
- fi
- # might not be needed with live-config, it uses %sudo
- sed -i '/$OLDUSERNAME/d' /etc/sudoers
- groupadd -g 1000 $NEWUSERNAME
- useradd -u 1000 -g 1000 -c "$NEWUSERREALNAME,,," -G $DEFAULTGROUPS -s /bin/bash -m $NEWUSERNAME
- echo -e "$NEWUSERPASS\n$NEWUSERPASS\n" | passwd $NEWUSERNAME
- # add to supplementary groups, check they exist first
- for i in adm crontab disk fuse lp netdev powerdev scanner ssh
- do
- GROUPEXISTS=\$(cat /etc/group|sort|awk -F ":" '{print \$1}'|grep -o "\$i")
- if [ "\$GROUPEXISTS" = "" ]; then
- echo "Error. Group \$i does not exist"
- else
- echo "Adding new user to group \$i"
- usermod -a -G \$i $NEWUSERNAME
- fi
- done
- # do root passwd
- echo -e "$NEWROOTPASS\n$NEWROOTPASS\n" | passwd root
- # hostname and hosts file
- echo "$NEWHOSTNAME" > /etc/hostname
- echo "127.0.0.1 localhost" > /etc/hosts
- echo "127.0.0.1 $NEWHOSTNAME" >> /etc/hosts
- # sort su/sudo
- if [ -n "$TDESU_CONFIGFILE" ]; then
- echo "[super-user-command]" >> /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
- echo "super-user-command=su" >> /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
- chown $NEWUSERNAME:$NEWUSERNAME /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
- if [ "$SUDOCONFIG" = "enabled" ]; then
- sed -i 's/command=su/command=sudo/' /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
- else
- if [ -f /var/lib/dpkg/info/kdesudo-trinity.list ]; then
- apt-get -y --force-yes purge kdesudo-trinity
- fi
- if [ -f /var/lib/dpkg/info/tdesudo-trinity.list ]; then
- apt-get -y --force-yes purge tdesudo-trinity
- fi
- fi
- fi
- #######################################
- if [ "$SUDOCONFIG" = "disabled" ]; then
- # wheezy live-config now uses /etc/sudoers.d
- if [ -e /etc/sudoers.d/live ]; then
- rm -f /etc/sudoers.d/live
- fi
- # fix gksu in user's home
- if [ -f /home/"$NEWUSERNAME"/.gconf/apps/gksu/%gconf.xml ]; then
- sed -i '/sudo-mode/s/true/false/' /home/"$NEWUSERNAME"/.gconf/apps/gksu/%gconf.xml
- # TODO fix kde4 in user's home
- fi
- else
- # NEWUSERNAME will use sudo so add him to sudo group
- usermod -a -G sudo $NEWUSERNAME
- fi
- # OLDUSERNAME no longer exists so remove from /etc/sudoers
- sed -i "s|$OLDUSERNAME ALL=(ALL) NOPASSWD: ALL||" /etc/sudoers
- if [ -n $CUSTOM_SKEL ]; then
- cp -R $CUSTOM_SKEL/. /home/$NEWUSERNAME
- # sort ownership for /home/${NEWUSERNAME}
- chown ${NEWUSERNAME}:${NEWUSERNAME} /home/${NEWUSERNAME} -R
- fi
- EOF
- fi
- #*************************************************************
- #*************************************************************
- # run script in chroot using vars from copied "userinput"
- chmod +x /target/chrootscript
- chroot /target /bin/bash /chrootscript
- #*************************************************************
- #*************************************************************
- # BUG
- # got an error in "clone" mode, the hostname was set blank, don't know why. Quick fix:
- if [ "$SNAPMETHOD" = "clone" ]; then
- NEWHOSTNAME=$(cat /etc/hostname)
- echo "$NEWHOSTNAME" > /target/etc/hostname
- # in case we need it later
- NEWUSERNAME=$OLDUSERNAME
- fi
- #*************************************************************
- #*************************************************************
- # not needed? $NEWUSERNAME is already sudo group member
- #sed -i "s|$OLDUSERNAME ALL=(ALL) NOPASSWD: ALL|$NEWUSERNAME ALL=(ALL:ALL) ALL|" /target/etc/sudoers
- rm -f /target/etc/blkid.tab
- if [ -f /target/etc/blkid.tab.old ]; then
- rm -f /target/etc/blkid.tab.old
- fi
- # fix new hostname for wicd
- sed -i "s/dhcphostname = .*/dhcphostname = $NEWHOSTNAME/" /target/etc/wicd/wired-settings.conf
- # pmount may be globally allowed in live system
- sed 's:/dev/sd/:#/dev/sd:' /target/etc/pmount.allow
- #ERRORLOG="/var/log/installer_errors.log"
- # copy it to the install
- cp -a $ERRORLOG /target/home/$NEWUSERNAME/installer_errors.log
- chmod 666 /target/home/$NEWUSERNAME/installer_errors.log
- #*************************************************************
- #*************************************************************
- # do grub ################################
- # was set earlier
- echo "$GRUBVERSION is installed"
- if [ "$GRUBINST" = "UEFI mode" ]; then #
- if [ -n "$EFI_PART" ]; then
- mkdir /target/boot/efi
- mount $EFI_PART /target/boot/efi
- chroot /target grub-install /dev/sda
- # add to installation's fstab
- EFI_PART_UUIDUUID=$(blkid -o value -s UUID $EFI_PART)
- echo -e "\n#efi partition" >>/target/etc/fstab
- echo -e "UUID=$EFI_PART_UUIDUUID /boot/efi vfat defaults 0 2" >>/target/etc/fstab
- umount $EFI_PART
- if [ -f /boot/efi/EFI/debian/grubx64.efi ]; then
- efi_msg="Grub-efi was installed"
- else
- efi_msg="Grub-efi bootloader installation failed. You will need to correct this manually."
- fi
- else
- echo "Error.. the EFI system partition was not detected"
- GRUBINST="Do not install grub"
- fi
- fi
- # this works on it's own, to get grub in mbr
- if [ "$GRUBINST" = $"MBR of first hard disk" ]; then
- chroot /target grub-install /dev/sda
- fi
- # this might write (hd1,whatever)" but should be (hd0,whatever)
- if [ "$GRUBINST" = $"MBR of installation disk" ]; then
- # get install device (e.g. /dev/sda)
- INSTALLDEV=$(echo $INSTALLPARTITION |sed 's:[0-9]::'g)
- chroot /target grub-install $INSTALLDEV
- fi
- if [ "$GRUBINST" = $"Installation partition" ]; then
- case "$GRUBVERSION" in
- grub-legacy|grub-gfxboot)
- # grub-install fails to a partition! gives "error 22: No such partition"
- # this will probable give error 22 but gets the files in /boot (grub shell might not)
- chroot /target grub-install $INSTALLPARTITION
- # isolate the device (sdx) letter then use tr like this to translate to the right number for grub
- GRUBDEVICENUM=$(echo $INSTALLPARTITION |sed 's:/dev/sd::' |sed 's:[0-9]::'g |tr '[a-j]' '[0-9]')
- # isolate the partition number
- INSTALLPARTNUM=$(echo $INSTALLPARTITION |sed 's:/dev/sd::'|sed 's:[a-z]::')
- # and reduce it by 1 for grub
- GRUBPARTNUM=$(expr $INSTALLPARTNUM - 1)
- # finally get the finished grub root syntax
- GRUBROOT="(hd$GRUBDEVICENUM,$GRUBPARTNUM)"
- # use grub shell in batch mode (grub-install fails to a partition)
- grub --batch <<EOF
- root $GRUBROOT
- setup $GRUBROOT
- quit
- EOF
- ;;
- grub-pc)
- # chroot /target /bin/bash grub-install --recheck --no-floppy --force $INSTALLPARTITION
- chroot /target grub-install --recheck --no-floppy --force $INSTALLPARTITION
- ;;
- *)
- echo "Error: Grub version not detected"
- ;;
- esac
- fi
- if [ "$GRUBINST" != "Do not install grub" ]; then
- chroot /target update-grub
- fi
- # update-grub-legacy is part of exegnu-scripts?
- if [ "$GRUBVERSION" = "grub-legacy" ] || [ "$GRUBVERSION" = "grub-gfxboot" ]; then
- if [ -f /usr/bin/update-grub-legacy ]; then
- update-grub-legacy /target/boot/grub/menu.lst
- fi
- fi
- if [ "$GRUBVERSION" = "grub-gfxboot" ]; then
- # for gfxboot only
- # default splash is "message.hd" but could be other... change here if needed
- GFXSPLASH=message.hd
- if [ -e /target/boot/$GFXSPLASH ]; then
- # adda line for the splash
- sed -i "/color/ a gfxmenu /boot/$GFXSPLASH" /target/boot/grub/menu.lst
- # hash out the "normal grub-legacy" colours
- sed -i "s|color cyan/blue white/blue|#color cyan/blue white/blue|" /target/boot/grub/menu.lst
- # just adds a space to make cmd line easy to edit
- sed -i "s|root=UUID=$INSTALLPARTITIONUUID ro|root=UUID=$INSTALLPARTITIONUUID ro |"g /target/boot/grub/menu.lst
- fi
- fi
- #*************************************************************
- #*************************************************************
- $DIALOG --$INFO --width=460 --height=200 --title="$TITLE" --text=$"Installation is done\! You may now reboot.\n\n\Please review \"/var/log/installer_errors.log\" for any error details\n\n\The error log was copied to the installation at /home/$NEWUSERNAME/installer_errors.log.\n\n\ $efi_msg"
- ### last few jobs ################################################################################
- # if grub failed (hung) at least we got everything else done
- # do this again, if grub failed at least we got everything else done
- #ERRORLOG="/var/log/installer_errors.log"
- # copy it to the install
- cp -a $ERRORLOG /target/home/$NEWUSERNAME/installer_errors.log
- chmod 666 /target/home/$NEWUSERNAME/installer_errors.log
- # clean up and umount
- rm -f /target/chrootscript /target/userinput ./userinput ./rsyncexcludes
- sleep 1
- umount /target/proc
- sleep 1
- umount /target/dev
- sleep 1
- umount /target/sys
- sleep 1
- umount /target/home
- sleep 1
- umount /target
- sleep 1
- rmdir /target
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement