Advertisement
Guest User

Untitled

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