3 # The installer of Dragora GNU/Linux-Libre
5 # Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
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.
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.
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/>.
20 # Exit immediately on any error
24 TMPDIR
="${TMPDIR:-$HOME}"
25 TMPFILE
="${TMPDIR}/${PROGRAM}.${RANDOM-0}$$"
26 LOCKFILE
=/tmp
/dragora-installer.lockfile
28 # Override locale settings
31 export LC_ALL LANGUAGE
37 # Clean up temporary files
38 rm -f -- "$TMPFILE" "$LOCKFILE"
40 # Clean up temporary subdirectory related to the installer
41 if test -z "$PRESERVE"
43 rm -rf -- "$SUBTMPDIR"
48 printf "%s\n" "" "^ Return status = $status" 1>&2
57 if test ! -d "$TMPDIR"
59 echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
62 if test ! -w "$TMPDIR"
64 echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
68 trap 'chkstatus_or_exit' EXIT HUP INT QUIT ABRT TERM
70 umask 077; # Remove access for all but user.
72 # Set a lock to allow only one instance of the installer
74 if ( set -C ; echo ": $PROGRAM - locked" > $LOCKFILE ) 2> /dev
/null
78 if test -e "$LOCKFILE"
80 echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
83 echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
88 # Create subdirectory to store the files produced by the installer
90 SUBTMPDIR
="${TMPDIR}/.${PROGRAM}" # Default sets to "${HOME}/.dragora-installer".
91 mkdir
-p -m 700 -- $SUBTMPDIR
93 umask 022; # Remove write permission for group and other.
95 # Detect and prepare initial list of Linux partition(s)
97 if fdisk
-l |
grep -m 1 Linux |
grep -q -v swap
99 fdisk
-l |
grep Linux |
grep -v swap | LC_COLLATE
=C
sort \
100 > ${SUBTMPDIR}/partitions
103 " Linux partitions were not detected." \
105 "A Linux partition is required to continue the installation. You can" \
106 "use utilities such as fdisk(8), cfdisk(8) or parted(8) to create at" \
107 "least one Linux partition. Then run \`${PROGRAM}' again."
111 # Determine the maximum size of the terminal to be used on the dialogues.
112 # Try using shell variables that set LINES and COLUMNS, first.
113 echo "Checking terminal size ..."
116 LINES
="$(tput lines)" || \
117 { LINES
="$(stty size)" && LINES
="${LINES% *}"; }
119 if test -z "$COLUMNS"
121 COLUMNS
="$(tput cols)" || \
122 { COLUMNS
="$(stty size)" && COLUMNS
="${COLUMNS#* }"; }
124 echo "$LINES $COLUMNS"
126 export SUBTMPDIR LINES COLUMNS
129 --backtitle "\ZbDragora 3.0 Installer" \
130 --title "INSTALLER INFORMATION" \
132 "Welcome to \Z3${PROGRAM}\Zn.\n\n\
133 This program prepares Dragora 3.0 to run on your computer.\n\n\
134 - To set up Dragora now, press \ZuENTER\Zn.\n\n\
135 - To quit, press \ZuEsc\Zn.\n\n\
137 Use the arrow keys to move between options and selections, also \ZuTAB\Zn to
138 jump from one option to another. \ZuENTER\Zn to continue, \ZuEsc\Zn to cancel
139 or return to a previous menu, and \ZuCtrl+C\Zn to abort the installation at
142 * Here is a representation of the most commonly used keys in a QWERTY layout:
144 \Z3[Esc]\Zn \Z3[F1]\Zn
145 \Z3[<- ]\Zn \Z3[Ins][Home][PageUp]\Zn
146 \Z3[TAB]\Zn \Z3[Del][End ][PageDown]\Zn
149 \Z3[Ctrl]\Zn \Z3[ SPACE ]\Zn \Z3[<][V][>]\Zn
150 \Zn" $
((LINES
- 8)) $
((COLUMNS
- 8))
152 # Try to detect and mount the hybrid ISO image, there may be a USB memory
153 # stick already inserted. If not, the media menu will be displayed.
155 mkdir
-p -- /media
/dragora-medium
157 if ! blkid
-t LABEL
="Dragora Packages" > /dev
/null
160 --backtitle "\ZbInstallation Medium" \
161 --title "Pendrive/SDCard/CDROM" \
163 "Please insert the media labeled as \"Dragora Packages\" and\n\
164 press \Zb\Z7ENTER\Zn to continue. Otherwise a media selection menu\n\
165 will be displayed." 7 63
166 if blkid
-t LABEL
="Dragora Packages" > /dev
/null
168 if ! mountpoint
-q /media
/dragora-medium
170 mount
-v -t iso9660 LABEL
="Dragora Packages" /media
/dragora-medium
&& \
171 echo "/media/dragora-medium/packages" > ${SUBTMPDIR}/MediumFound
178 if ! mountpoint
-q /media
/dragora-medium
180 mount
-v -t iso9660 LABEL
="Dragora Packages" /media
/dragora-medium
183 echo "/media/dragora-medium/packages" > ${SUBTMPDIR}/MediumFound
186 # Attempt to unmount possible pre-mounted filesystem(s)
187 mountpoint
-q /media
/dragora-root
/sys
&& umount
/media
/dragora-root
/sys
188 mountpoint
-q /media
/dragora-root
/proc
&& umount
/media
/dragora-root
/proc
189 mountpoint
-q /media
/dragora-root
/dev
&& umount
/media
/dragora-root
/dev
191 # Clean up possible empty mount-directories
193 /media
/dragora-medium \
194 /media
/dragora-root
2> /dev
/null || true
196 # Double-check to see the installation directory
197 if test ! -f "${SUBTMPDIR}/MediumFound"
200 --backtitle "\ZbInstallation Medium" \
201 --title "MEDIUM NOT FOUND" \
202 --sleep 7 --infobox \
203 "\nNo means of installation was found to proceed with\n\
204 the installation of Dragora. Please check your\n\
205 drives and the directory containing the software\n\
210 . @PARTS@MakeSwap
; # Verify/give format to a Swap partition.
211 . @PARTS@MakeFS
; # Verify/give format to Linux partitions.
212 . @PARTS@FstabEdit
; # File system table edition (fstab).
213 . @PARTS@MountRoot
; # Mount root partition for installation.
214 . @PARTS@FstabMounts
; # Mount rest of file systems from fstab.
215 . @PARTS@ShowSeries
; # Show software series.
216 . @PARTS@InstallPackages
; # Package installation.
217 . @PARTS@SetPassword
; # Set password for root.
218 . @PARTS@MenuBootloader
; # Boot loader installation.
219 . @PARTS@ConfServices
; # Running services.
220 . @PARTS@CopyConfig
; # Copy local config files (keymap, mouse).
222 umount
/media
/dragora-root
/dev
> /dev
/null
2>&1 || true
223 umount
/media
/dragora-root
/proc
> /dev
/null
2>&1 || true
225 if test -e /media
/dragora-root
/etc
/fstab
227 if mountpoint
-q /media
/dragora-medium
229 umount
/media
/dragora-medium
231 if test -s ${SUBTMPDIR}/SeTCDdev
234 dialog
--clear --colors \
235 --title "The Setup for Dragora has been completed" \
237 "\nWhen you are ready, you can press \Zb\Z7ENTER\Zn to eject the installation disc...\n" 8 70 || _status
=$?
238 if test $_status -eq 0
240 cdrom_device
="$(cat -- ${SUBTMPDIR}/CDDevice)"
242 # Try to eject using SCSI commands, fallback on CDROM eject command
243 eject
--scsi $cdrom_device || eject
--cdrom $cdrom_device
246 --title "The Setup for Dragora has been completed" \
247 --msgbox "\nPlease remove the installation disc.\n" 7 44 || true
249 # Attempt to use the tray close command
250 eject
-t $cdrom_device > /dev
/null
2>&1 || true
252 unset _status cdrom_device
259 dialog
--clear --colors \
260 --backtitle "\ZbSystem restart" \
261 --title "The Setup for Dragora has been completed" \
263 "\nWould you like to reboot the system now?.\n" 7 46 || _status
=$?
275 echo "Going out to the shell..."