Advertisement
Guest User

Untitled

a guest
Sep 20th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.14 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. set -x
  3. version="Refracta Installer (Yad) 9.1.6-pre (20150920)"
  4. # Copyright 2011, 2012, 2013, 2014, 2015 fsmithred@gmail.com
  5. # Modified experimental version of Refracta Installer (Yad) 9.1.0 (20140327)
  6. # Based on refractainstaller-8.0.3 by Dean Linkous
  7. # License: GPL-3
  8. # This is free software with NO WARRANTY. Use at your own risk!
  9.  
  10.  
  11. # DESCRIPTION
  12. # This script is used for installing a live system to a hard drive. User
  13. # input is via popup windows created by yad. It should be run from
  14. # a terminal; if it's started from a menu item or a panel launcher, it
  15. # should be run in a persistent terminal, so that progress messages can
  16. # be seen and for user input in a few places.
  17. #
  18. # There are two modes for installation - Simple or Expert
  19. # Simple Mode:
  20. # Create rsync excludes file if default file is missing.
  21. # User can run partitioner inside the installer or skip it.
  22. # User selects partition for installation. Bootloader goes to /dev/sda.
  23. # Summary window asks to proceed with installation.
  24. # Stuff happens without interaction.
  25. #
  26. # Expert Mode:
  27. # User selects installation options - change username, select up to three
  28. # partitions (/, /boot, /home), select filesystem type for each partition,
  29. # choose whether to encrypt partitions or not, choose whether to write
  30. # random data or zeros to partitions.
  31. # User has option to exit and use custom excludes file.
  32. # User can run partitioner inside the installer.
  33. # Summary window asks to proceed with installation.
  34. # Stuff happens with some interaction (passwords, username, edit /etc/sudoers)
  35. #
  36. # Stuff:
  37. # Cleanup (in case of previous aborted run)
  38. # Create encrypted volumes *(Expert mode only)
  39. # Write random data or zeros *
  40. # Mount partition(s) and create filesystem(s)
  41. # Copy system with rsync
  42. # Create swapfile or use existing swap partition
  43. # Copy update-initramfs
  44. # Set up fstab
  45. # Set up crypttab *
  46. # Install bootloader
  47. # Cleanup
  48. # Change username and passwords, edit /etc/sudoers *
  49. # Re-enable update-db and freshclam, disable ssh root login.
  50.  
  51.  
  52. # If you want to change any defaults, change them in the configfile.
  53. # Default is /etc/refractainstaller.conf
  54. # If you want to use a different config file for testing, change this
  55. # variable. Normally, users should not edit anything in this script.
  56.  
  57.  
  58.  
  59. configfile="/etc/refractainstaller.conf"
  60.  
  61. if [[ -f $configfile ]]; then
  62. source $configfile
  63. else
  64. yad --title=Warning --window-icon=error \
  65. --button=Exit:0 \
  66. --text=$" Config file $configfile is missing.
  67. "
  68. echo $" Config file $configfile is missing."
  69. exit 1
  70. fi
  71.  
  72. # Record errors in a logfile.
  73. exec 2>"$error_log"
  74.  
  75. # greeter window title
  76. if [ -z "$window_title" ]; then
  77. window_title="$version"
  78. fi
  79.  
  80. show_help () {
  81. printf "$help_text"
  82. exit 0
  83. }
  84.  
  85. help_text=$"
  86. Usage: $0 [option]
  87.  
  88. Run refractainstaller-yad from a terminal with no options
  89. or select Refracta Installer from the System menu to install
  90. a running live-CD or live-usb-hdd to a hard drive.
  91.  
  92.  
  93. valid options:
  94. -h, --help show this help text
  95. -v, --version display the version information
  96. -d. --debug debug mode
  97.  
  98. "
  99.  
  100. while [[ $1 == -* ]]; do
  101. case "$1" in
  102.  
  103. -h|--help)
  104. show_help ;;
  105.  
  106. -v|--version)
  107. printf "\n$version\n\n"
  108. exit 0 ;;
  109.  
  110. -d|--debug)
  111. DEBUG="yes"
  112. break ;;
  113.  
  114. *)
  115. printf $"\t invalid option: $1 \n\n"
  116. printf $"\t Try: $0 -h for full help. \n\n"
  117. exit 1 ;;
  118. esac
  119. done
  120.  
  121. if [ "$debug" = "yes" ] || [ "$DEBUG" = "yes" ]; then
  122. set -x
  123. fi
  124.  
  125. # Check that xserver is running and user is root.
  126. [[ $DISPLAY ]] || { echo $"There is no xserver running. Exiting..." ; exit 1 ; }
  127. if [[ $(id -u) -ne 0 ]] ; then
  128. yad --title=Error --window-icon=error --text=$"
  129. You need to be root!
  130. "
  131. exit 1
  132. fi
  133.  
  134. #******************************************************************
  135.  
  136. # Make sure yad is installed, and check the version.
  137. if [[ -f /usr/bin/yad ]] ; then
  138. yadversion=$(yad --version | cut -d. -f2)
  139. if [[ $yadversion < 17 ]]; then
  140. yad --title=Error --window-icon=error --text="
  141. The version of Yad is too old. You need 0.17.1.1 or later. If Zenity
  142. is installed, you can run refractainstaller-gui instead.
  143. "
  144. echo "
  145. The version of Yad is too old. You need 0.17.1.1 or later. If Zenity
  146. is installed, you can run refractainstaller-gui instead.
  147. "
  148. exit 1
  149. fi
  150. else
  151. echo "Yad is not installed. Use refractainstaller-gui or refractainstaller instead.
  152. Exiting..."
  153. exit 1
  154. fi
  155.  
  156.  
  157. #******************************************************************
  158.  
  159.  
  160. if [[ ! -d /lib/live/mount/medium ]] && [[ ! -d /lib/live/mount/findiso ]] && [[ ! -d /lib/live/mount/fromiso ]]; then
  161. live_session_warning=$" ### WARNING: Not running from live-CD or live-USB ###
  162. ### or unsupported configuration. Be sure you know ###
  163. ### what you are doing. This may not work. ### "
  164. fi
  165.  
  166.  
  167. # Greeting window
  168. yad --title="$window_title" --width=480 --button=$"Simple installation":0 \
  169. --button=$"Expert installation":1 --button=Exit:2 \
  170. --text=$"$live_session_warning
  171.  
  172. This utility will install a running live-CD or live-USB to your hard drive.
  173.  
  174. This is free software that comes with no warranty or guarantee of any
  175. type, including but not limited to express, implied, merchantability or
  176. fitness of purpose.
  177.  
  178. Copyright 2011-2014 fsmithred@gmail.com,
  179. based on refractainstaller-8.0.3 by Dean Linkous. \n Version: $version \n\n\
  180. ${custom_text} \n
  181. "
  182. mode="$?"
  183. case $mode in
  184. 0) install="simple" ;;
  185. 1) install="expert" ;;
  186. 2) exit 0 ;;
  187. esac
  188.  
  189.  
  190. # determine grub version now, it gets used for installing the bootloader and
  191. # preventing simple install from using ext4 with grub-legacy or grub-gfx.
  192. grubversion=$(dpkg -l | egrep "ii|hi" | grep -v bin | grep -v doc | awk '$2 ~ "grub-[glp]" { print $2}')
  193. # grubversion="grub-legacy" # for testing, comment out the above line and uncomment this one
  194.  
  195.  
  196. # function to exit the script if there are errors
  197. check_exit () {
  198. exit_code="$?"
  199. if [[ $exit_code -ne 0 ]] ; then
  200. yad --question --title=$"Error" --window-icon=error --button=$"Continue":0 --button=$"Exit now":1 \
  201. --text=$"Error detected: $exit_code $error_message
  202. \nSee $error_log for details. \n\nThis may not be fatal.. Press \"Continue\" to proceed anyway"
  203.  
  204. if [[ $? -ne 0 ]] ; then
  205. cleanup
  206. exit 1
  207. fi
  208. fi
  209. }
  210.  
  211.  
  212. copy_excludes () {
  213. cat > "$rsync_excludes" <<EOF
  214. # It is safe to delete this file after installation.
  215.  
  216. - /dev/*
  217. - /cdrom/*
  218. - /media/*
  219. - /target
  220. - /swapfile
  221. - /mnt/*
  222. - /sys/*
  223. - /proc/*
  224. - /tmp/*
  225. - /live
  226. - /boot/grub/grub.cfg
  227. - /boot/grub/menu.lst
  228. - /boot/grub/device.map
  229. - /etc/udev/rules.d/70-persistent-cd.rules
  230. - /etc/udev/rules.d/70-persistent-net.rules
  231. - /etc/fstab
  232. - /etc/fstab.d
  233. - /etc/mtab
  234. - /home/snapshot/
  235. - /home/*/.gvfs
  236.  
  237. # Added for newer version of live-config/live-boot
  238. # in sid (to become Jessie)
  239. - /lib/live/overlay
  240. - /lib/live/image
  241. - /lib/live/rootfs
  242. - /lib/live/mount
  243. - /run/*
  244.  
  245. EOF
  246.  
  247. chmod 666 "$rsync_excludes"
  248. }
  249.  
  250.  
  251.  
  252. # Check that rsync excludes file exists, or create one.
  253. if ! [[ -f $rsync_excludes ]] ; then
  254. yad --title=Warning --window-icon=error \
  255. --button=Continue:0 --button=Exit:1 \
  256. --text=$" There is no rsync excludes file, or its name does not match what this script expects.
  257. You should continue and let the script create one, or if you have a custom excludes file,
  258. and you know what you're doing, you can exit the script and edit the
  259. rsync_excludes variable in $configfile so that it matches the name
  260. and path of your custom file.
  261.  
  262. If you have any other drives or partitions mounted that you don't want
  263. to be copied, unmount them or edit the excludes file to list them."
  264. if [[ $? = 0 ]] ; then
  265. rsync_excludes="$(pwd)/installer_exclude.list"
  266. copy_excludes
  267. echo $"@@@ copied excludes to $(pwd)" >> "$error_log"
  268. else
  269. exit 0
  270. fi
  271. fi
  272.  
  273.  
  274. # These set the default setting in the options window,
  275. # based on setting in config file. Simple Install does
  276. # what config file says.
  277. if [[ $run_preinstall = "yes" ]] ; then
  278. var15="TRUE"
  279. else
  280. var15="FALSE"
  281. fi
  282. if [[ $run_postinstall = "yes" ]] ; then
  283. var16="TRUE"
  284. else
  285. var16="FALSE"
  286. fi
  287.  
  288. pre_install_list=$(ls -m /usr/lib/refractainstaller/pre-install)
  289. post_install_list=$(ls -m /usr/lib/refractainstaller/post-install)
  290.  
  291. # Check for swap partition and set default option accordingly.
  292. if [[ $(blkid -c /dev/null | grep swap) ]] ; then
  293. var3="TRUE"
  294. else
  295. var3="FALSE"
  296. fi
  297.  
  298.  
  299. # Select expert installation options
  300. if [[ $install = "expert" ]]; then
  301. opts=$(yad --list --title=$"Installation Options" \
  302. --text=$"Check the options you want for the installation.\n
  303. If you don't understand an option, you probably don't need it.\n" \
  304. --checklist --column $"Choose" --column "":HD --column $"Option" \
  305. --width=590 --height=555 --button=OK:0 --button=Exit:1\
  306. FALSE 01 $"Create a separate /home partition" \
  307. FALSE 02 $"Create a separate /boot partition" \
  308. $var3 03 $"Use existing swap partition instead of swapfile." \
  309. FALSE 04 $"Encrypt the root filesystem (separate /boot required)" \
  310. FALSE 05 $"Encrypt the /home partition (separate /home required)" \
  311. FALSE 06 $"Write random data to encrypted partitions (more secure)" \
  312. FALSE 07 $"Write zeroes to all partitions (to erase previous data)" \
  313. FALSE 08 $"Do not install bootloader. I'll handle it myself." \
  314. FALSE 09 $"Do not format filesystems. I'll handle it myself." \
  315. TRUE 10 $"Use UUID in /etc/fstab. (Useful if drive order changes.)" \
  316. FALSE 11 $"Use filesystem labels (disk labels) in /etc/fstab." \
  317. TRUE 12 $"Disable automatic login to desktop." \
  318. TRUE 13 $"Disable automatic login to console. (sysvinit only)" \
  319. FALSE 14 $"Move selected directories to separate partitions." \
  320. $var15 15 $"Run pre-install scripts (listed below)
  321. $pre_install_list" \
  322. $var16 16 $"Run post-install scripts (listed below)
  323. $post_install_list")
  324.  
  325.  
  326. else
  327. # simple defaults
  328. use_uuid="yes"
  329. disable_auto_desktop="yes"
  330. disable_auto_console="yes"
  331.  
  332. fi
  333. if [[ $? = 1 ]] ; then
  334. exit 0
  335. fi
  336.  
  337. if $(echo $opts | grep -q 01); then
  338. sep_home="yes"
  339. fi
  340. if $(echo $opts | grep -q 02); then
  341. sep_boot="yes"
  342. fi
  343. if $(echo $opts | grep -q 03); then
  344. use_existing_swap="yes"
  345. fi
  346. if $(echo $opts | grep -q 04); then
  347. encrypt_os="yes"
  348. fi
  349. if $(echo $opts | grep -q 05); then
  350. encrypt_home="yes"
  351. fi
  352. if $(echo $opts | grep -q 06); then
  353. write_random="yes"
  354. fi
  355. if $(echo $opts | grep -q 07); then
  356. write_zero="yes"
  357. fi
  358. if $(echo $opts | grep -q 08); then
  359. bootloader="no"
  360. else
  361. bootloader="yes"
  362. fi
  363. if $(echo $opts | grep -q 09); then
  364. if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then
  365. no_format=""
  366. else
  367. no_format="yes"
  368. fi
  369. fi
  370. if $(echo $opts | grep -q 10) || [ "$use_uuid" = "yes" ]; then
  371. if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then
  372. uuid_message=$"--> UUIDs in fstab won't work with encrypted filesystems and
  373. will not be used. Edit fstab manually after the installation."
  374.  
  375. else
  376. use_uuid="yes"
  377. fi
  378. fi
  379. if $(echo $opts |grep -q 11) || [ "$use_labels" = "yes" ]; then
  380. if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then
  381. disklabel_message=$"--> Disk labels in fstab won't work with encrypted filesystems and
  382. will not be used. Edit fstab manually after the installation."
  383. else
  384. use_uuid="no"
  385. use_labels="yes"
  386. fi
  387. fi
  388.  
  389. if $(echo $opts | grep -q 12); then
  390. disable_auto_desktop="yes"
  391. fi
  392. if $(echo $opts | grep -q 13); then
  393. disable_auto_console="yes"
  394. fi
  395. if $(echo $opts | grep -q 14); then
  396. if ! [[ -h /usr/lib/refractainstaller/post-install/move-dir-mount-gui.sh ]] ; then
  397. ln -s /usr/lib/refractainstaller/move-dir-mount-gui.sh /usr/lib/refractainstaller/post-install/move-dir-mount-gui.sh
  398. fi
  399. separate_partition_message=$"At the end of the installation, you will be given a chance to move selected directories to separate partitions."
  400. else
  401. if [[ -h /usr/lib/refractainstaller/post-install/move-dir-mount-gui.sh ]] ; then
  402. rm /usr/lib/refractainstaller/post-install/move-dir-mount-gui.sh
  403. fi
  404. fi
  405. if $(echo $opts | grep -q 15); then
  406. run_preinstall="yes"
  407. else
  408. run_preinstall="no"
  409. fi
  410. if $(echo $opts | grep -q 16); then
  411. run_postinstall="yes"
  412. else
  413. run_postinstall="no"
  414. fi
  415.  
  416.  
  417. if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then
  418. # test for cryptsetup
  419. if ! [[ -f /sbin/cryptsetup ]] ; then
  420. yad --title=Error --window-icon=error \
  421. --button=$"Proceed without encrypting partitions":0 \
  422. --button=Exit:1 --text=$"You need to install cryptsetup and run the command, 'sudo modprobe dm-mod' before you can use encryption."
  423. if [[ $? = 0 ]] ; then
  424. encrypt_os="no"
  425. encrypt_home="no"
  426. else
  427. exit 1
  428. fi
  429. fi
  430. # end test for cryptsetup
  431. fi
  432.  
  433.  
  434. ## Partition a disk ##### Simple install now does get to partition the disk - uncomment the conditional below to change it back.
  435. #if [[ $install = "expert" ]]; then
  436. yad --title=Partitioning --button=$"Run GParted":0 --button=$"Run cfdisk":1 \
  437. --width=650 --button=$"Skip this step":2 --button=Exit:3 \
  438. --text=$" You need to have at least one partition ready for the installation, plus one for each separate
  439. partition that you chose. If you already have the partition(s) ready, you can skip this step.
  440.  
  441. Run the partitioner now?"
  442.  
  443. ans="$?"
  444. case $ans in
  445. 0) gparted ;;
  446. 1) xterm -fa monaco -fs 12 -geometry 90x20+0+0 -hold -e cfdisk ;;
  447. 2) ;;
  448. 3) exit 0 ;;
  449. esac
  450. #fi
  451.  
  452. # # test to make sure there's a separate /boot partition
  453. if [[ $sep_boot = "no" ]]; then
  454. if [[ $encrypt_os = "yes" ]]; then
  455. yad --window-icon=error --title=Error \
  456. --button=$"Proceed without encrypting partition":0 \
  457. --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."
  458. if [[ $? = 0 ]] ; then
  459. encrypt_os="no"
  460. else
  461. exit 1
  462. fi
  463. fi
  464. fi
  465.  
  466.  
  467. # Find hard drives, and choose one for grub
  468. choose_grub () {
  469. yad --title=$"Install GRUB bootloader" --text=$" Choose a location to install the GRUB bootloader. The usual choice is to
  470. put it in the master boot record of the first hard drive (/dev/sda).
  471.  
  472. Choose MBR to install to the mbr of any hard disk.
  473. Choose Partition to install to a partition.
  474. Choose No Bootloader to proceed without a bootloader.
  475. Choose Exit to exit this program.
  476. " \
  477. --button=MBR:0 --button=Partition:1 --button=$"No Bootloader":2 --button=Exit:3
  478. answer="$?"
  479.  
  480. if [[ $answer = 0 ]] ; then
  481. grub_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z]" \
  482. | sort | awk '{print "\n" $0 }' \
  483. | yad --list --separator="" --title=Bootloader --text=$"Choose a location to install the bootloader.
  484. " \
  485. --column ' ' --column 'Hard Drives' --height=200)
  486.  
  487. if [[ -z $grub_dev ]] ; then
  488. yad --title=Error --window-icon=error --button=$"Yes, I'm sure.":0 --button=$"Go back":1 \
  489. --text=$"No bootloader will be installed. Are you sure you want this?"
  490. if [[ $? = 1 ]] ; then
  491. choose_grub
  492. fi
  493. elif ! [[ -b $grub_dev ]] ; then
  494. yad --title=Error --window-icon=error --button=Exit:0 --button=$"Go back":1 \
  495. --text=$"Something is wrong. $grub_dev is not a block device."
  496. if [[ $? = 0 ]] ; then
  497. exit 1
  498. else
  499. choose_grub
  500. fi
  501. fi
  502.  
  503. elif [[ $answer = 1 ]] ; then
  504. grub_partition=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
  505. | sort | awk '{print "\n" $0 }' \
  506. | yad --list --title=$"Bootloader" --text=$"Select a partition for the bootloader (GRUB)." \
  507. --separator="" --column ' ' --column $'Partitions' --height=380 --width=150)
  508.  
  509. if [[ -z $grub_partition ]] ; then
  510. yad --title=Error --window-icon=error --button=$"Yes, I'm sure.":0 --button=$"Go back":1 \
  511. --text=$"No bootloader will be installed. Are you sure you want this?"
  512. if [[ $? = 1 ]] ; then
  513. choose_grub
  514. fi
  515. elif ! [[ -b $grub_partition ]] ; then
  516. yad --title=Error --window-icon=error --button=Exit:0 --button="Go back":1 \
  517. --text=$"Something is wrong. $grub_partition is not a block device."
  518. if [[ $? = 0 ]] ; then
  519. exit 1
  520. else
  521. choose_grub
  522. fi
  523. fi
  524.  
  525.  
  526. elif [[ $answer = 2 ]] ; then
  527. yad --title=Bootloader --text=$" Proceeding without a bootloader.
  528. You will need to do special things to boot your operating system. Be sure
  529. that you know what you're doing." \
  530. --button=Proceed:0 --button=Exit:1
  531. if [[ $? = 1 ]] ; then
  532. exit 0
  533. fi
  534. elif [[ $answer = 3 ]] ; then
  535. exit 0
  536. fi
  537. }
  538.  
  539. ### Simple install gets default grub bootloader in /dev/sda
  540. if [[ $install = "expert" ]]; then
  541. if [[ $bootloader = "yes" ]]; then
  542. choose_grub
  543. fi
  544. fi
  545.  
  546. if [[ $install = "simple" ]]; then
  547. grub_dev="/dev/sda"
  548. fi
  549.  
  550.  
  551. # Show output of blkid for reference.
  552. #xterm -fa monaco -fs 12 -geometry 90x20+0+0 -hold -e 'echo "Partition list (for reference.) You may need this later." && blkid -c /dev/null' &
  553. blkid -c /dev/null | yad --text-info --title=$"Partition List" --text=$"Partition list (for reference.) You may need this later." \
  554. --width 820 --height 400 --button=$"Close window":0 &
  555. sleep 2
  556.  
  557. # Show the partition list in a menu, and choose one for /boot
  558. choose_boot () {
  559. boot_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
  560. | sort | awk '{print "\n" $0 }' \
  561. | yad --list --title=$"/boot partition" --text=$"Select a partition for /boot." \
  562. --separator="" --column ' ' --column $'Partitions' --height=380 --width=150 --button="OK":0)
  563. }
  564.  
  565. if [[ $sep_boot = "yes" ]]; then
  566. choose_boot
  567. fi
  568.  
  569. # Choose filesystem type for /boot
  570. choose_fs_boot () {
  571. if [[ -n $boot_dev ]]; then
  572. fs_type_boot=$(yad --list --title=$"/boot filesystem" --text=$"What type of filesystem would you like on $boot_dev?" \
  573. --separator="" --column $"Format" --height=200 --button="OK":0 \
  574. "ext2" \
  575. "ext3" \
  576. "ext4")
  577. fi
  578.  
  579. if [[ -z $fs_type_boot ]]; then
  580. yad --window-icon=error --title=Error --button=$"Go back":0 --button=Exit:1 \
  581. --text=$"You must choose a file system type for /boot"
  582. if [[ $? = 0 ]]; then
  583. choose_fs_boot
  584. else
  585. exit 1
  586. fi
  587. fi
  588. }
  589.  
  590. if [[ -n $boot_dev ]]; then
  591. if [[ $no_format = "yes" ]]; then
  592. fs_type_boot=$(blkid -s TYPE "$boot_dev" | awk -F"\"" '{ print $2 }')
  593. else
  594. choose_fs_boot
  595. fi
  596. fi
  597.  
  598.  
  599. # Show the partition list in a menu, and choose one for the OS
  600. choose_root () {
  601. install_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
  602. | sort | awk '{print "\n" $0 }' \
  603. | yad --list --title=$"Root Partition" --text=$"Choose a partition to use for the installation of the operating system." \
  604. --separator="" --column ' ' --column $'Partitions' --height 380 --width 150 --button="OK":0)
  605.  
  606. if [[ -z $install_dev ]] ; then
  607. yad --window-icon=error --title=Error --button="Go back":0 --button=Exit:1 \
  608. --text=$"Nothing was selected. You must select a partition for the installation. What would you like to do?"
  609. if [[ $? = 0 ]] ; then
  610. choose_root
  611. else
  612. exit 1
  613. fi
  614. elif ! [[ -b $install_dev ]] ; then
  615. yad --window-icon=error --title=Error --button="Go back":0 --button=Exit:1 \
  616. --text=$" Something is wrong. Maybe you checked
  617. more than one box. You said you want to install
  618. the system to $install_dev"
  619. if [[ $? = 0 ]] ; then
  620. choose_root
  621. else
  622. exit 1
  623. fi
  624. elif
  625. [[ $install_dev = $boot_dev ]] ; then
  626. yad --window-icon=error --title=Error --text=$"You chose the same partition for the operating system as the one for /boot. Try again." --button="OK":0
  627. choose_root
  628. fi
  629. }
  630.  
  631. choose_root
  632.  
  633.  
  634. # Choose filesystem type for OS.
  635. choose_fs_os () {
  636. fs_type_os=$(yad --list --title=$"Root Filesystem" --text=$"What type of filesystem would you like on $install_dev?" \
  637. --separator="" --column $"Format" --height=200 --button="OK":0 \
  638. "ext2" \
  639. "ext3" \
  640. "ext4")
  641. if [[ -z $fs_type_os ]]; then
  642. yad --window-icon=error --title=Error --button="Go back":0 --button=Exit:1 \
  643. --text=$"You must choose a file system type
  644. for the operating system"
  645. if [[ $? = 0 ]]; then
  646. choose_fs_os
  647. else
  648. exit 1
  649. fi
  650. fi
  651. }
  652.  
  653.  
  654. ### Simple install gets default ext4 filesystem (or ext3 with older grub)
  655. if [[ $install = "expert" ]]; then
  656. if [[ $no_format = "yes" ]]; then
  657. fs_type_os=$(blkid -s TYPE "$install_dev" | awk -F"\"" '{ print $2 }')
  658. else
  659. choose_fs_os
  660. fi
  661. else
  662. if [[ $grubversion = "grub-pc" ]] ; then
  663. fs_type_os="ext4"
  664. else
  665. fs_type_os="ext3"
  666. fi
  667. fi
  668.  
  669.  
  670.  
  671. # Show the partition list in a menu, and choose one for /home
  672. choose_home () {
  673. home_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
  674. | sort | awk '{print "\n" $0 }' \
  675. | yad --list --title=$"/home partition" --text=$"Select a partition for /home" \
  676. --separator="" --column ' ' --column $'Partitions' --height=380 --width=150 --button="OK":0)
  677. if [[ -n $home_dev ]] ; then
  678. if ! [[ -b $home_dev ]] ; then
  679. yad --info --title=Error --button="Go back":0 --button=Exit:1 \
  680. --text=$" Something is wrong.
  681. $home_dev is not a block device. "
  682. if [[ $? = 0 ]] ; then
  683. choose_home
  684. else
  685. exit 1
  686. fi
  687. elif
  688. [[ $install_dev = $home_dev ]] ; then
  689. yad --window-icon=error --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." \
  690. --button=$"Go back":0 --button=Exit:1
  691. if [[ $? = 0 ]] ; then
  692. choose_home
  693. else
  694. exit 1
  695. fi
  696. elif
  697. [[ $boot_dev = $home_dev ]] ; then
  698. yad --window-icon=error --title=Error --text=$"You chose the same partition for /home as the one for /boot. Try again." \
  699. --button=$"Go back":0 --button=Exit:1
  700. if [[ $? = 0 ]] ; then
  701. choose_home
  702. else
  703. exit 1
  704. fi
  705. fi
  706. fi
  707. }
  708.  
  709. if [[ $sep_home = "yes" ]]; then
  710. choose_home
  711. fi
  712.  
  713.  
  714. # Choose filesystem type for /home
  715. choose_fs_home () {
  716. if [[ -n $home_dev ]]; then
  717. fs_type_home=$(yad --list --title=$"/home filesystem" --text=$"What type of filesystem would you like on $home_dev?" \
  718. --separator="" --column $"Format" --height=200 --button="OK":0 \
  719. "ext2" \
  720. "ext3" \
  721. "ext4")
  722. fi
  723.  
  724. if [[ -z $fs_type_home ]]; then
  725. yad --window-icon=error --title=Error --button="Go back":0 --button=Exit:1 \
  726. --text=$"You must choose a file system type for /home"
  727. if [[ $? = 0 ]]; then
  728. choose_fs_home
  729. else
  730. exit 1
  731. fi
  732. fi
  733. }
  734.  
  735. if [[ -n $home_dev ]]; then
  736. if [[ $no_format = "yes" ]]; then
  737. fs_type_home=$(blkid -s TYPE "$home_dev" | awk -F"\"" '{ print $2 }')
  738. else
  739. choose_fs_home
  740. fi
  741. fi
  742.  
  743.  
  744. # Show the partition list in a menu, and choose one for swap
  745. choose_swap () {
  746. swap_info=$(/sbin/blkid |grep swap | awk '{print "\n" $0 }'\
  747. | yad --list --title=$"swap partition" --text=$"Select a partition for swap." \
  748. --separator="" --column ' ' --column $'Partitions' --height=180 --width=600 --button="OK":0)
  749. swap_dev=$(echo $swap_info | awk -F: '{ print $1 }')
  750. if [[ -z $swap_dev ]] ; then
  751. yad --window-icon=error --title=Error --text=$"You did not choose a swap partition.
  752. Click OK to use a swapfile instead.
  753. Click Cancel to exit the program."
  754. if [[ $? = 0 ]] ; then
  755. use_existing_swap=""
  756. else
  757. exit 1
  758. fi
  759. fi
  760. }
  761.  
  762.  
  763. if [[ $use_existing_swap = "yes" ]]; then
  764. choose_swap
  765. fi
  766.  
  767.  
  768.  
  769.  
  770.  
  771. # Show a summary of what will be done
  772. # if [[ $change_user = "yes" ]]; then
  773. # user_message=$"--> User name will be changed."
  774. # fi
  775.  
  776. if [[ -n $grub_dev ]] ; then
  777. grub_dev_message=$"--> Bootloader will be installed in $grub_dev"
  778. elif [[ -n $grub_partition ]] ; then
  779. grub_dev_message=$"--> Bootloader will be installed in $grub_partition"
  780. else
  781. grub_dev_message=$"--> Bootloader will not be installed."
  782. fi
  783.  
  784. if [[ $encrypt_os = yes ]] ; then
  785. os_enc_message=$", and will be encrypted."
  786. fi
  787.  
  788. if [[ -z $home_dev ]] ; then
  789. home_dev_message=$"--> /home will not be on a separate partition."
  790. elif
  791. [[ $no_format = "yes" ]]; then
  792. home_dev_message=$"--> /home will be installed on $home_dev"
  793. else
  794. home_dev_message=$"--> /home will be installed on $home_dev and formatted as $fs_type_home"
  795. fi
  796.  
  797. if [[ -n $home_dev ]] && [[ $encrypt_home = yes ]] ; then
  798. home_enc_message=$", and will be encrypted."
  799. fi
  800.  
  801. if [[ -n $boot_dev ]] ; then
  802. if [[ $no_format != "yes" ]]; then
  803. boot_dev_message=$"--> /boot will be installed on $boot_dev and formatted as $fs_type_boot."
  804. else
  805. boot_dev_message=$"--> /boot will be installed on $boot_dev"
  806. fi
  807. fi
  808.  
  809. if [[ $encrypt_os = yes ]] || [[ $encrypt_home = yes ]] ; then
  810. proceed_message=$"*** IF YOU PROCEED, YOU WILL NEED TO RESPOND TO SOME QUESTIONS IN THE TERMINAL. Be prepared to create
  811. passphrases for any encrypted partitions (several times each.) When you see the progress bar come up, you can take a break."
  812. fi
  813.  
  814. if [[ $disable_auto_desktop = "yes" ]]; then
  815. desktop_message=$"Desktop autologin will be disabled."
  816. fi
  817.  
  818. if [[ $disable_auto_console = "yes" ]]; then
  819. console_message=$"Console autologin will be disabled."
  820. fi
  821.  
  822. if [[ $no_format = "yes" ]]; then
  823. install_dev_message=$"--> Operating system will be installed on $install_dev, and you will (or did) format it manually."
  824. else
  825. install_dev_message=$"--> Operating system will be installed on $install_dev and formatted as $fs_type_os$os_enc_message"
  826. fi
  827.  
  828. if [[ $run_preinstall = "yes" ]] ; then
  829. preinstall_message=$"pre-install scripts are enabled."
  830. else
  831. preinstall_message=$"pre-install scripts are disabled."
  832. fi
  833. if [[ $run_postinstall = "yes" ]] ; then
  834. postinstall_message=$"post-install scripts are enabled."
  835. else
  836. postinstall_message=$"post-install scripts are disabled."
  837. fi
  838.  
  839.  
  840. yad --info --title=Summary --button=$"Proceed with the installation.":0 --button="Exit":1 \
  841. --text=$"Please CLOSE any running applications NOW.
  842.  
  843. Here is a summary of what will be done. THIS IS YOUR LAST CHANCE TO EXIT before any changes are made to the disk.
  844.  
  845. $grub_dev_message
  846. $install_dev_message$os_enc_message
  847. $home_dev_message$home_enc_message
  848. $boot_dev_message
  849. $desktop_message
  850. $console_message
  851. $uuid_message
  852. $disklabel_message
  853. $preinstall_message
  854. $postinstall_message
  855. $separate_partition_message
  856.  
  857. $proceed_message"
  858. if [[ $? != 0 ]] ; then
  859. exit 0
  860. fi
  861.  
  862.  
  863. # Actual installation begins here
  864.  
  865.  
  866. # Run pre-install scripts if enabled.
  867. if [[ $run_preinstall = "yes" ]] ; then
  868. for file in /usr/lib/refractainstaller/pre-install/* ; do
  869. if [[ -x $file ]] ; then
  870. bash $file
  871. fi
  872. done
  873. fi
  874.  
  875.  
  876. # Unmount or close anything that might need unmounting or closing
  877. cleanup () {
  878. echo -e "\n @@@ Cleaning up...\n" >> "$error_log"
  879. if $(df | grep -q /target/proc/) ; then
  880. umount /target/proc/
  881. fi
  882.  
  883. if $(df | grep -q /target/dev/) ; then
  884. umount /target/dev/
  885. fi
  886.  
  887. if $(df | grep -q /target/sys/) ; then
  888. umount /target/sys/
  889. fi
  890.  
  891. # grep gives an error if $boot_dev is null
  892. if $(df | grep -q $boot_dev) ; then
  893. umount -l $boot_dev
  894. fi
  895.  
  896. if $(df | grep -q /target_boot) ; then
  897. umount -l /target_boot/
  898. fi
  899.  
  900. if $(df | grep -q /target_home) ; then
  901. umount -l /target_home/
  902. fi
  903.  
  904. # grep gives an error if $home is null
  905. if $(df | grep -q $home_dev) ; then
  906. umount $home_dev
  907. fi
  908.  
  909. if $(df | grep -q "\/dev\/mapper\/home_fs") ; then
  910. umount /dev/mapper/home_fs
  911. fi
  912.  
  913. if [[ -h /dev/mapper/home_fs ]] ; then
  914. cryptsetup luksClose home_fs
  915. fi
  916.  
  917. if $(df | grep -q /target) ; then
  918. umount -l /target/
  919. fi
  920.  
  921. if $(df | grep -q $install_dev) ; then
  922. umount $install_dev
  923. fi
  924.  
  925. if $(df | grep "\/dev\/mapper\/root_fs") ; then
  926. umount /dev/mapper/root_fs
  927. fi
  928.  
  929. if [[ -h /dev/mapper/root_fs ]] ; then
  930. cryptsetup luksClose /dev/mapper/root_fs
  931. fi
  932.  
  933.  
  934. # These next ones might be unnecessary
  935. if [[ -d /target ]] ; then
  936. rm -rf /target
  937. fi
  938.  
  939. if [[ -d /target_home ]] ; then
  940. rm -rf /target_home
  941. fi
  942.  
  943. if [[ -d /target_boot ]] ; then
  944. rm -rf /target_boot
  945. fi
  946. }
  947.  
  948. cleanup
  949.  
  950.  
  951. # Write random data to OS partition
  952. if [[ $write_random = "yes" ]]; then
  953. if [[ $encrypt_os = "yes" ]]; then
  954. #xterm -fa monaco -fs 12 -geometry 80x20+0+0 -e dd if=/dev/urandom of="$install_dev"
  955. # # Redirect stderr so we can see the output of dd
  956. exec 2>&1
  957. dd if=/dev/urandom of="$install_dev"
  958. # # Resume logging errors in file
  959. exec 2>>"$error_log"
  960. fi
  961. fi
  962.  
  963. # Write random data to /home partition
  964. if [[ $write_random = "yes" ]]; then
  965. if [[ $encrypt_home = "yes" ]]; then
  966. #xterm -fa monaco -fs 12 -geometry 80x20+0+0 -e dd if=/dev/urandom of="$home_dev"
  967. # # Redirect stderr so we can see the output of dd
  968. exec 2>&1
  969. dd if=/dev/urandom of="$home_dev"
  970. # # Resume logging errors in file
  971. exec 2>>"$error_log"
  972. fi
  973. fi
  974.  
  975.  
  976. # Write zeros to partitions
  977. if [[ $write_zero = "yes" ]]; then
  978. #xterm -fa monaco -fs 12 -geometry 80x20+0+0 -e dd if=/dev/zero of="$install_dev"
  979. dd if=/dev/zero of="$install_dev"
  980. if [[ $sep_home = "yes" ]]; then
  981. #xterm -fa monaco -fs 12 -geometry 80x20+0+0 -e dd if=/dev/zero of="$home_dev"
  982. # # Redirect stderr so we can see the output of dd
  983. exec 2>&1
  984. dd if=/dev/zero of="$home_dev"
  985. # # Resume logging errors in file
  986. exec 2>>"$error_log"
  987. fi
  988. if [[ $sep_boot = "yes" ]]; then
  989. #xterm -fa monaco -fs 12 -geometry 80x20+0+0 -e dd if=/dev/zero of="$boot_dev"
  990. # # Redirect stderr so we can see the output of dd
  991. exec 2>&1
  992. dd if=/dev/zero of="$boot_dev"
  993. # # Resume logging errors in file
  994. exec 2>>"$error_log"
  995. fi
  996. fi
  997.  
  998.  
  999. # make mount point, format, adjust reserve and mount
  1000. # install_dev must maintain the device name for cryptsetup
  1001. # install_part will be either device name or /dev/mapper name as needed.
  1002. mkdir /target ; check_exit
  1003.  
  1004.  
  1005. #*****************************************************************************
  1006.  
  1007.  
  1008. make_luks () {
  1009. exec 2>/dev/null
  1010. setpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" \
  1011. --title "Passphrase" --image="dialog-password" --button=OK:0 --text="Enter a passphrase for the encrypted volume: $mapper_name ")
  1012.  
  1013. if [[ $(echo $setpass | awk -F"@_@" '{print $1}') != $(echo $setpass | awk -F"@_@" '{print $2}') ]] ; then
  1014. try_again
  1015. return
  1016. else
  1017. passphr=$(echo $setpass | awk -F"@_@" '{ print $1 }')
  1018. echo "$passphr" | cryptsetup luksFormat "$luks_dev"
  1019. echo "$passphr" | cryptsetup luksOpen "$luks_dev" "$mapper_name"
  1020.  
  1021. fi
  1022. exec 2>>"$error_log"
  1023. }
  1024.  
  1025.  
  1026. try_again () {
  1027. yad --image="gtk-dialog-warning" --title "Error" --button=Yes:0 --button="Exit":1 \
  1028. --text "Entries do not match. Do you want to try again?"
  1029. if [[ $? = 0 ]] ; then
  1030. make_luks
  1031. else
  1032. cleanup
  1033. exit 0
  1034. fi
  1035. }
  1036.  
  1037.  
  1038. if [[ $encrypt_os = yes ]] ; then
  1039. luks_dev="$install_dev"
  1040. mapper_name="root_fs"
  1041. make_luks
  1042. install_part="/dev/mapper/$mapper_name"
  1043. else
  1044. install_part="$install_dev"
  1045. fi
  1046. if [[ $no_format != "yes" ]]; then
  1047. mke2fs -t $fs_type_os "$install_part" ; check_exit
  1048. tune2fs -r 10000 "$install_part" ; check_exit
  1049. fi
  1050. mount "$install_part" /target ; check_exit
  1051.  
  1052.  
  1053. # make mount point for separate home if needed
  1054. # and set variable for rsync exclusion.
  1055. if [[ -n $home_dev ]] ; then
  1056. mkdir /target_home ; check_exit
  1057. if [[ $encrypt_home = yes ]]; then
  1058. luks_dev="$home_dev"
  1059. mapper_name="home_fs"
  1060. make_luks
  1061. home_part="/dev/mapper/$mapper_name"
  1062. else
  1063. home_part=$home_dev
  1064. fi
  1065. if [[ $no_format != "yes" ]]; then
  1066. mke2fs -t $fs_type_home "$home_part" ; check_exit
  1067. tune2fs -r 10000 "$home_part" ; check_exit
  1068. fi
  1069. mount "$home_part" /target_home ; check_exit
  1070. sep_home_opt="--exclude=/home/*"
  1071. fi
  1072.  
  1073.  
  1074.  
  1075. #*****************************************************************************
  1076.  
  1077.  
  1078. # make mount point for separate /boot if needed
  1079. # and set variable for rsync exclusion.
  1080. # allow default for reserved blocks (don't need tune2fs here)
  1081. if [[ -n $boot_dev ]] ; then
  1082. mkdir /target_boot ; check_exit
  1083. if [[ $no_format != "yes" ]]; then
  1084. mke2fs -t $fs_type_boot $boot_dev ; check_exit
  1085. fi
  1086. mount $boot_dev /target_boot
  1087. sep_boot_opt="--exclude=/boot/*"
  1088. fi
  1089.  
  1090.  
  1091. # copy everything over except the things listed in the exclude list
  1092. rsync -av / /target/ --filter='P lost+found' --filter='H lost+found' --exclude-from="$rsync_excludes" ${sep_home_opt} ${sep_boot_opt} --delete-before --delete-excluded | \
  1093. tee >(yad --progress --pulsate --width=350 --auto-close --title=$"Copying system to new partition.")
  1094.  
  1095.  
  1096. # copy separate /home if needed
  1097. if ! [[ -z $home_dev ]] ; then
  1098. rsync -av /home/ /target_home/ --filter='P lost+found' --filter='H lost+found' --exclude-from="$home_boot_excludes" | \
  1099. tee >(yad --progress --pulsate --width=350 --auto-close --title=$"Copying home folders to new partition.")
  1100. fi
  1101.  
  1102. # copy separate /boot if needed
  1103. if [[ -n $boot_dev ]] ; then
  1104. rsync -av /boot/ /target_boot/ --filter='P lost+found' --filter='H lost+found' --exclude-from="$home_boot_excludes" | \
  1105. tee >(yad --progress --pulsate --width=350 --auto-close --title=$"Copying files to boot partition.")
  1106. fi
  1107.  
  1108.  
  1109. # create swapfile
  1110. if ! [[ $use_existing_swap = "yes" ]] ; then
  1111. dd if=/dev/zero of=/target/swapfile bs="$swapfile_blocksize" count="$swapfile_count" | \
  1112. tee >(yad --progress --pulsate --width=350 --auto-close --title=$"Making a swap file...")
  1113. mkswap /target/swapfile ; check_exit
  1114. chmod 600 /target/swapfile
  1115. fi
  1116.  
  1117.  
  1118.  
  1119. # copy the real update-initramfs back in place ### OBSOLETE???
  1120. #if [[ -f /target/usr/sbin/update-initramfs.distrib ]] ; then
  1121. # cp /target/usr/sbin/update-initramfs.distrib /target/usr/sbin/update-initramfs
  1122. #fi
  1123. #if [[ -f /target/usr/sbin/update-initramfs.debian ]] ; then
  1124. # cp /target/usr/sbin/update-initramfs.debian /target/usr/sbin/update-initramfs
  1125. #fi
  1126.  
  1127. #*****************************************************************************
  1128.  
  1129.  
  1130. # Disallow mounting of all fixed drives with pmount
  1131. if [[ -f /target/etc/pmount.allow ]] ; then
  1132. if [[ $pmount_fixed = "no" ]] ; then
  1133. sed -i 's:/dev/sd\[a-z\]:#/dev/sd\[a-z\]:' /target/etc/pmount.allow
  1134. fi
  1135. fi
  1136.  
  1137. # Re-enable updatedb if it was disabled by an older version of refractasnapshot
  1138. if [[ -e /target/usr/bin/updatedb.mlocate ]] ; then
  1139. if ! [[ -x /target/usr/bin/updatedb.mlocate ]] ; then
  1140. chmod +x /target/usr/bin/updatedb.mlocate
  1141. fi
  1142. fi
  1143.  
  1144.  
  1145. # Disable autologin
  1146. if [[ $disable_auto_desktop = "yes" ]]; then
  1147.  
  1148. #gdm
  1149. if [[ -f /target/etc/gdm/gdm.conf ]]; then
  1150. sed -i 's/^AutomaticLogin/#AutomaticLogin/' /target/etc/gdm/gdm.conf
  1151. fi
  1152.  
  1153. #gdm3
  1154. if [[ -f /target/etc/gdm3/daemon.conf ]]; then
  1155. sed -i 's/^AutomaticLogin/#AutomaticLogin/' /target/etc/gdm3/daemon.conf
  1156. fi
  1157.  
  1158. #lightdm
  1159. if [[ -f /target/etc/lightdm/lightdm.conf ]]; then
  1160. sed -i 's/^autologin/#autologin/g' /target/etc/lightdm/lightdm.conf
  1161. fi
  1162.  
  1163. #kdm
  1164. if [ -f /target/etc/default/kdm.d/live-autologin ]; then
  1165. rm -f /target/etc/default/kdm.d/live-autologin
  1166. fi
  1167.  
  1168. if [ -f /target/etc/kde3/kdm/kdmrc ]; then
  1169. sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/kde3/kdm/kdmrc
  1170. sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/kde3/kdm/kdmrc
  1171. fi
  1172.  
  1173. if [ -f /target/etc/kde4/kdm/kdmrc ]; then
  1174. sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/kde4/kdm/kdmrc
  1175. sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/kde4/kdm/kdmrc
  1176. fi
  1177.  
  1178. # trinity desktop
  1179.  
  1180. # v3.5.13
  1181. if [[ -f /target/etc/default/kdm-trinity.d/live-autologin ]]; then
  1182. rm -f /target/etc/default/kdm-trinity.d/live-autologin
  1183. fi
  1184.  
  1185. if [ -f /target/etc/trinity/kdm/kdmrc ]; then
  1186. sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/trinity/kdm/kdmrc
  1187. sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/trinity/kdm/kdmrc
  1188. fi
  1189.  
  1190. # v3.5.14
  1191. if [[ -f /target/etc/default/tdm-trinity.d/live-autologin ]]; then
  1192. rm -f /target/etc/default/tdm-trinity.d/live-autologin
  1193. fi
  1194.  
  1195. if [ -f /target/etc/trinity/tdm/tdmrc ]; then
  1196. sed -i -e 's/^AutoLogin/#AutoLogin/g' /target/etc/trinity/tdm/tdmrc
  1197. sed -i -e 's/^AutoReLogin/#AutoReLogin/g' /target/etc/trinity/tdm/tdmrc
  1198. fi
  1199.  
  1200. # No display manager
  1201. if [ -f /target/etc/profile.d/zz-live-config_xinit.sh ]; then
  1202. rm -f /target/etc/profile.d/zz-live-config_xinit.sh
  1203. fi
  1204. fi
  1205.  
  1206.  
  1207. # Disable console autologin
  1208. if [[ $disable_auto_console = "yes" ]]; then
  1209. if grep -q "respawn:/bin/login -f" /target/etc/inittab ; then
  1210. mv /target/etc/inittab /target/etc/inittab.$(date +%Y%m%d_%H%M)
  1211. cp /usr/lib/refractainstaller/inittab.debian /target/etc/inittab
  1212. fi
  1213. fi
  1214.  
  1215.  
  1216. # setup fstab
  1217.  
  1218. # add entry for root filesystem
  1219. if [[ $encrypt_os != "yes" ]]; then
  1220. if [[ $use_uuid = yes ]]; then
  1221. install_part="$(blkid -s UUID $install_dev | awk '{ print $2 }' | sed 's/\"//g')"
  1222. elif [[ $use_labels = yes ]]; then
  1223. rootfslabel=$(/sbin/blkid -c /dev/null -s LABEL $install_dev | awk -F"\"" '{ print $2 }')
  1224. if [[ -n $rootfslabel ]]; then
  1225. install_part="LABEL=$rootfslabel"
  1226. else
  1227. rootfslabel=$(yad --entry --title=$"Filesystem Label" --text=$"Enter a disk label for $install_dev" --width=300 --button="OK":0)
  1228. if [[ -n $rootfslabel ]]; then
  1229. e2label "$install_dev" "$rootfslabel"
  1230. install_part="LABEL=$rootfslabel"
  1231. else
  1232. install_part="$install_dev"
  1233. fi
  1234. fi
  1235. else
  1236. install_part="$install_dev"
  1237. fi
  1238. fi
  1239. echo -e "proc\t\t/proc\tproc\tdefaults\t0\t0
  1240. $install_part\t/\t$fs_type_os\tdefaults,noatime\t0\t1" > /target/etc/fstab
  1241. check_exit
  1242.  
  1243.  
  1244. # add entry for /home to fstab if needed
  1245. if ! [[ -z $home_dev ]] ; then
  1246. if [[ $encrypt_os != "yes" ]]; then
  1247. if [[ $use_uuid = yes ]]; then
  1248. home_part="$(blkid -s UUID $home_dev | awk '{ print $2 }' | sed 's/\"//g')"
  1249. elif [[ $use_labels = yes ]]; then
  1250. homefslabel=$(/sbin/blkid -c /dev/null -s LABEL $home_dev | awk -F"\"" '{ print $2 }')
  1251. if [[ -n $homefslabel ]]; then
  1252. home_part="LABEL=$homefslabel"
  1253. else
  1254. homefslabel=$(yad --entry --title=$"Filesystem Label" --text=$"Enter a disk label for $home_dev" --width=300 --button="OK":0)
  1255. if [[ -n $homefslabel ]]; then
  1256. e2label "$home_dev" "$homefslabel"
  1257. home_part="LABEL=$homefslabel"
  1258. else
  1259. home_part="$home_dev"
  1260. fi
  1261. fi
  1262. else
  1263. home_part="$home_dev"
  1264. fi
  1265. fi
  1266. echo -e "$home_part\t/home\t$fs_type_home\tdefaults,noatime\t0\t2" >> /target/etc/fstab
  1267. check_exit
  1268. fi
  1269.  
  1270. # add entry for /boot to fstab if needed
  1271. if [[ -n $boot_dev ]] ; then
  1272. if [[ $use_uuid = yes ]]; then
  1273. boot_part="$(blkid -s UUID $boot_dev | awk '{ print $2 }' | sed 's/\"//g')"
  1274. elif [[ $use_labels = yes ]]; then
  1275. bootfslabel=$(/sbin/blkid -c /dev/null -s LABEL $boot_dev | awk -F"\"" '{ print $2 }')
  1276. if [[ -n $bootfslabel ]]; then
  1277. boot_part="LABEL=$bootfslabel"
  1278. else
  1279. bootfslabel=$(yad --entry --title=$"Filesystem Label" --text=$"Enter a disk label for $boot_dev" --width=300 --button="OK":0)
  1280. if [[ -n $bootfslabel ]]; then
  1281. e2label "$boot_dev" "$bootfslabel"
  1282. boot_part="LABEL=$bootfslabel"
  1283. else
  1284. boot_part="$boot_dev"
  1285. fi
  1286. fi
  1287. else
  1288. boot_part="$boot_dev"
  1289. fi
  1290. echo -e "$boot_part\t/boot\t$fs_type_boot\tdefaults,noatime,\t0\t2" >> /target/etc/fstab
  1291. check_exit
  1292. fi
  1293.  
  1294.  
  1295. # add entry for swap to fstab if needed
  1296. if [[ $use_existing_swap = "yes" ]] ; then
  1297. if [[ $use_uuid = yes ]]; then
  1298. swap_part="$(/sbin/blkid -s UUID $swap_dev | awk '{ print $2 }' | sed 's/\"//g')"
  1299. else
  1300. swap_part="$swap_dev"
  1301. fi
  1302. echo -e $"\n Adding swap entry to fstab...\n"
  1303. echo -e "$swap_part\tswap\tswap\tdefaults\t0\t0" >> /target/etc/fstab
  1304. else
  1305. echo -e "/swapfile\tswap\tswap\tdefaults\t0\t0" >> /target/etc/fstab
  1306. fi
  1307.  
  1308.  
  1309. # Add entry for root filesystem to crypttab if needed
  1310. if [[ $encrypt_os = yes ]] ; then
  1311. echo -e "root_fs\t\t$install_dev\t\tnone\t\tluks" >> /target/etc/crypttab
  1312. fi
  1313.  
  1314.  
  1315. # Add entry for /home to crypttab if needed
  1316. if [[ $encrypt_home = yes ]] ; then
  1317. echo -e "home_fs\t\t$home_dev\t\tnone\t\tluks" >> /target/etc/crypttab
  1318. fi
  1319.  
  1320.  
  1321. # mount stuff so grub will behave (so chroot will work)
  1322. mount --bind /dev/ /target/dev/ ; check_exit
  1323. mount --bind /proc/ /target/proc/ ; check_exit
  1324. mount --bind /sys/ /target/sys/ ; check_exit
  1325.  
  1326.  
  1327. # Re-enable freshclam if it was disabled by snapshot ##### This ain't perfect, but it works!
  1328. if type -p freshclam ; then
  1329. if [[ $enable_freshclam = "yes" ]] ; then
  1330. if ! [[ -h /target/etc/rc2.d/S02clamav-freshclam ]] ; then
  1331. chroot /target update-rc.d clamav-freshclam defaults
  1332. fi
  1333. fi
  1334. fi
  1335.  
  1336.  
  1337. # Allow users to login to ssh with passwords if desired.
  1338. # Allow root login only with auth keys.
  1339. # or do nothing.
  1340. if [[ $ssh_pass = "yes" ]] ; then
  1341. sed -i~ 's/PasswordAuthentication no/PasswordAuthentication yes/' /target/etc/ssh/sshd_config
  1342. sed -i 's/PermitRootLogin yes/PermitRootLogin without-password/' /target/etc/ssh/sshd_config
  1343. elif [[ $ssh_pass = "no" ]] ; then
  1344. sed -i~ 's/ PasswordAuthentication yes/PasswordAuthentication no/' /target/etc/ssh/sshd_config
  1345. sed -i 's/PermitRootLogin yes/PermitRootLogin without-password/' /target/etc/ssh/sshd_config
  1346. elif [[ -n "$ssh_pass" ]] ; then
  1347. echo "WARNING: ssh_pass value not recognized. No changes were made to /etc/ssh/sshd_config"
  1348. fi
  1349.  
  1350.  
  1351. install_grub () {
  1352. # Setup GRUB
  1353. echo "Setting up grub bootloader.. Please wait.."
  1354.  
  1355. # If /boot is separate partition, need to mount it in chroot for grub
  1356. if [[ -n $boot_dev ]] ; then
  1357. chroot /target mount $boot_dev /boot
  1358. fi
  1359.  
  1360.  
  1361. # If grub is installed to a partition, we need to know if it's grub-pc
  1362. # or grub-legacy/grub-gfx to handle it properly.
  1363. if [[ -n $grub_partition ]] ; then
  1364. if [[ $grubversion != "grub-pc" ]] ; then
  1365.  
  1366. # isolate the device (sdx) letter then use tr like this to translate to the right number for grub
  1367. GRUBDEVICENUM=$(echo $grub_partition |sed 's:/dev/sd::' |sed 's:[0-9]::'g |tr '[a-j]' '[0-9]')
  1368.  
  1369. # isolate the partition number
  1370. INSTALLPARTNUM=$(echo $grub_partition |sed 's:/dev/sd::'|sed 's:[a-z]::')
  1371.  
  1372. # and reduce it by 1 for grub
  1373. GRUBPARTNUM=$(expr $INSTALLPARTNUM - 1)
  1374.  
  1375. # finally get the finished grub root syntax
  1376. GRUBROOT="(hd$GRUBDEVICENUM,$GRUBPARTNUM)"
  1377.  
  1378.  
  1379. chroot /target grub-install $grub_partition
  1380. grub --batch <<EOF
  1381. root $GRUBROOT
  1382. setup $GRUBROOT
  1383. quit
  1384. EOF
  1385.  
  1386. else
  1387. error_message=$"grub-install failed."
  1388. chroot /target grub-install --recheck --no-floppy --force $grub_partition >> "$error_log" ; check_exit
  1389. fi
  1390. fi
  1391.  
  1392.  
  1393. if [[ -n $grub_dev ]]; then
  1394. echo -e $"\n Installing GRUB boot loader...\n" >> "$error_log"
  1395. error_message=$"grub-install failed."
  1396. chroot /target grub-install $grub_dev >> "$error_log" ; check_exit
  1397. fi
  1398.  
  1399. error_message=""
  1400. }
  1401.  
  1402. install_grub | tee >(yad --title="Installing GRUB bootloader..." --progress --pulsate --auto-close --width 300)
  1403.  
  1404.  
  1405. #******************************************************************
  1406.  
  1407. # Run update-initramfs to include dm-mod if using encryption
  1408. if [[ $encrypt_os = yes ]] || [[ $encrypt_home = yes ]] ; then
  1409. if [[ -f /usr/sbin/update-initramfs.orig.initramfs-tools ]] ; then
  1410. chroot /target /usr/sbin/update-initramfs.orig.initramfs-tools -u >> "$error_log"
  1411. else
  1412. chroot /target /usr/sbin/update-initramfs -u >> "$error_log"
  1413. fi
  1414. fi
  1415.  
  1416.  
  1417. #******************************************************************
  1418.  
  1419.  
  1420.  
  1421. if [[ -n $grub_dev ]] || [[ -n $grub_partition ]] ; then
  1422. chroot /target update-grub ; check_exit
  1423. fi
  1424.  
  1425. if [ -f /target/boot/grub/setup_left_core_image_in_filesystem ]; then
  1426. rm -f /target/boot/grub/setup_left_core_image_in_filesystem
  1427. fi
  1428.  
  1429. # INSTALLATION FINISHED - BEGIN CONFIGURE USERNAME, HOSTNAME, PASSWORDS, SUDO
  1430.  
  1431.  
  1432. # Need to mount the target home partition under the target root partition
  1433. # so the commands can find it (for changing user configs gksu)
  1434. if [[ $sep_home = "yes" ]]; then
  1435. mount $home_part /target/home
  1436. fi
  1437.  
  1438.  
  1439. # it might not be on in some live builds
  1440. chroot /target /bin/bash -c "shadowconfig on"
  1441.  
  1442. oldname=$(awk -F: '/1000:1000/ { print $1 }' /target/etc/passwd)
  1443. old_realname=$(cat /target/etc/passwd |grep "^$oldname"|sed "s/,,,//"|awk -F ":" '{print $5}')
  1444.  
  1445. username_dialog() {
  1446.  
  1447. newuser=$(yad --form --title="Configure hostname and username..." --button="OK":0 \
  1448. --text=$"\n You should change the hostname and username \n \
  1449. (optional but recommended) \n" \
  1450. --field=$"New hostname \(no spaces\):" \
  1451. --field=$"New username \(no spaces\):" \
  1452. --field=$"New user's 'real name' \(e.g. John Smith\):" \
  1453. --field=$"Permit sudo for new user\?":CHK \
  1454. --field=$"Use sudo as default for new user\?":CHK \
  1455. --field=$"Use sudo only for shutdown\?":CHK \
  1456. "$HOSTNAME" "$oldname" "$old_realname" FALSE FALSE TRUE)
  1457.  
  1458. new_hostname=$(echo $newuser |awk -F "|" '{print $1}')
  1459. newname=$(echo $newuser |awk -F "|" '{print $2}')
  1460. new_realname=$(echo $newuser |awk -F "|" '{print $3}')
  1461. sudoconfig=$(echo $newuser |awk -F "|" '{print $4}')
  1462. sudo_is_default=$(echo $newuser |awk -F "|" '{print $5}')
  1463. sudo_shutdown=$(echo $newuser |awk -F "|" '{print $6}')
  1464. }
  1465.  
  1466. username_dialog
  1467.  
  1468.  
  1469.  
  1470. # Test to make sure new_hostname is a legal hostname, let user fix it if it's not.
  1471. fix_hostname () {
  1472. new_hostname=$(yad --entry --title=$"Change hostname" \
  1473. --text=$"Illegal hostname. Try again.
  1474.  
  1475. You can use alphanumeric characters anywhere in the hostname, and
  1476. you can use the minus sign (-) as long as it's not at the beginning or end." \
  1477. --entry-text="$HOSTNAME" --width=500 --button="OK":0)
  1478. test_hostname
  1479. }
  1480.  
  1481.  
  1482. test_hostname () {
  1483. if [[ $new_hostname =~ "$"|"%"|"("|")"|"*"|"_"|"@"|"~"|"!"|"#"|"="|"+"|"&"|"^"|":"|";"|"'"|","|"."|"<"|">"|"?"|"{"|"}"|"["|"]"|"/"|"|"|" " ]]; then
  1484. fix_hostname
  1485. elif [[ $new_hostname =~ "\""|"\`" ]];then
  1486. fix_hostname
  1487. elif [[ $new_hostname = -* ]] || [[ $new_hostname = *- ]]; then
  1488. fix_hostname
  1489. elif [[ -z $new_hostname ]]; then
  1490. new_hostname="$HOSTNAME"
  1491. fi
  1492. }
  1493.  
  1494.  
  1495. # do hostname
  1496. if [[ $new_hostname != $HOSTNAME ]]; then
  1497. test_hostname
  1498. sed -i "s/$HOSTNAME/$new_hostname/" /target/etc/hostname
  1499. sed -i "s/$HOSTNAME/$new_hostname/g" /target/etc/hosts
  1500. fi
  1501.  
  1502. # do username
  1503. if [ -z "$newname" ]; then
  1504. newname=$oldname
  1505. fi
  1506.  
  1507. if [ "$oldname" != "$newname" ]; then
  1508.  
  1509. chroot /target usermod -l $newname $oldname ; check_exit
  1510. chroot /target groupmod -n $newname $oldname ; check_exit
  1511. chroot /target usermod -d /home/$newname -m $newname ; check_exit
  1512.  
  1513. for i in $(grep -r "/home/$oldname" /target/home/$newname/.config | awk -F":" '{ print $1 }'); do
  1514. sed -i "s/\/home\/$oldname/\/home\/$newname/g" "$i"
  1515. done
  1516.  
  1517. for i in $(grep -r "/home/$oldname" /target/home/$newname/.local | awk -F":" '{ print $1 }'); do
  1518. sed -i "s/\/home\/$oldname/\/home\/$newname/g" "$i"
  1519. done
  1520. fi
  1521.  
  1522. #sed -i~ "s/$old_realname,,,/$new_realname,,,/" /target/etc/passwd
  1523. chroot /target /bin/bash -c "chfn -f '$new_realname' $newname"
  1524.  
  1525.  
  1526. ## sort sudo ##
  1527.  
  1528. # =>wheezy live-config now uses /etc/sudoers.d
  1529. if [ -e /target/etc/sudoers.d/live ]; then
  1530. rm -f /target/etc/sudoers.d/live
  1531. fi
  1532.  
  1533. oldusername=$(awk -F: '/1000:1000/ { print $1 }' /etc/passwd)
  1534. newusername=$(awk -F: '/1000:1000/ { print $1 }' /target/etc/passwd)
  1535.  
  1536. # squeeze (or other distro) might have used /etc/sudoers
  1537. if grep -qs $oldusername /target/etc/sudoers ; then
  1538. sed -i "/$oldusername/d" /target/etc/sudoers
  1539. fi
  1540.  
  1541. if [ "$sudoconfig" = "TRUE" ] || [ "$sudo_is_default" = "TRUE" ]; then
  1542. # $newusername is permitted to use sudo so add him to sudo group
  1543. chroot /target usermod -a -G sudo $newusername
  1544.  
  1545. # it shoud be already there in =>wheezy.. in case it's not:
  1546. if ! grep -qs "^%sudo" /target/etc/sudoers ; then
  1547. echo "%sudo ALL=(ALL:ALL) ALL" >> /etc/sudoers
  1548. fi
  1549. fi
  1550.  
  1551. if [ "$sudo_is_default" != "TRUE" ]; then
  1552.  
  1553. # files that may have been written by live-config to force live sudo mode
  1554.  
  1555. # should they just be deleted?
  1556.  
  1557. # rm -f /target/home/*/.gconf/apps/gksu/%gconf.xml
  1558. # rm -f /target/home/*/.*/share/config/*desurc
  1559.  
  1560. # fix gksu in user's home ($newusername will not use sudo by default)
  1561. if [ -f /target/home/"$newusername"/.gconf/apps/gksu/%gconf.xml ]; then
  1562. sed -i '/sudo-mode/s/true/false/' /target/home/"$newusername"/.gconf/apps/gksu/%gconf.xml
  1563. fi
  1564.  
  1565. sed -i 's/SU_TO_ROOT_SU=sudo/SU_TO_ROOT_SU=su/' /target/home/$newusername/.su-to-rootrc
  1566. # detects .kde/ .kde4/ .trinity/ (kdesurc or tdesurc)
  1567. for file in /target/home/$newusername/.*/share/config/*desurc ; do
  1568. sed -i 's/super-user-command=sudo/super-user-command=su/' $file
  1569. done
  1570. fi
  1571.  
  1572. if [ "$sudo_shutdown" = "TRUE" ]; then
  1573. sudo_include_file="/target/etc/sudoers.d/user_shutdown"
  1574. if [ -f "$sudo_include_file" ]; then
  1575. mv "$sudo_include_file" "${sudo_include_file}.old"
  1576. fi
  1577. echo "$newusername ALL= NOPASSWD: /usr/sbin/pm-suspend, /usr/sbin/pm-hibernate, /sbin/halt, /sbin/reboot" > "$sudo_include_file"
  1578. fi
  1579.  
  1580.  
  1581. # live-config also writes directory /home/user/.kde
  1582. # if kde is not installed it should be removed !
  1583.  
  1584.  
  1585. ## passwords ##
  1586.  
  1587. clean_log() {
  1588.  
  1589. # clear the log of plain-text passwords
  1590. if [ -n "$newpass" ]; then
  1591. sed -i "s|$newpass|\*\*\*\*|"g $error_log
  1592. fi
  1593.  
  1594. if [ -n "$confirm_newpass" ]; then
  1595. sed -i "s|$confirm_newpass|\*\*\*\*|"g $error_log
  1596. fi
  1597. newpass=""
  1598. confirm_newpass=""
  1599. }
  1600.  
  1601. pass_error() {
  1602.  
  1603. clean_log
  1604. use_existing=""
  1605. disable_root=""
  1606.  
  1607. yad --title=$"Configure $pass_dialog password" --image="gtk-dialog-error" --width=320 --button="OK":0 \
  1608. --text=$" Passwords do not match (or checkbox error) \n\n Please try again "
  1609. }
  1610.  
  1611. configure_pass() {
  1612.  
  1613. clean_log
  1614.  
  1615. pass_entry=$(yad --form --title=$"Configure $pass_dialog password" --button="OK":0 \
  1616. --text=$"You should reset the $pass_dialog password.\n" \
  1617. --field=$"Enter new $pass_dialog password::H" \
  1618. --field=$"Confirm new $pass_dialog password::H" \
  1619. --field=$"Use current password\? (not recommended)":CHK \
  1620. "$field_four")
  1621.  
  1622. # TODO check for illegal characters?
  1623.  
  1624. newpass=$(echo $pass_entry|awk -F "|" '{print $1}')
  1625. confirm_newpass=$(echo $pass_entry|awk -F "|" '{print $2}')
  1626. use_existing=$(echo $pass_entry|awk -F "|" '{print $3}')
  1627. disable_root=$(echo $pass_entry|awk -F "|" '{print $4}')
  1628.  
  1629. if [ "$use_existing" = "TRUE" ] && [ "$disable_root" = "TRUE" ] ; then
  1630. pass_error
  1631. configure_pass
  1632. fi
  1633.  
  1634. if [ -n "$newpass" ] && [ "$use_existing" = "TRUE" ]; then
  1635. pass_error
  1636. configure_pass
  1637. fi
  1638.  
  1639. if [ "$use_existing" = "TRUE" ] || [ "$disable_root" = "TRUE" ] ; then
  1640. return
  1641. fi
  1642.  
  1643. if [ -z "$newpass" ] || [ "$newpass" != "$confirm_newpass" ]; then
  1644. pass_error
  1645. configure_pass
  1646. fi
  1647. }
  1648.  
  1649. # do root password
  1650. set_rootpass() {
  1651. if [ "$sudo_is_default" = "TRUE" ]; then
  1652. field_four=$'--field=Disable root account\? \(not recommended\):CHK'
  1653. fi
  1654.  
  1655. pass_dialog=root
  1656. configure_pass
  1657.  
  1658. if [ "$disable_root" = "TRUE" ]; then
  1659. echo $"disabling root account.. "
  1660.  
  1661. # replace second field with "*" in /etc/shadow
  1662. rootpass_hash=$(cat /target/etc/shadow|grep ^root| awk -F ":" '{print $3 ":" $4 ":" $5 ":" $6}')
  1663. sed -i "s|^root:.*|root:\*:${rootpass_hash}:::|" /target/etc/shadow
  1664. else
  1665. if [ -n "$newpass" ]; then
  1666. chroot /target /bin/bash -c "echo -e \"$newpass\n$newpass\n\" | passwd root"
  1667. #else do nothing, keep old password
  1668. fi
  1669. fi
  1670.  
  1671. clean_log
  1672. }
  1673.  
  1674. # do user password
  1675. set_userpass() {
  1676.  
  1677. pass_dialog=user
  1678. field_four=""
  1679. configure_pass
  1680.  
  1681. if [ -n "$newpass" ]; then
  1682. chroot /target /bin/bash -c "echo -e \"$newpass\n$newpass\n\" | passwd $newusername"
  1683. # else do nothing, keep old password
  1684. fi
  1685.  
  1686. clean_log
  1687. }
  1688.  
  1689. set_rootpass
  1690. set_userpass
  1691.  
  1692. # Run any post-install scripts
  1693. if [[ $run_postinstall = "yes" ]] ; then
  1694. for file in /usr/lib/refractainstaller/post-install/* ; do
  1695. if [[ -x "$file" ]] ; then
  1696. bash "$file"
  1697. fi
  1698. done
  1699. fi
  1700.  
  1701.  
  1702.  
  1703. yad --image=gtk-dialog-info --title="$window_title" --text=$" Installation complete. \n\n You may now reboot into the new system.\n\n Remember to remove your installation media.\n" --width=500 --button="OK":0
  1704.  
  1705. # copy error log to installation now before calling cleanup function
  1706. cp "$error_log" /target/home/"$newusername"/
  1707. chown 1000:1000 /target/home/"$newusername"/"${error_log##*/}"
  1708. cleanup
  1709.  
  1710. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement