Advertisement
Guest User

Untitled

a guest
Dec 21st, 2017
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # exegnu-installer
  4.  
  5. # HD installer for a generic Debian Live system OR a refractasnapshot-type Live system
  6.  
  7. # depends: zenity | yad, gparted
  8.  
  9. # Copyright: David Hare, April 2011
  10. # Copyright 2011 fsmithred@gmail.com
  11. # License: GPL-3
  12. # Credits to: fsmithred (refracta) and fragadelic (remastersys) for some parts of code used here.
  13. # Both have written good working installers.
  14. # Traducción (espanol): Alexis Puente Montiel, < alexispm_stellaluna@yahoo.es >
  15. # Trinity (kde3 fork) desktop and grub-legacy are supported
  16. # 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)
  17. # "new user config" mode means, it will behave as a normal debian-live image with whatever defaults are in /etc/skel
  18. # The intention is to minimise extra steps and cli work for the user (one script does all)
  19. # Script written for squeeze; wheezy/sid support....... depends who is on the case of maintaining it!
  20. # It should be run from a root terminal session. Zenity|yad dialogs are used.
  21.  
  22. # TODO : support for seperate /home /boot and encryption
  23. # TODO : write log file (without verbose rsync output)
  24.  
  25. # (for now) any customisation to new user's ~ need to be set in /etc/skel else you get Debian and desktop manager defaults
  26.  
  27. TEXTDOMAIN=exegnu-installer
  28. TEXTDOMAINDIR=/usr/share/locale/
  29.  
  30. ##USER EDITABLE VARS ##
  31.  
  32. # set the title for zenity|yad dialogs to whatever you want here but keep the quotes
  33. TITLE=$"Exe GNU/Linux Installer"
  34.  
  35. # if it's a snapshot, /etc/snapshotid must exist. (uncomment the next line if original refractasnapshot was used)
  36.  
  37. # echo "Generated by $TITLE for temporary use" > /etc/snapshotid
  38.  
  39. # use yad if exists else use zenity
  40. if [ -f /usr/bin/yad ]; then
  41. DIALOG=yad
  42. INFO="image=gtk-dialog-info"
  43. QUESTION="image=gtk-dialog-question"
  44. WARNING="image=gtk-dialog-warning"
  45. ERROR="image=gtk-dialog-error"
  46.  
  47. #buttons
  48. BUTTON0="button"
  49. BUTTON1="button"
  50. BUTTON0NUM=":0"
  51. BUTTON1NUM=":1"
  52. else
  53. DIALOG=zenity
  54. INFO=info
  55. QUESTION=question
  56. WARNING=warning
  57. ERROR=error
  58.  
  59. #buttons
  60. BUTTON0="ok-label"
  61. BUTTON1="cancel-label"
  62. BUTTON0NUM=""
  63. BUTTON1NUM=""
  64. fi
  65.  
  66. #################################################################################
  67.  
  68. # detect system language
  69. SCRIPTLANG=$(env | egrep 'LC|LANG' | grep -o 'es_')
  70.  
  71. #* check for root
  72. if [[ $EUID -ne 0 ]]; then
  73. $DIALOG --$ERROR --width=400 --height=160 --title="$TITLE" --text=$"\nThis installer must be run as Root\! \n\nCannot continue."
  74. exit 1
  75. fi
  76.  
  77. # LIVESESSIONCHECK
  78. #LIVESESSIONCHECK=$(cat /etc/passwd|grep 1000|grep Live)
  79. LIVESESSIONCHECK=$(cat /proc/cmdline | grep "boot=live")
  80.  
  81. # Make sure script can't run from a fixed installation
  82. #if [ "$LIVESESSIONCHECK" = "" ] && [ "$LIVESNAP" = "" ]; then
  83. if [ "$LIVESESSIONCHECK" = "" ]; then
  84. $DIALOG --$ERROR --width=400 --height=160 --title="$TITLE" --text=$"\nThis does not seem to be a Debian Live session\!\n\nCannot continue."
  85. exit 1
  86. fi
  87.  
  88. # identify if it's a snapshot, (/etc/snapshotid must exist)
  89. if [ -f /etc/snapshotid ]; then
  90. LIVESNAP=yes
  91. fi
  92.  
  93. #*************************************************************
  94.  
  95. #* intro
  96.  
  97. TEXT=$"\n\nThis Live system will be installed to hard disk.\n\nPartitioning and formatting will be necessary.\n\nDo you want to continue?"
  98.  
  99. $DIALOG --$QUESTION --width=460 --height=240 --title="$TITLE" --${BUTTON0}=$"Continue"${BUTTON0NUM} --${BUTTON1}=$"Exit now"${BUTTON1NUM} --text="$TEXT"
  100.  
  101. if [ "$?" = "1" ]; then
  102. exit 1
  103. fi
  104.  
  105. #*************************************************************
  106.  
  107. # write errors to log
  108. ERRORLOG="/var/log/installer_errors.log"
  109.  
  110. if [ -f "$ERRORLOG" ]; then truncate -s 0 $ERRORLOG; fi
  111.  
  112. exec 2>>"$ERRORLOG"
  113.  
  114. # FUTURE USE: zinstaller (thanks fsmithred) used this maybe something similar here?
  115. # exit on errors
  116. check_exit () {
  117. [[ $? -eq 0 ]] || { echo "
  118.  
  119. Exit due to error: $?
  120. See $ERRORLOG for details.
  121. " ; $DIALOG --$ERROR --text="Exit due to error: $?
  122. See $ERRORLOG for details." &
  123. exit 1 ; }
  124. }
  125.  
  126. # for zenity boxes, if no input was given, "try again or exit" box
  127. input_error () {
  128.  
  129. $DIALOG --$QUESTION --width=460 --title="$TITLE" --${BUTTON0}=$"Try again"${BUTTON0NUM} --${BUTTON1}=$"Quit the installer"${BUTTON1NUM} --text=$"Input error! Please try again"
  130.  
  131. if [[ $? -eq 1 ]]; then
  132. rm -f userinput
  133. exit 1
  134. else
  135. $REPEAT_FUNCTION
  136. fi
  137. }
  138.  
  139. #*************************************************************
  140.  
  141. # if it's a live snapshot, set snapshot install method
  142.  
  143. snap_method () {
  144.  
  145. TEXT=$"A \"Live Snapshot\" system is detected.\n\nPlease select the installation method:"
  146. OPTION1=$"Install to fixed disk with existing user configurations"
  147. OPTION2=$"Install to fixed disk with a new default user"
  148.  
  149. SNAPMETHOD=$($DIALOG --width=640 --height=200 --title="$TITLE" --list --column="" --column="" --hide-column=1 --print-column=1 --separator="" --text="$TEXT" "01" "$OPTION1" "02" "$OPTION2")
  150.  
  151. # if it did not get set (is blank)
  152. if [ "$SNAPMETHOD" = "" ]; then
  153. # set a new repeat_function for input_error function
  154. REPEAT_FUNCTION=snap_method
  155. # call "input error" function and repeat the dialog (or exit)
  156. input_error
  157. fi
  158. }
  159.  
  160. if [ "$LIVESNAP" = "yes" ]; then
  161. snap_method
  162.  
  163. if [ "$SNAPMETHOD" = "01" ]; then
  164. SNAPMETHOD=clone
  165. else
  166. SNAPMETHOD=newconfig
  167. fi
  168.  
  169. # if it's a live snapshot, some or all of these will be in /proc/cmdline
  170. CMDNOAUTOLOGIN=$(egrep noautologin /proc/cmdline)
  171. CMDNOSUDO=$(egrep nosudo /proc/cmdline)
  172. CMDNOUSER=$(egrep nouser /proc/cmdline)
  173. # else it's a generic debian-live
  174. fi
  175.  
  176. #*************************************************************
  177.  
  178. # before partitioning, find out now if a swap partition already exists
  179.  
  180. EXISTINGSWAP=$(blkid -o list |grep /dev |grep swap| awk '{print $1}' |sort)
  181.  
  182. #partitioning question
  183. TEXT=$"A disk partition formatted EXT2/3/4 and at least 3GB is required for this installation.\n\n\
  184. Optionally, a swap partition may be created at this time or an existing swap may be used \n\n\
  185. Optionally, a separate /home partition may be created \n\n\
  186. Even if partitions are already prepared, you should run GParted now to review their location and device names.\n\n\
  187. Run GParted Partition Editor now?"
  188.  
  189. $DIALOG --$QUESTION --width=460 --height=320 --title=$"Partitioning" --${BUTTON0}=$"Yes"${BUTTON0NUM} --${BUTTON1}="No"${BUTTON1NUM} --text="$TEXT"
  190.  
  191. if [[ $? = 0 ]] ; then
  192. gparted
  193. fi
  194.  
  195. ##########################################
  196.  
  197. # get user input for the installer variables to a file 'userinput'
  198. # it will get copied to and used in chroot later
  199.  
  200. # start with what's in the conf file
  201. echo "">userinput
  202. while read line; do echo "$line"|sed "s~^#.*~~">>userinput; done </etc/exegnu/exegnu-installer.conf
  203.  
  204. # get partition lists for zenity
  205.  
  206. # blkid can be unreliable used with awk if some devices have a label and some not... awk '{print $1}' always gets the device
  207.  
  208. # blkid -o value -s TAG ('/dev/sdbx' to specify a device) works, where TAG can be TYPE LABEL or UUID
  209. # "grep /dev/sd" excludes the headers
  210.  
  211.  
  212. # set / ($INSTALLPARTITION) function
  213. set_installpartition () {
  214.  
  215. INSTALLPARTITIONLIST=$(blkid -o list |grep /dev/sd|grep -v ntfs|grep -v vfat|grep -v swap|awk '{print $1}'|sort)
  216.  
  217. # check the partition is large enough?
  218. INSTALLPARTITION=$($DIALOG --width=460 --height=320 --title="$TITLE" --list --separator="" --column="" --text=$"Please select the root partition for the installed system" $INSTALLPARTITIONLIST)
  219.  
  220. # if it did not get set (is blank)
  221. if [ "$INSTALLPARTITION" = "" ]; then
  222. # set a new repeat_function for input_error function
  223. REPEAT_FUNCTION=set_installpartition
  224. # call "input error" function and repeat the dialog (or exit)
  225. input_error
  226. fi
  227. }
  228.  
  229. #run that function
  230. set_installpartition
  231. # write it to config file
  232. echo "INSTALLPARTITION=\"$INSTALLPARTITION\"" >>userinput
  233.  
  234. ##########################################
  235.  
  236. # set / ($HOMEPARTITION) function
  237. set_homepartition () {
  238.  
  239. HOMEPARTITIONLIST=$(blkid -o list |grep /dev/sd|grep -v ntfs|grep -v vfat|grep -v swap|grep -v "${INSTALLPARTITION} "|awk '{print $1}'|sort)
  240.  
  241. # check the partition is large enough?
  242. NO_HOME=$"Do not use a separate /home partition"
  243. 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)
  244.  
  245. }
  246.  
  247. set_homepartition
  248.  
  249. # write it to config file
  250. if echo $HOMEPARTITION|grep -q "/dev/sd[a-z][0-9]"; then
  251. echo "HOMEPARTITION=\"$HOMEPARTITION\"" >>userinput
  252. else
  253. # /home will be set on rootfs even if the dialog was cancelled without annswer
  254. HOMEPARTITION=${NO_HOME}
  255. fi
  256.  
  257. ##########################################
  258.  
  259. # set swap ($SWAPPARTITION)
  260. set_swappartition () {
  261.  
  262. SWAPPARTITIONLIST=$(blkid -o list|grep /dev/sd |grep swap|awk '{print $1}'|sort)
  263.  
  264. USE_SWAPFILE=$"Use a swap file"
  265. NO_SWAP=$"Do not configure swap"
  266. 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)
  267.  
  268. if [ "$SWAPPARTITION" = "" ]; then
  269. # set a new repeat_function for input_error function
  270. REPEAT_FUNCTION=set_swappartition
  271. # call "input error" function and repeat the dialog (or exit)
  272. input_error
  273. fi
  274.  
  275. }
  276.  
  277. #run that function
  278. set_swappartition
  279.  
  280. # write it to config file
  281. if [ "$SWAPPARTITION" != "$NO_SWAP" ] ; then
  282. echo "SWAPPARTITION=\"$SWAPPARTITION\"" >>userinput
  283. fi
  284.  
  285. ##########################################
  286.  
  287. # set filesystem root
  288. set_filesystem () {
  289. FSTYPE=$($DIALOG --width=460 --height=200 --title="$TITLE" --list --separator="" --column="" --text=$"Please select the required root filesystem" "ext3" "ext4")
  290.  
  291. if [ "$FSTYPE" = "" ]; then
  292. REPEAT_FUNCTION=set_filesystem
  293. input_error
  294. fi
  295. }
  296.  
  297. set_filesystem
  298. echo "FSTYPE=\"$FSTYPE\"" >>userinput
  299.  
  300. ##########################################
  301.  
  302. # set filesystem home
  303. set_filesystem_home () {
  304. FSTYPEHOME=$($DIALOG --width=460 --height=200 --title="$TITLE" --list --separator="" --column="" --text=$"Please select the required /home filesystem" "ext3" "ext4")
  305.  
  306. if [ "$FSTYPEHOME" = "" ]; then
  307. REPEAT_FUNCTION=set_filesystem_home
  308. input_error
  309. fi
  310. }
  311.  
  312. if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
  313. set_filesystem_home
  314. echo "FSTYPEHOME=\"$FSTYPEHOME\"" >>userinput
  315. fi
  316.  
  317. ##########################################
  318.  
  319. # set fs label root
  320.  
  321. set_fslabelroot () {
  322.  
  323. 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 ")
  324.  
  325. if ! [ "$FSLABELROOT" = "" ]; then
  326.  
  327. CHECK_LABEL_ROOT=$(blkid|grep LABEL=\"$FSLABELROOT\"|grep -v $INSTALLPARTITION)
  328.  
  329. if ! [ "$CHECK_LABEL_ROOT" = "" ]; then
  330.  
  331. REPEAT_FUNCTION=set_fslabelroot
  332.  
  333. TEXT=$"This label is already in use! Please try again"
  334.  
  335. $DIALOG --$QUESTION --${BUTTON0}=$"Try again"${BUTTON0NUM} --${BUTTON1}=$"Quit the installer"${BUTTON1NUM} --text="$TEXT"
  336.  
  337. if [[ $? -eq 1 ]]; then
  338. rm -f userinput
  339. exit 1
  340. else
  341. $REPEAT_FUNCTION
  342. fi
  343. fi
  344. fi
  345.  
  346. }
  347.  
  348. set_fslabelroot
  349. echo "FSLABELROOT=\"$FSLABELROOT\"" >>userinput
  350.  
  351. ##########################################
  352.  
  353. # set fs label home
  354.  
  355. set_fslabelhome () {
  356.  
  357. 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 ")
  358.  
  359. if ! [ "$FSLABELHOME" = "" ]; then
  360.  
  361. CHECK_LABEL_HOME=$(blkid|grep LABEL=\"$FSLABELHOME\"|grep -v $HOMEPARTITION)
  362.  
  363. if ! [ "$CHECK_LABEL_HOME" = "" ]; then
  364.  
  365. REPEAT_FUNCTION=set_fslabelhome
  366.  
  367. TEXT=$"This label is already in use! Please try again"
  368.  
  369. $DIALOG --$QUESTION ---${BUTTON0}=$"Try again"${BUTTON0NUM} --${BUTTON1}=$"Quit the installer"${BUTTON1NUM} --text="$TEXT"
  370.  
  371. if [[ $? -eq 1 ]]; then
  372. rm -f userinput
  373. exit 1
  374. else
  375. $REPEAT_FUNCTION
  376. fi
  377. fi
  378. fi
  379.  
  380. }
  381.  
  382. if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
  383. set_fslabelhome
  384. echo "FSLABELHOME=\"$FSLABELHOME\"" >>userinput
  385. fi
  386.  
  387. ##########################################
  388.  
  389.  
  390. # set user input configs, (but some not for a snapshot clone)
  391. if ! [ "$SNAPMETHOD" = "clone" ]; then
  392.  
  393. # set hostname
  394. set_hostname () {
  395. 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 ")
  396.  
  397. if [ "$NEWHOSTNAME" = "" ]; then
  398. REPEAT_FUNCTION=set_hostname
  399. input_error
  400. fi
  401. }
  402.  
  403. set_hostname
  404. echo "NEWHOSTNAME=\"$NEWHOSTNAME\"" >>userinput
  405.  
  406. ##########################################
  407.  
  408. # set username
  409. set_username () {
  410. 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 ")
  411.  
  412. if [ "$NEWUSERNAME" = "" ]; then
  413. REPEAT_FUNCTION=set_username
  414. input_error
  415. fi
  416. }
  417.  
  418. set_username
  419. echo "NEWUSERNAME=\"$NEWUSERNAME\"" >>userinput
  420.  
  421. ##########################################
  422.  
  423. # set "user full name"
  424. set_userfullname () {
  425. 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 ")
  426.  
  427. if [ "$NEWUSERREALNAME" = "" ]; then
  428. REPEAT_FUNCTION=set_userfullname
  429. input_error
  430. fi
  431. }
  432.  
  433. set_userfullname
  434. echo "NEWUSERREALNAME=\"$NEWUSERREALNAME\"" >>userinput
  435.  
  436. ##########################################
  437.  
  438. # set user password
  439. set_userpass () {
  440. # what is the point of starring out passwords now? the config file gets deleted later
  441. NEWUSERPASS=$($DIALOG --width=460 --height=160 --title="$TITLE" --entry --text=$"\nPlease enter a password for your new user\n")
  442.  
  443. if [ "$NEWUSERPASS" = "" ]; then
  444. REPEAT_FUNCTION=set_userpass
  445. input_error
  446. fi
  447. }
  448.  
  449. set_userpass
  450. echo "NEWUSERPASS=\"$NEWUSERPASS\"" >>userinput
  451.  
  452. ##########################################
  453.  
  454. # set root password
  455. set_rootpass () {
  456. NEWROOTPASS=$($DIALOG --width=460 --height=200 --title="$TITLE" --entry --text=$"\nPlease enter a root password for the installed system\n")
  457.  
  458. if [ "$NEWROOTPASS" = "" ]; then
  459. REPEAT_FUNCTION=set_rootpass
  460. input_error
  461. fi
  462. }
  463.  
  464. set_rootpass
  465. echo "NEWROOTPASS=\"$NEWROOTPASS\"" >>userinput
  466.  
  467. # set user choice for su/sudo (unless it's a snapshot "clone")
  468.  
  469. 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)?"
  470.  
  471. $DIALOG --$QUESTION --width=460 --height=320 --title="$TITLE" --${BUTTON0}=$"Disable sudo"${BUTTON0NUM} --${BUTTON1}=$"Use sudo"${BUTTON1NUM} --text="$TEXT"
  472.  
  473. if [ "$?" = 0 ]; then
  474. SUDOCONFIG=disabled
  475. SUDOCONFIG_TEXT=$"will be disabled"
  476. else
  477. SUDOCONFIG=enabled
  478. SUDOCONFIG_TEXT=$"will be enabled"
  479. fi
  480.  
  481. echo "SUDOCONFIG=\"$SUDOCONFIG\"" >>userinput
  482.  
  483. # end snapshot-clone conditional
  484. fi
  485.  
  486.  
  487. ## tzdata ################################
  488.  
  489. TZ=$(cat /etc/timezone)
  490. TEXT=$"The current default timezone is set to $TZ. \n\n\
  491. Local timezone can now be set in the terminal window. \n\n\
  492. Please cancel this dialog to use the current default"
  493.  
  494. $DIALOG --$QUESTION --width=460 --height=240 --title="$TITLE" --${BUTTON0}=$"Cancel"${BUTTON0NUM} --${BUTTON1}=$"Change timezone"${BUTTON1NUM} --text="$TEXT"
  495.  
  496. if [ "$?" = "1" ]; then
  497. dpkg-reconfigure tzdata
  498. fi
  499.  
  500. ##########################################
  501. ##########################################
  502.  
  503. # set grub install location
  504. configure_grub () {
  505.  
  506. # get grub version, we want to support all
  507. 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)
  508.  
  509. # detect uefi
  510. if [ -d /sys/firmware/efi ] && [ "$GRUBVERSION" = "grub-efi-amd64" ]; then
  511. booted_efi=yes
  512. EFI_PART=$(fdisk -l|grep "^/dev/sd[a-z][0-9]"|grep -m 1 "EFI"|awk '{print $1}')
  513. EFI_DISK=$(fdisk -l|grep "^/dev/sd[a-z][0-9]"|grep -m 1 "EFI"|sed 's~/dev/~~'|awk '{print $1}')
  514.  
  515. 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 "
  516.  
  517. GRUBINST=$($DIALOG --width=460 --height=400 --title="$TITLE" --list --separator="" --column="" --text="$TEXT" $"UEFI mode" $"Do not install Grub")
  518. else
  519. 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 "
  520.  
  521. 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")
  522.  
  523. fi
  524. if [ -z "$GRUBINST" ]; then
  525. REPEAT_FUNCTION=configure_grub
  526. input_error
  527. fi
  528. }
  529.  
  530. configure_grub
  531. # echo "GRUBVERS=\"$GRUBVERS\"" >>userinput
  532. echo "GRUBINST=\"$GRUBINST\"" >>userinput
  533.  
  534. ###################################################
  535.  
  536. # verify chosen settings
  537. # last chance to exit before something gets buggered (hopefully not)!
  538.  
  539. if [ "$SNAPMETHOD" = "clone" ]; then
  540.  
  541. TEXT=$"\nThe system will be installed to $INSTALLPARTITION, formatted to $FSTYPE\n\n\
  542. Usernames and passwords will be as in the live session\n\n\
  543. Grub bootloader will be installed to $GRUBINST\n\n\
  544. Disk formatting and Installation will now begin.\n\
  545. Please EXIT NOW if not ready to do this\!"
  546.  
  547. $DIALOG --$QUESTION --width=460 --height=240 --title=$"Please Review Settings" --${BUTTON0}=$"Continue"${BUTTON0NUM} --${BUTTON1}="Exit now"${BUTTON1NUM} --text="$TEXT"
  548.  
  549. if ! [[ $? = 0 ]] ; then
  550. rm -f userinput
  551. exit
  552. fi
  553. else
  554. if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
  555. # only include this if separate /home
  556. HOMECONFIG_TEXT=$"The /home partition will be $HOMEPARTITION, formatted to $FSTYPEHOME\n\n\
  557. The /home partition label will be '$FSLABELHOME'\n\n"
  558. fi
  559.  
  560. TEXT=$"\nThe system will be installed to $INSTALLPARTITION, formatted to $FSTYPE\n\n\
  561. The system partition label will be '$FSLABELROOT'\n\n\
  562. ${HOMECONFIG_TEXT}\
  563. The hostname will be '$NEWHOSTNAME'\n\n\
  564. The user name will be '$NEWUSERNAME'\n\n\
  565. The user's full name will be '$NEWUSERREALNAME'\n\n\
  566. The user password will be '$NEWUSERPASS'\n\n\
  567. The root password will be '$NEWROOTPASS'\n\n\
  568. Grub bootloader will be installed to $GRUBINST\n\n\
  569. Sudo $SUDOCONFIG_TEXT\n\n\
  570. Disk formatting and Installation will now begin.\n\n\
  571. Please EXIT NOW if not ready to do this\!\n"
  572.  
  573. $DIALOG --$QUESTION --width=640 --title=$"Please Review Settings" --${BUTTON0}=$"Continue"${BUTTON0NUM} --${BUTTON1}=$"Exit now"${BUTTON1NUM} --text="$TEXT"
  574.  
  575. if ! [[ $? = 0 ]] ; then
  576. rm -f userinput
  577. exit
  578. fi
  579. # end "clone" conditional
  580. fi
  581.  
  582. # Settings are now in file "./userinput" to be used later
  583.  
  584. #*************************************************************
  585.  
  586. # read chosen settings set by dialogs from file
  587. source ./userinput
  588.  
  589. # format /
  590. mke2fs -t $FSTYPE "$INSTALLPARTITION"
  591.  
  592. #tune2fs
  593. tune2fs -r 10000 "$INSTALLPARTITION"
  594.  
  595. # do labels
  596. if ! [ "$FSLABELROOT" = "" ]; then
  597. e2label $INSTALLPARTITION $FSLABELROOT
  598. fi
  599.  
  600. # make mountpoint and mount it
  601. mkdir /target
  602. mount "$INSTALLPARTITION" /target
  603.  
  604. # separate /home only
  605. if [ "$HOMEPARTITION" != "$NO_HOME" ] ; then
  606. mke2fs -t $FSTYPEHOME "$HOMEPARTITION"
  607. tune2fs -r 10000 "$HOMEPARTITION"
  608.  
  609. if ! [ "$FSLABELHOME" = "" ]; then
  610. e2label $HOMEPARTITION $FSLABELHOME
  611. fi
  612.  
  613. # mkdir /targethome
  614. # mount "$HOMEPARTITION" /targethome
  615.  
  616. mkdir /target/home
  617. mount "$HOMEPARTITION" /target/home
  618. fi
  619.  
  620. #*************************************************************
  621.  
  622. # sort swap
  623. case "$SWAPPARTITION" in
  624.  
  625. ${NO_SWAP})
  626. sleep 0
  627. ;;
  628.  
  629. ${USE_SWAPFILE})
  630.  
  631. # make a swapfile now
  632. # bollocks! "if" used like this makes the script think it's a conditional.....try it in quotes
  633. dd "if=/dev/zero" of=/target/swapfile bs=1048 count=256000
  634. mkswap /target/swapfile
  635. ;;
  636. *)
  637. # we are using a partition
  638. # what if swap exists? Why format? also, it might be already mounted and used in live session
  639.  
  640. # if it is formatted the uuid will change, then fstab will be wrong in another OS that uses it
  641. # but could still format with old uuid, first swapoff -a then mkswap $SWAPPARTITION -U <old_uuid>
  642.  
  643. if ! [ "$(blkid -o value -s TYPE $SWAPPARTITION)" = "swap" ]; then
  644. mkswap $SWAPPARTITION
  645. fi
  646. ;;
  647. esac
  648.  
  649. #*************************************************************
  650.  
  651. # make rsync excludes file
  652. cat > ./rsyncexcludes <<EOF
  653. - /dev/*
  654. - /cdrom/*
  655. - /media/*
  656. - /target
  657. - /swapfile
  658. - /mnt/*
  659. - /sys/*
  660. - /proc/*
  661. - /tmp/*
  662. - /live
  663. - /boot/grub/grub.cfg
  664. - /boot/grub/menu.lst
  665. - /boot/grub/device.map
  666. - /etc/udev/rules.d/70-persistent-cd.rules
  667. - /etc/udev/rules.d/70-persistent-net.rules
  668. - /etc/fstab
  669. - /etc/mtab
  670. - /home/snapshot/
  671. - /etc/snapshotid/
  672. - /var/tmp/*
  673. - /lib/live/mount/*
  674. - /etc/fstab.d/*
  675. - /run/*
  676.  
  677. - /lib/live/overlay
  678. - /lib/live/image
  679. - /lib/live/rootfs
  680. - /lib/live/mount
  681. - /lib/live/findiso
  682.  
  683. EOF
  684.  
  685. # copy the system
  686. rsync -a --progress / /target/ --exclude-from ./rsyncexcludes
  687.  
  688. #*************************************************************
  689.  
  690. # make some basic entries in myfs/dev so the system can boot properly before udev starts
  691. # rsync excluded /dev/*
  692.  
  693. mknod -m 622 /target/dev/console c 5 1
  694. mknod -m 666 /target/dev/null c 1 3
  695. mknod -m 666 /target/dev/zero c 1 5
  696. mknod -m 666 /target/dev/ptmx c 5 2
  697. mknod -m 666 /target/dev/tty c 5 0
  698. mknod -m 444 /target/dev/random c 1 8
  699. mknod -m 444 /target/dev/urandom c 1 9
  700. chown -v root:tty /target/dev/{console,ptmx,tty}
  701.  
  702. ln -sv /proc/self/fd /target/dev/fd
  703. ln -sv /proc/self/fd/0 /target/dev/stdin
  704. ln -sv /proc/self/fd/1 /target/dev/stdout
  705. ln -sv /proc/self/fd/2 /target/dev/stderr
  706. ln -sv /proc/kcore /target/dev/core
  707. ln -sv /run/shm /target/dev/shm
  708. mkdir -v /target/dev/pts
  709.  
  710. #*************************************************************
  711.  
  712. # post-install fixes start here
  713.  
  714. # get uuids for new fstab
  715.  
  716. INSTALLPARTITIONUUID=$(blkid -o value -s UUID $INSTALLPARTITION)
  717. HOMEPARTITIONUUID=$(blkid -o value -s UUID $HOMEPARTITION)
  718. SWAPPARTITIONUUID=$(blkid -o value -s UUID $SWAPPARTITION)
  719.  
  720. if [ "$HOMEPARTITION" = "$NO_HOME" ]; then
  721. sleep 0
  722. else
  723. HOMEHASH="# $HOMEPARTITION ( /home )"
  724. HOMECONFIG="UUID=$HOMEPARTITIONUUID /home $FSTYPEHOME relatime,errors=remount-ro 0 1"
  725. fi
  726.  
  727. if [ "$SWAPPARTITION" = "$NO_SWAP" ]; then
  728. sleep 0
  729. elif [ "$SWAPPARTITION" = "$USE_SWAPFILE" ]; then
  730. SWAPHASH="# /swapfile ( swap )"
  731. SWAPCONFIG="/swapfile swap swap defaults 0 0"
  732. else
  733. SWAPHASH="# $SWAPPARTITION ( swap )"
  734. SWAPCONFIG="UUID=$SWAPPARTITIONUUID none swap sw 0 0"
  735. fi
  736.  
  737. #make new fstab
  738. # not sure about the cdrom entry... should it be /dev/sr0? what if more than one exists? is cdrom entry necessary at all?
  739.  
  740. cat > /target/etc/fstab <<EOF
  741. # /etc/fstab: static file system information.
  742. #
  743. # Generated by $TITLE
  744. #
  745. # <file system> <mount point> <type> <options> <dump> <pass>
  746.  
  747. proc /proc proc defaults 0 0
  748.  
  749. # $INSTALLPARTITION ( / )
  750. UUID=$INSTALLPARTITIONUUID / $FSTYPE relatime,errors=remount-ro 0 1
  751.  
  752. $HOMEHASH
  753. $HOMECONFIG
  754.  
  755. $SWAPHASH
  756. $SWAPCONFIG
  757.  
  758. # cdrom
  759. /dev/cdrom /media/cdrom udf,iso9660 user,noauto,exec,utf8 0 0
  760.  
  761. EOF
  762.  
  763. # restore original inittab
  764. cp /target/usr/share/sysvinit/inittab /target/etc/inittab
  765.  
  766. # do hostname and hosts
  767. echo "$NEWHOSTNAME" > /target/etc/hostname
  768. echo "127.0.0.1 localhost" > /target/etc/hosts
  769. echo "127.0.0.1 $NEWHOSTNAME" >> /target/etc/hosts
  770. touch /target/etc/resolv.conf
  771.  
  772. # remove autologin (was set by live-config)
  773. # UNLESS it's a snapshot then "noxautoconfig nosudo noautologin nouser" will be in cmdline
  774. #
  775. # "egrep noautologin /proc/cmdline" to find out
  776.  
  777. if [ "$CMDNOAUTOLOGIN" = "" ];then
  778.  
  779. #gdm2
  780. if [ -f /target/etc/gdm/gdm.conf ]; then
  781. sed -i -e 's/AutomaticLogin/#AutomaticLogin/g' /target/etc/gdm/gdm.conf
  782. sed -i -e 's/TimedLogin/#TimedLogin/g' /target/etc/gdm/gdm.conf
  783. fi
  784.  
  785. #gdm3
  786. if [ -f /target/etc/gdm/gdm.conf ]; then
  787. sed -i -e 's/AutomaticLogin/#AutomaticLogin/g' /target/etc/gdm3/daemon.conf
  788. sed -i -e 's/TimedLogin/#TimedLogin/g' /target/etc/gdm3/daemon.conf
  789. fi
  790.  
  791. #lightdm
  792. if [ -f /target/etc/lightdm/lightdm.conf ]; then
  793. sed -i -e 's/autologin/#autologin/g' /target/etc/lightdm/lightdm.conf
  794. fi
  795.  
  796. #kde
  797. if [ -f /target/etc/default/kdm.d/live-autologin ]; then
  798. rm -f /target/etc/default/kdm.d/live-autologin
  799. fi
  800.  
  801. if [ -f /target/etc/kde3/kdm/kdmrc ]; then
  802. sed -i -e 's/AutoLogin/#AutoLogin/g' /target/etc/kde3/kdm/kdmrc
  803. sed -i -e 's/AutoReLogin/#AutoReLogin/g' /target/etc/kde3/kdm/kdmrc
  804. fi
  805.  
  806. if [ -f /target/etc/kde4/kdm/kdmrc ]; then
  807. sed -i -e 's/AutoLogin/#AutoLogin/g' /target/etc/kde4/kdm/kdmrc
  808. sed -i -e 's/AutoReLogin/#AutoReLogin/g' /target/etc/kde4/kdm/kdmrc
  809. fi
  810.  
  811. #kdm-trinity (=< TDE R13)
  812. if [ -f /target/etc/default/kdm-trinity.d/live-autologin ]; then
  813. rm -f /target/etc/default/kdm-trinity.d/live-autologin
  814. fi
  815.  
  816. if [ -f /target/etc/trinity/kdm/kdmrc ]; then
  817. sed -i -e 's/AutoLogin/#AutoLogin/g' /target/etc/trinity/kdm/kdmrc
  818. sed -i -e 's/AutoReLogin/#AutoReLogin/g' /target/etc/trinity/kdm/kdmrc
  819. fi
  820.  
  821. #tdm-trinity (=> TDE R14)
  822. if [ -f /target/etc/default/tdm-trinity.d/live-autologin ]; then
  823. rm -f /target/etc/default/tdm-trinity.d/live-autologin
  824. fi
  825.  
  826. if [ -f /target/etc/trinity/tdm/tdmrc ]; then
  827. sed -i -e 's/AutoLogin/#AutoLogin/g' /target/etc/trinity/tdm/tdmrc
  828. sed -i -e 's/AutoReLogin/#AutoReLogin/g' /target/etc/trinity/tdm/tdmrc
  829. fi
  830.  
  831. # console autologin
  832. # if grep -q "respawn:/bin/login -f" /target/etc/inittab ; then
  833. # mv /target/etc/inittab /target/etc/inittab.$(date +%Y%m%d_%H%M)
  834. # cp /usr/lib/refractainstaller/inittab.debian /target/etc/inittab
  835. # fi
  836. fi
  837. #*************************************************************
  838. #*************************************************************
  839.  
  840. # prepare for chroot
  841. #mount --bind /dev/ /target/dev/
  842. #mount --bind /proc/ /target/proc/
  843. #mount --bind /sys/ /target/sys/
  844.  
  845. for i in dev devpts proc sys; do
  846. mount --bind /$i/ /target/$i/
  847. done
  848.  
  849. ##########################################
  850.  
  851. # do grub later, one machine hung doing grub now, then the rest of the install was incomplete
  852.  
  853. #*************************************************************
  854. #*************************************************************
  855.  
  856. #get more stuff in /target ready for chroot
  857.  
  858. # add some extra vars to "userinput"
  859.  
  860. OLDUSERNAME=""`grep '^[^:]*:[^:]*:1000:' /target/etc/passwd | awk -F ":" '{ print $1 }' | sed s/,,,//`""
  861. echo "OLDUSERNAME=$OLDUSERNAME" >>userinput
  862.  
  863. # this may not be needed
  864. OLDUSERGROUP=$(cat /target/etc/group |grep 1000 | awk -F ":" '{ print $1 }')
  865. echo "OLDUSERGROUP=$OLDUSERGROUP" >>userinput
  866.  
  867. # groups for new user
  868. # DEFAULTGROUPS="audio,cdrom,crontab,dialout,disk,floppy,fuse,lp,video,plugdev,netdev,powerdev,scanner,ssh,video,users"
  869. DEFAULTGROUPS="audio,cdrom,dialout,floppy,plugdev,users,video"
  870.  
  871. echo "DEFAULTGROUPS=$DEFAULTGROUPS" >>userinput
  872. #
  873.  
  874.  
  875. # do we still need this for 3.5.13 ?
  876. # compatibility for older tde versions
  877.  
  878. if [ -f /opt/trinity/bin/kdesu ]; then
  879. TDESU_CONFIGFILE=kdesurc
  880. fi
  881.  
  882. if [ -f /opt/trinity/bin/tdesu ]; then
  883. TDESU_CONFIGFILE=tdesurc
  884. fi
  885.  
  886. echo "TDESU_CONFIGFILE=$TDESU_CONFIGFILE" >>userinput
  887.  
  888. # our userconfig file with the vars for chroot script
  889. cp -a userinput /target/userinput
  890.  
  891. #*************************************************************
  892.  
  893. # make a script for chroot and copy it to there
  894. cat > /target/chrootscript <<EOF
  895. #!/bin/bash
  896.  
  897. # this all to run in a chroot
  898. # these vars, get from config file made with zenity dialogs and copied to the chroot
  899.  
  900. # read the vars from the copied userinput file
  901. source ./userinput
  902.  
  903. # sort dpkg-divert done by live-config
  904. # must remove divert live files else errors overwriting them
  905.  
  906. if [ -f /usr/sbin/update-initramfs.debian ]; then
  907. rm -f /usr/sbin/update-initramfs
  908. dpkg-divert --remove --rename --quiet /usr/sbin/update-initramfs
  909. fi
  910.  
  911. if [[ -f /usr/sbin/update-initramfs.distrib ]] ; then
  912. rm -f /usr/sbin/update-initramfs
  913. dpkg-divert --remove --rename --quiet /usr/sbin/update-initramfs
  914. fi
  915.  
  916. if [ -f /usr/sbin/anacron.debian ]; then
  917. rm -f /usr/sbin/anacron
  918. dpkg-divert --remove --rename --quiet /usr/sbin/anacron
  919. fi
  920.  
  921. dpkg-divert --remove --rename --quiet /usr/lib/update-notifier/apt-check
  922.  
  923. update-initramfs -u
  924.  
  925. shadowconfig on
  926.  
  927. ######################################################
  928.  
  929. EOF
  930.  
  931. # append these to chroot script, except in snapshot-clone mode
  932.  
  933. if ! [ "$SNAPMETHOD" = "clone" ]; then
  934.  
  935. cat >> /target/chrootscript <<EOF
  936.  
  937. # delete old user, make new
  938. userdel -f -r $OLDUSERNAME
  939.  
  940. # userdel should have done this but it did not
  941. if cat /etc/group|grep -v users|grep $OLDUSERGROUP; then
  942. groupdel $OLDUSERGROUP
  943. fi
  944.  
  945. # might not be needed with live-config, it uses %sudo
  946. sed -i '/$OLDUSERNAME/d' /etc/sudoers
  947.  
  948. groupadd -g 1000 $NEWUSERNAME
  949. useradd -u 1000 -g 1000 -c "$NEWUSERREALNAME,,," -G $DEFAULTGROUPS -s /bin/bash -m $NEWUSERNAME
  950. echo -e "$NEWUSERPASS\n$NEWUSERPASS\n" | passwd $NEWUSERNAME
  951.  
  952. # add to supplementary groups, check they exist first
  953. for i in adm crontab disk fuse lp netdev powerdev scanner ssh
  954. do
  955. GROUPEXISTS=\$(cat /etc/group|sort|awk -F ":" '{print \$1}'|grep -o "\$i")
  956. if [ "\$GROUPEXISTS" = "" ]; then
  957. echo "Error. Group \$i does not exist"
  958. else
  959. echo "Adding new user to group \$i"
  960. usermod -a -G \$i $NEWUSERNAME
  961. fi
  962. done
  963.  
  964. # do root passwd
  965. echo -e "$NEWROOTPASS\n$NEWROOTPASS\n" | passwd root
  966.  
  967. # hostname and hosts file
  968. echo "$NEWHOSTNAME" > /etc/hostname
  969. echo "127.0.0.1 localhost" > /etc/hosts
  970. echo "127.0.0.1 $NEWHOSTNAME" >> /etc/hosts
  971.  
  972. # sort su/sudo
  973.  
  974. if [ -n "$TDESU_CONFIGFILE" ]; then
  975.  
  976. echo "[super-user-command]" >> /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
  977. echo "super-user-command=su" >> /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
  978. chown $NEWUSERNAME:$NEWUSERNAME /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
  979.  
  980. if [ "$SUDOCONFIG" = "enabled" ]; then
  981. sed -i 's/command=su/command=sudo/' /home/$NEWUSERNAME/.trinity/share/config/$TDESU_CONFIGFILE
  982. else
  983. if [ -f /var/lib/dpkg/info/kdesudo-trinity.list ]; then
  984. apt-get -y --force-yes purge kdesudo-trinity
  985. fi
  986.  
  987. if [ -f /var/lib/dpkg/info/tdesudo-trinity.list ]; then
  988. apt-get -y --force-yes purge tdesudo-trinity
  989. fi
  990. fi
  991. fi
  992.  
  993. #######################################
  994.  
  995. if [ "$SUDOCONFIG" = "disabled" ]; then
  996.  
  997. # wheezy live-config now uses /etc/sudoers.d
  998. if [ -e /etc/sudoers.d/live ]; then
  999. rm -f /etc/sudoers.d/live
  1000. fi
  1001.  
  1002. # fix gksu in user's home
  1003. if [ -f /home/"$NEWUSERNAME"/.gconf/apps/gksu/%gconf.xml ]; then
  1004. sed -i '/sudo-mode/s/true/false/' /home/"$NEWUSERNAME"/.gconf/apps/gksu/%gconf.xml
  1005. # TODO fix kde4 in user's home
  1006. fi
  1007.  
  1008. else
  1009. # NEWUSERNAME will use sudo so add him to sudo group
  1010. usermod -a -G sudo $NEWUSERNAME
  1011. fi
  1012.  
  1013. # OLDUSERNAME no longer exists so remove from /etc/sudoers
  1014. sed -i "s|$OLDUSERNAME ALL=(ALL) NOPASSWD: ALL||" /etc/sudoers
  1015.  
  1016. if [ -n $CUSTOM_SKEL ]; then
  1017.  
  1018. cp -R $CUSTOM_SKEL/. /home/$NEWUSERNAME
  1019. # sort ownership for /home/${NEWUSERNAME}
  1020. chown ${NEWUSERNAME}:${NEWUSERNAME} /home/${NEWUSERNAME} -R
  1021. fi
  1022.  
  1023.  
  1024. EOF
  1025.  
  1026. fi
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032. #*************************************************************
  1033. #*************************************************************
  1034.  
  1035. # run script in chroot using vars from copied "userinput"
  1036. chmod +x /target/chrootscript
  1037. chroot /target /bin/bash /chrootscript
  1038.  
  1039. #*************************************************************
  1040. #*************************************************************
  1041.  
  1042. # BUG
  1043. # got an error in "clone" mode, the hostname was set blank, don't know why. Quick fix:
  1044. if [ "$SNAPMETHOD" = "clone" ]; then
  1045. NEWHOSTNAME=$(cat /etc/hostname)
  1046. echo "$NEWHOSTNAME" > /target/etc/hostname
  1047. # in case we need it later
  1048. NEWUSERNAME=$OLDUSERNAME
  1049. fi
  1050.  
  1051. #*************************************************************
  1052. #*************************************************************
  1053.  
  1054. # not needed? $NEWUSERNAME is already sudo group member
  1055. #sed -i "s|$OLDUSERNAME ALL=(ALL) NOPASSWD: ALL|$NEWUSERNAME ALL=(ALL:ALL) ALL|" /target/etc/sudoers
  1056.  
  1057. rm -f /target/etc/blkid.tab
  1058. if [ -f /target/etc/blkid.tab.old ]; then
  1059. rm -f /target/etc/blkid.tab.old
  1060. fi
  1061.  
  1062. # fix new hostname for wicd
  1063. sed -i "s/dhcphostname = .*/dhcphostname = $NEWHOSTNAME/" /target/etc/wicd/wired-settings.conf
  1064.  
  1065. # pmount may be globally allowed in live system
  1066. sed 's:/dev/sd/:#/dev/sd:' /target/etc/pmount.allow
  1067.  
  1068. #ERRORLOG="/var/log/installer_errors.log"
  1069. # copy it to the install
  1070. cp -a $ERRORLOG /target/home/$NEWUSERNAME/installer_errors.log
  1071. chmod 666 /target/home/$NEWUSERNAME/installer_errors.log
  1072.  
  1073. #*************************************************************
  1074. #*************************************************************
  1075.  
  1076. # do grub ################################
  1077.  
  1078. # was set earlier
  1079. echo "$GRUBVERSION is installed"
  1080.  
  1081. if [ "$GRUBINST" = "UEFI mode" ]; then #
  1082.  
  1083. if [ -n "$EFI_PART" ]; then
  1084.  
  1085. mkdir /target/boot/efi
  1086. mount $EFI_PART /target/boot/efi
  1087. chroot /target grub-install /dev/sda
  1088. # add to installation's fstab
  1089. EFI_PART_UUIDUUID=$(blkid -o value -s UUID $EFI_PART)
  1090. echo -e "\n#efi partition" >>/target/etc/fstab
  1091. echo -e "UUID=$EFI_PART_UUIDUUID /boot/efi vfat defaults 0 2" >>/target/etc/fstab
  1092. umount $EFI_PART
  1093.  
  1094. if [ -f /boot/efi/EFI/debian/grubx64.efi ]; then
  1095. efi_msg="Grub-efi was installed"
  1096. else
  1097. efi_msg="Grub-efi bootloader installation failed. You will need to correct this manually."
  1098. fi
  1099. else
  1100. echo "Error.. the EFI system partition was not detected"
  1101. GRUBINST="Do not install grub"
  1102. fi
  1103. fi
  1104.  
  1105. # this works on it's own, to get grub in mbr
  1106. if [ "$GRUBINST" = $"MBR of first hard disk" ]; then
  1107. chroot /target grub-install /dev/sda
  1108. fi
  1109.  
  1110. # this might write (hd1,whatever)" but should be (hd0,whatever)
  1111. if [ "$GRUBINST" = $"MBR of installation disk" ]; then
  1112. # get install device (e.g. /dev/sda)
  1113. INSTALLDEV=$(echo $INSTALLPARTITION |sed 's:[0-9]::'g)
  1114. chroot /target grub-install $INSTALLDEV
  1115. fi
  1116.  
  1117. if [ "$GRUBINST" = $"Installation partition" ]; then
  1118.  
  1119. case "$GRUBVERSION" in
  1120.  
  1121. grub-legacy|grub-gfxboot)
  1122.  
  1123. # grub-install fails to a partition! gives "error 22: No such partition"
  1124.  
  1125. # this will probable give error 22 but gets the files in /boot (grub shell might not)
  1126. chroot /target grub-install $INSTALLPARTITION
  1127.  
  1128. # isolate the device (sdx) letter then use tr like this to translate to the right number for grub
  1129. GRUBDEVICENUM=$(echo $INSTALLPARTITION |sed 's:/dev/sd::' |sed 's:[0-9]::'g |tr '[a-j]' '[0-9]')
  1130.  
  1131. # isolate the partition number
  1132. INSTALLPARTNUM=$(echo $INSTALLPARTITION |sed 's:/dev/sd::'|sed 's:[a-z]::')
  1133.  
  1134. # and reduce it by 1 for grub
  1135. GRUBPARTNUM=$(expr $INSTALLPARTNUM - 1)
  1136.  
  1137. # finally get the finished grub root syntax
  1138. GRUBROOT="(hd$GRUBDEVICENUM,$GRUBPARTNUM)"
  1139.  
  1140. # use grub shell in batch mode (grub-install fails to a partition)
  1141. grub --batch <<EOF
  1142. root $GRUBROOT
  1143. setup $GRUBROOT
  1144. quit
  1145. EOF
  1146. ;;
  1147. grub-pc)
  1148. # chroot /target /bin/bash grub-install --recheck --no-floppy --force $INSTALLPARTITION
  1149. chroot /target grub-install --recheck --no-floppy --force $INSTALLPARTITION
  1150. ;;
  1151. *)
  1152. echo "Error: Grub version not detected"
  1153. ;;
  1154. esac
  1155.  
  1156. fi
  1157.  
  1158. if [ "$GRUBINST" != "Do not install grub" ]; then
  1159. chroot /target update-grub
  1160. fi
  1161.  
  1162. # update-grub-legacy is part of exegnu-scripts?
  1163. if [ "$GRUBVERSION" = "grub-legacy" ] || [ "$GRUBVERSION" = "grub-gfxboot" ]; then
  1164. if [ -f /usr/bin/update-grub-legacy ]; then
  1165. update-grub-legacy /target/boot/grub/menu.lst
  1166. fi
  1167. fi
  1168.  
  1169. if [ "$GRUBVERSION" = "grub-gfxboot" ]; then
  1170. # for gfxboot only
  1171. # default splash is "message.hd" but could be other... change here if needed
  1172. GFXSPLASH=message.hd
  1173.  
  1174. if [ -e /target/boot/$GFXSPLASH ]; then
  1175. # adda line for the splash
  1176. sed -i "/color/ a gfxmenu /boot/$GFXSPLASH" /target/boot/grub/menu.lst
  1177. # hash out the "normal grub-legacy" colours
  1178. sed -i "s|color cyan/blue white/blue|#color cyan/blue white/blue|" /target/boot/grub/menu.lst
  1179. # just adds a space to make cmd line easy to edit
  1180. sed -i "s|root=UUID=$INSTALLPARTITIONUUID ro|root=UUID=$INSTALLPARTITIONUUID ro |"g /target/boot/grub/menu.lst
  1181. fi
  1182. fi
  1183.  
  1184. #*************************************************************
  1185. #*************************************************************
  1186.  
  1187. $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"
  1188.  
  1189. ### last few jobs ################################################################################
  1190.  
  1191. # if grub failed (hung) at least we got everything else done
  1192.  
  1193. # do this again, if grub failed at least we got everything else done
  1194. #ERRORLOG="/var/log/installer_errors.log"
  1195. # copy it to the install
  1196. cp -a $ERRORLOG /target/home/$NEWUSERNAME/installer_errors.log
  1197. chmod 666 /target/home/$NEWUSERNAME/installer_errors.log
  1198.  
  1199. # clean up and umount
  1200. rm -f /target/chrootscript /target/userinput ./userinput ./rsyncexcludes
  1201. sleep 1
  1202. umount /target/proc
  1203. sleep 1
  1204. umount /target/dev
  1205. sleep 1
  1206. umount /target/sys
  1207. sleep 1
  1208. umount /target/home
  1209. sleep 1
  1210. umount /target
  1211. sleep 1
  1212. rmdir /target
  1213.  
  1214.  
  1215. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement