stages: 2/04-iso: Do not include kernel build/source tree in the LiveCD
[dragora.git] / archive / dragora-installer / dragora-installer
blob83bde8646415115d371d25ac6f66a6f633d211d2
1 #! /bin/sh -
3 # The installer of Dragora GNU/Linux-Libre
5 # Copyright (c) 2019-2023 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
21 set -e
23 PROGRAM="${0##*/}"
24 TMPDIR="${TMPDIR:-$HOME}"
25 TMPFILE="${TMPDIR}/${PROGRAM}.${RANDOM-0}$$"
26 LOCKFILE=/tmp/dragora-installer.lockfile
28 # Override locale settings
29 LANG=C
30 LC_ALL=C
31 export LANG LC_ALL
33 unmountFilesystems()
35 for filesystem in \
36 /media/dragora-root/sys \
37 /media/dragora-root/proc \
38 /media/dragora-root/dev \
39 /media/dragora-root \
40 /media/dragora-packages ; \
42 if mountpoint -q "$filesystem"
43 then
44 echo ""
45 echo ""
46 echo "Unmounting $(findmnt -n -o SOURCE $filesystem) from $filesystem ..."
47 if ! umount -v -R "$filesystem"
48 then
49 echo " ^ Doing a lazy unmount for \`${filesystem}' ..."
50 umount -v -l "$filesystem"
53 done
54 unset -v filesystem
57 chkstatus_or_exit()
59 status=$?
61 # Clean up temporary files
62 rm -f -- "$TMPFILE" "$LOCKFILE"
64 # Clean up temporary subdirectory if 'PRESERVE' is unset or null
65 test -z "$PRESERVE" && rm -rf -- "$SUBTMPDIR"
67 # Unmount possible (previously) mounted file systems
68 unmountFilesystems
70 if test $status -ne 0
71 then
72 printf '%s\n' "" "^ Return status = $status" 1>&2
73 exit 2;
76 unset -v status
79 # Sanity checks
81 if test ! -d "$TMPDIR"
82 then
83 echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
84 exit 1;
86 if test ! -w "$TMPDIR"
87 then
88 echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
89 exit 1;
92 trap 'chkstatus_or_exit' EXIT HUP INT QUIT ABRT TERM
94 umask 077; # Remove access for all but user.
96 # Set a lock to allow only one instance of the installer
98 if ( set -C ; echo ": $PROGRAM - locked" > $LOCKFILE ) 2> /dev/null
99 then
100 true
101 else
102 if test -e "$LOCKFILE"
103 then
104 echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
105 exit 1;
106 else
107 echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
108 exit 2;
112 # Remove write permission for group and other
113 umask 022
115 # Create subdirectory to store the files produced by the installer
117 # Default sets to "${HOME}/.dragora-installer"
118 SUBTMPDIR="${TMPDIR}/.${PROGRAM}"
119 mkdir -p -- "$SUBTMPDIR"
120 chmod 700 -- "$SUBTMPDIR"
122 # Detect and prepare initial list of Linux partition(s)
124 if fdisk -l | sed -e 's|Linux filesystem|Linux|g' | grep -E -q -m 1 'Linux$'
125 then
126 fdisk -l | sed -e 's|Linux filesystem|Linux|g' | grep -E 'Linux$' | \
127 sort > "${SUBTMPDIR}/partitions"
128 else
129 cat 1>&2 << EOF
130 Linux partitions were not detected.
132 A Linux partition is required to continue the installation. You can
133 use utilities such as fdisk(8), cfdisk(8) or parted(8) to create at
134 least one Linux partition. Then run \`${PROGRAM}' again.
136 exit 1;
139 # Determine the maximum size of the terminal to be used on the dialogues
141 echo "Checking terminal size ..."
142 LINES="${LINES:-$(tput lines)}"
143 COLUMNS="${COLUMNS:-$(tput cols)}"
145 export SUBTMPDIR LINES COLUMNS
147 dialog --colors \
148 --backtitle "\\ZbThe installer of Dragora GNU/Linux-Libre 3.0" \
149 --title "INSTALLER INFORMATION" \
150 --cr-wrap --msgbox \
151 "Welcome to \\Z3${PROGRAM}\\Zn.
153 This program will help you install Dragora 3.0 on your computer.
155 Use the cursor keys to move around in the installer's menus.
157 Press \\Z3[Tab]\\Zn to jump to the next option and \
158 \\Z3[Shift]\\Zn\\Zb\\Z7+\\Zn\\Z3[Tab]\\Zn to jump to the previous one.
160 Use \\Z3[Space]\\Zn to select or unselect an item, \\Z3[Enter]\\Zn to \
161 confirm or proceed to the next menu.
163 You can use \\Z3[Ctrl]\\Zn\\Zb\\Z7+\\Zn\\Z3[C]\\Zn to abort the \
164 installation at any time.
166 To quit a dialog (such as the one you are in), press \\Z3[Esc]\\Zn.
168 " $((LINES - 4)) $((COLUMNS - 8))
170 # Try to detect and mount the hybrid ISO image, there may be a USB memory
171 # stick already inserted. If not, the media menu will be displayed.
173 mkdir -p -- /media/dragora-packages
175 if ! blkid -t LABEL="Dragora Packages" > /dev/null
176 then
177 dialog --colors \
178 --backtitle "\\ZbInstallation Medium" \
179 --title "Pendrive/SDCard/CDROM" \
180 --cr-wrap --msgbox \
182 Please insert the medium labeled \"Dragora Packages\" and
183 press \\Z3[Enter]\\Zn to continue. Otherwise, a media selection
184 menu will be displayed.
185 " 9 60
186 if blkid -t LABEL="Dragora Packages" > /dev/null
187 then
188 if ! mountpoint -q /media/dragora-packages
189 then
190 mount -v -t iso9660 LABEL="Dragora Packages" \
191 /media/dragora-packages
192 echo '/media/dragora-packages/packages' \
193 > "${SUBTMPDIR}/MediumFound"
194 sleep 1
196 else
197 . @PARTS@MenuMedia
199 else
200 if ! mountpoint -q /media/dragora-packages
201 then
202 mount -v -t iso9660 LABEL="Dragora Packages" /media/dragora-packages
203 sleep 2
205 echo '/media/dragora-packages/packages' > "${SUBTMPDIR}/MediumFound"
208 # Attempt to unmount possible pre-mounted filesystem(s)
209 mountpoint -q /media/dragora-root/sys && umount /media/dragora-root/sys
210 mountpoint -q /media/dragora-root/proc && umount /media/dragora-root/proc
211 mountpoint -q /media/dragora-root/dev && umount /media/dragora-root/dev
213 # Clean up possible empty mount-directories
214 rmdir -- /media/dragora-packages /media/dragora-root 2> /dev/null || true
216 # Double-check to see the installation directory
217 if test ! -f "${SUBTMPDIR}/MediumFound"
218 then
219 dialog --colors \
220 --backtitle "\\ZbInstallation Medium" \
221 --title "MEDIUM NOT FOUND" \
222 --sleep 5 --cr-wrap --infobox \
224 No means of installation was found to proceed
225 with the installation of Dragora.
227 Please check your drives and the directory
228 containing the software packages...
229 " 9 49
230 exit 99;
233 . @PARTS@MakeSwap; # Swap devices.
234 . @PARTS@MakeFS; # Linux partitions.
235 . @PARTS@FstabEdit; # File system table edition (fstab).
236 . @PARTS@MountRoot; # Mount root partition for installation.
237 . @PARTS@FstabMounts; # Mount rest of file systems from fstab.
238 . @PARTS@ShowSeries; # Software series.
239 . @PARTS@InstallPackages; # Package installation.
240 . @PARTS@PostInstall; # Post-installation.
241 . @PARTS@SetPassword; # Password for root.
242 . @PARTS@MenuBootloader; # Boot loader installation.
243 . @PARTS@ConfServices; # Running services.
245 if test -e /media/dragora-root/etc/fstab
246 then
247 if mountpoint -q /media/dragora-packages
248 then
249 umount /media/dragora-packages
251 if test -s "${SUBTMPDIR}/SeTCDdev"
252 then
253 _status=0
254 dialog --clear --colors \
255 --title "The Setup for Dragora has been completed" \
256 --cr-wrap --msgbox \
258 If you are ready, press \\Z3[Enter]\\Zn to eject
259 the installation disc...
260 " 8 0 || _status=$?
262 if test $_status -eq 0
263 then
264 cdrom_device="$(cat -- "${SUBTMPDIR}/CDDevice")"
266 # Try to eject using SCSI commands, fallback on CDROM eject command
267 eject --scsi "$cdrom_device" || eject --cdrom "$cdrom_device"
269 dialog \
270 --title "The Setup for Dragora has been completed" \
271 --msgbox "\\nPlease remove the installation disc.\\n" 7 44 || true
273 # Attempt to use the tray close command
274 eject -t "$cdrom_device" > /dev/null 2>&1 || true
276 unset -v _status cdrom_device
280 sync
282 _status=0
284 dialog --clear --colors \
285 --backtitle "\\ZbSystem restart" \
286 --title "The Setup for Dragora has been completed." \
287 --cr-wrap --yesno \
289 Would you like to reboot the system now?
290 " 7 45 || _status=$?
292 case $_status in
294 unset -v _status
295 dialog --clear
296 unmountFilesystems
297 exec reboot -d -f
300 unset -v _status
301 unmountFilesystems
302 echo ""
303 echo ""
304 echo ""
305 echo "Going out to the shell ..."
306 echo ""
307 echo ""
308 exit 0
310 esac