recipes: optimize lzlib and plzip
[dragora.git] / archive / dragora-installer / dragora-installer
blob9ba6a36edb4def0644523fee9f70bf8abf1ea515
1 #! /bin/sh -
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
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 LC_ALL=C
30 LANGUAGE=C
31 export LC_ALL LANGUAGE
33 chkstatus_or_exit()
35 status=$?
37 # Clean up temporary files
38 rm -f -- "$TMPFILE" "$LOCKFILE"
40 # Clean up temporary subdirectory related to the installer
41 if test -z "$PRESERVE"
42 then
43 rm -rf -- "$SUBTMPDIR"
46 if test $status -ne 0
47 then
48 printf "%s\n" "" "^ Return status = $status" 1>&2
49 exit 2;
52 unset status
55 # Sanity checks
57 if test ! -d "$TMPDIR"
58 then
59 echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
60 exit 1;
62 if test ! -w "$TMPDIR"
63 then
64 echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
65 exit 1;
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
75 then
76 true
77 else
78 if test -e "$LOCKFILE"
79 then
80 echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
81 exit 1;
82 else
83 echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
84 exit 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
98 then
99 fdisk -l | grep Linux | grep -v swap | LC_COLLATE=C sort \
100 > ${SUBTMPDIR}/partitions
101 else
102 printf "%s\n" \
103 " Linux partitions were not detected." \
104 "" \
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."
108 exit 1;
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 ..."
114 if test -z "$LINES"
115 then
116 LINES="$(tput lines)" || \
117 { LINES="$(stty size)" && LINES="${LINES% *}"; }
119 if test -z "$COLUMNS"
120 then
121 COLUMNS="$(tput cols)" || \
122 { COLUMNS="$(stty size)" && COLUMNS="${COLUMNS#* }"; }
124 echo "$LINES $COLUMNS"
126 export SUBTMPDIR LINES COLUMNS
128 dialog --colors \
129 --backtitle "\ZbDragora 3.0 Installer" \
130 --title "INSTALLER INFORMATION" \
131 --cr-wrap --msgbox \
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
140 any time.
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
147 \Z3[-ENTER-]\Zn
148 \Z3[c]\Zn \Z3[^]\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
158 then
159 dialog --colors \
160 --backtitle "\ZbInstallation Medium" \
161 --title "Pendrive/SDCard/CDROM" \
162 --msgbox \
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
167 then
168 if ! mountpoint -q /media/dragora-medium
169 then
170 mount -v -t iso9660 LABEL="Dragora Packages" /media/dragora-medium && \
171 echo "/media/dragora-medium/packages" > ${SUBTMPDIR}/MediumFound
172 sleep 2
174 else
175 . @PARTS@MenuMedia
177 else
178 if ! mountpoint -q /media/dragora-medium
179 then
180 mount -v -t iso9660 LABEL="Dragora Packages" /media/dragora-medium
181 sleep 2
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
192 rmdir -- \
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"
198 then
199 dialog --colors \
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\
206 packages." 8 55
207 exit 99;
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
226 then
227 if mountpoint -q /media/dragora-medium
228 then
229 umount /media/dragora-medium
231 if test -s ${SUBTMPDIR}/SeTCDdev
232 then
233 _status=0
234 dialog --clear --colors \
235 --title "The Setup for Dragora has been completed" \
236 --msgbox \
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
239 then
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
245 dialog \
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
256 sync
258 _status=0
259 dialog --clear --colors \
260 --backtitle "\ZbSystem restart" \
261 --title "The Setup for Dragora has been completed" \
262 --yesno \
263 "\nWould you like to reboot the system now?.\n" 7 46 || _status=$?
264 case $_status in
266 unset _status
267 dialog --clear
268 exec reboot -d -f
271 unset _status
272 echo ""
273 echo ""
274 echo ""
275 echo "Going out to the shell..."
276 echo ""
277 echo ""
278 exit 0
280 esac