dragora-installer 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #! /bin/sh -
  2. #
  3. # The installer of Dragora GNU/Linux-Libre
  4. #
  5. # Copyright (c) 2019-2022 Matias Fonzo, <selk@dragora.org>.
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Exit immediately on any error
  20. set -e
  21. PROGRAM="${0##*/}"
  22. TMPDIR="${TMPDIR:-$HOME}"
  23. TMPFILE="${TMPDIR}/${PROGRAM}.${RANDOM-0}$$"
  24. LOCKFILE=/tmp/dragora-installer.lockfile
  25. # Override locale settings
  26. LANG=C
  27. LC_ALL=C
  28. export LANG LC_ALL
  29. unmountFilesystems()
  30. {
  31. for filesystem in \
  32. /media/dragora-root/sys \
  33. /media/dragora-root/proc \
  34. /media/dragora-root/dev \
  35. /media/dragora-root \
  36. /media/dragora-packages ; \
  37. do
  38. if mountpoint -q "$filesystem"
  39. then
  40. echo ""
  41. echo ""
  42. echo "Unmounting $(findmnt -n -o SOURCE $filesystem) from $filesystem ..."
  43. if ! umount -v -R "$filesystem"
  44. then
  45. echo " ^ Doing a lazy unmount for \`${filesystem}' ..."
  46. umount -v -l "$filesystem"
  47. fi
  48. fi
  49. done
  50. unset -v filesystem
  51. }
  52. chkstatus_or_exit()
  53. {
  54. status=$?
  55. # Clean up temporary files
  56. rm -f -- "$TMPFILE" "$LOCKFILE"
  57. # Clean up temporary subdirectory if 'PRESERVE' is unset or null
  58. test -z "$PRESERVE" && rm -rf -- "$SUBTMPDIR"
  59. # Unmount possible (previously) mounted file systems
  60. unmountFilesystems
  61. if test $status -ne 0
  62. then
  63. printf '%s\n' "" "^ Return status = $status" 1>&2
  64. exit 2;
  65. fi
  66. unset -v status
  67. }
  68. # Sanity checks
  69. if test ! -d "$TMPDIR"
  70. then
  71. echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
  72. exit 1;
  73. fi
  74. if test ! -w "$TMPDIR"
  75. then
  76. echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
  77. exit 1;
  78. fi
  79. trap 'chkstatus_or_exit' EXIT HUP INT QUIT ABRT TERM
  80. umask 077; # Remove access for all but user.
  81. # Set a lock to allow only one instance of the installer
  82. if ( set -C ; echo ": $PROGRAM - locked" > $LOCKFILE ) 2> /dev/null
  83. then
  84. true
  85. else
  86. if test -e "$LOCKFILE"
  87. then
  88. echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
  89. exit 1;
  90. else
  91. echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
  92. exit 2;
  93. fi
  94. fi
  95. # Remove write permission for group and other
  96. umask 022
  97. # Create subdirectory to store the files produced by the installer
  98. # Default sets to "${HOME}/.dragora-installer"
  99. SUBTMPDIR="${TMPDIR}/.${PROGRAM}"
  100. mkdir -p -- "$SUBTMPDIR"
  101. chmod 700 -- "$SUBTMPDIR"
  102. # Detect and prepare initial list of Linux partition(s)
  103. if fdisk -l | sed -e 's|Linux filesystem|Linux|g' | grep -E -q -m 1 'Linux$'
  104. then
  105. fdisk -l | sed -e 's|Linux filesystem|Linux|g' | grep -E 'Linux$' | \
  106. sort > "${SUBTMPDIR}/partitions"
  107. else
  108. cat 1>&2 << EOF
  109. Linux partitions were not detected.
  110. A Linux partition is required to continue the installation. You can
  111. use utilities such as fdisk(8), cfdisk(8) or parted(8) to create at
  112. least one Linux partition. Then run \`${PROGRAM}' again.
  113. EOF
  114. exit 1;
  115. fi
  116. # Determine the maximum size of the terminal to be used on the dialogues
  117. echo "Checking terminal size ..."
  118. LINES="${LINES:-$(tput lines)}"
  119. COLUMNS="${COLUMNS:-$(tput cols)}"
  120. export SUBTMPDIR LINES COLUMNS
  121. dialog --colors \
  122. --backtitle "\\ZbThe installer of Dragora GNU/Linux-Libre 3.0" \
  123. --title "INSTALLER INFORMATION" \
  124. --cr-wrap --msgbox \
  125. "Welcome to \\Z3${PROGRAM}\\Zn.
  126. This program will help you install Dragora 3.0 on your computer.
  127. Use the cursor keys to move around in the installer's menus.
  128. Press \\Z3[Tab]\\Zn to jump to the next option and \
  129. \\Z3[Shift]\\Zn\\Zb\\Z7+\\Zn\\Z3[Tab]\\Zn to jump to the previous one.
  130. Use \\Z3[Space]\\Zn to select or unselect an item, \\Z3[Enter]\\Zn to \
  131. confirm or proceed to the next menu.
  132. You can use \\Z3[Ctrl]\\Zn\\Zb\\Z7+\\Zn\\Z3[C]\\Zn to abort the \
  133. installation at any time.
  134. To quit a dialog (such as the one you are in), press \\Z3[Esc]\\Zn.
  135. " $((LINES - 4)) $((COLUMNS - 8))
  136. # Try to detect and mount the hybrid ISO image, there may be a USB memory
  137. # stick already inserted. If not, the media menu will be displayed.
  138. mkdir -p -- /media/dragora-packages
  139. if ! blkid -t LABEL="Dragora Packages" > /dev/null
  140. then
  141. dialog --colors \
  142. --backtitle "\\ZbInstallation Medium" \
  143. --title "Pendrive/SDCard/CDROM" \
  144. --cr-wrap --msgbox \
  145. "
  146. Please insert the medium labeled \"Dragora Packages\" and
  147. press \\Z3[Enter]\\Zn to continue. Otherwise, a media selection
  148. menu will be displayed.
  149. " 9 60
  150. if blkid -t LABEL="Dragora Packages" > /dev/null
  151. then
  152. if ! mountpoint -q /media/dragora-packages
  153. then
  154. mount -v -t iso9660 LABEL="Dragora Packages" \
  155. /media/dragora-packages
  156. echo '/media/dragora-packages/packages' \
  157. > "${SUBTMPDIR}/MediumFound"
  158. sleep 1
  159. fi
  160. else
  161. . @PARTS@MenuMedia
  162. fi
  163. else
  164. if ! mountpoint -q /media/dragora-packages
  165. then
  166. mount -v -t iso9660 LABEL="Dragora Packages" /media/dragora-packages
  167. sleep 2
  168. fi
  169. echo '/media/dragora-packages/packages' > "${SUBTMPDIR}/MediumFound"
  170. fi
  171. # Attempt to unmount possible pre-mounted filesystem(s)
  172. mountpoint -q /media/dragora-root/sys && umount /media/dragora-root/sys
  173. mountpoint -q /media/dragora-root/proc && umount /media/dragora-root/proc
  174. mountpoint -q /media/dragora-root/dev && umount /media/dragora-root/dev
  175. # Clean up possible empty mount-directories
  176. rmdir -- /media/dragora-packages /media/dragora-root 2> /dev/null || true
  177. # Double-check to see the installation directory
  178. if test ! -f "${SUBTMPDIR}/MediumFound"
  179. then
  180. dialog --colors \
  181. --backtitle "\\ZbInstallation Medium" \
  182. --title "MEDIUM NOT FOUND" \
  183. --sleep 7 --cr-wrap --infobox \
  184. "
  185. No means of installation was found to proceed
  186. with the installation of Dragora.
  187. Please check your drives and the directory
  188. containing the software packages...
  189. " 9 49
  190. exit 99;
  191. fi
  192. . @PARTS@MakeSwap; # Swap devices.
  193. . @PARTS@MakeFS; # Linux partitions.
  194. . @PARTS@FstabEdit; # File system table edition (fstab).
  195. . @PARTS@MountRoot; # Mount root partition for installation.
  196. . @PARTS@FstabMounts; # Mount rest of file systems from fstab.
  197. . @PARTS@ShowSeries; # Software series.
  198. . @PARTS@InstallPackages; # Package installation.
  199. . @PARTS@PostInstall; # Post-installation.
  200. . @PARTS@SetPassword; # Password for root.
  201. . @PARTS@MenuBootloader; # Boot loader installation.
  202. . @PARTS@ConfServices; # Running services.
  203. if test -e /media/dragora-root/etc/fstab
  204. then
  205. if mountpoint -q /media/dragora-packages
  206. then
  207. umount /media/dragora-packages
  208. fi
  209. if test -s "${SUBTMPDIR}/SeTCDdev"
  210. then
  211. _status=0
  212. dialog --clear --colors \
  213. --title "The Setup for Dragora has been completed" \
  214. --cr-wrap --msgbox \
  215. "
  216. If you are ready, press \\Z3[Enter]\\Zn to eject
  217. the installation disc...
  218. " 8 0 || _status=$?
  219. if test $_status -eq 0
  220. then
  221. cdrom_device="$(cat -- "${SUBTMPDIR}/CDDevice")"
  222. # Try to eject using SCSI commands, fallback on CDROM eject command
  223. eject --scsi "$cdrom_device" || eject --cdrom "$cdrom_device"
  224. dialog \
  225. --title "The Setup for Dragora has been completed" \
  226. --msgbox "\\nPlease remove the installation disc.\\n" 7 44 || true
  227. # Attempt to use the tray close command
  228. eject -t "$cdrom_device" > /dev/null 2>&1 || true
  229. fi
  230. unset -v _status cdrom_device
  231. fi
  232. fi
  233. sync
  234. _status=0
  235. dialog --clear --colors \
  236. --backtitle "\\ZbSystem restart" \
  237. --title "The Setup for Dragora has been completed." \
  238. --cr-wrap --yesno \
  239. "
  240. Would you like to reboot the system now?
  241. " 7 44 || _status=$?
  242. case $_status in
  243. 0)
  244. unset -v _status
  245. dialog --clear
  246. unmountFilesystems
  247. exec reboot -d -f
  248. ;;
  249. *)
  250. unset -v _status
  251. unmountFilesystems
  252. echo ""
  253. echo ""
  254. echo ""
  255. echo "Going out to the shell..."
  256. echo ""
  257. echo ""
  258. exit 0
  259. ;;
  260. esac