archive: dragora-installer: added
[dragora.git] / archive / dragora-installer / dragora-installer
blob286461cf63e851eaf672eedbb7338536a6701365
1 #! /bin/sh -
3 # Dragora installer
5 # Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # Exit immediately on any error
20 set -e
22 PROGRAM="${0##*/}"
23 TMPDIR="${TMPDIR:-/tmp}"
24 TMPFILE="${TMPDIR}/${PROGRAM}.${RANDOM-0}$$"
25 LOCKFILE="${TMPDIR}/dragora-installer.lockfile"
26 OUTPUT_TTY=/dev/tty3
28 chkstatus_or_exit()
30 status=$?
32 # Clean up temporary files
33 rm -f -- "$TMPFILE" "$LOCKFILE"
35 # Clean up temporary subdirectory related to the installer
36 test -d "$SUBTMPDIR" && rm -rf -- "$SUBTMPDIR"
38 if test $status -ne 0
39 then
40 printf "%s\n" "" "Return status = $status" 1>&2
41 exit 2;
44 unset status
47 # Sanity checks
49 if test ! -d "$TMPDIR"
50 then
51 echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
52 exit 1;
54 if test ! -w "$TMPDIR"
55 then
56 echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
57 exit 1;
60 trap 'chkstatus_or_exit' EXIT HUP INT QUIT ABRT TERM
62 umask 077; # Remove access for all but user.
64 # Set a lock to allow only one instance of the installer
66 if ( set -C ; echo ": $PROGRAM - locked" > $LOCKFILE ) 2> /dev/null
67 then
68 true
69 else
70 if test -e "$LOCKFILE"
71 then
72 echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
73 exit 1;
74 else
75 echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
76 exit 2;
80 # Create subdirectory to store the files produced by the installer
82 SUBTMPDIR="${TMPDIR}/${PROGRAM}" # By default "/tmp/dragora-installer"
83 mkdir -p -m 700 -- $SUBTMPDIR
84 export SUBTMPDIR
86 # Detect and prepare list of Linux partition(s)
88 if fdisk -l | grep -q -m 1 Linux
89 then
90 fdisk -l | grep Linux | LC_COLLATE=C sort > ${SUBTMPDIR}/partitions
91 else
92 printf "%s\n" \
93 " Linux partitions were not detected." \
94 "" \
95 "A Linux partition is required to continue the installation. You can" \
96 "use utilities such as fdisk(8), cfdisk(8) or parted(8) to create at" \
97 "least one Linux partition. Then run \`${PROGRAM}' again." \
99 exit 1;
102 umask 022; # Remove write permission for group and other.
104 dialog --colors \
105 --backtitle "\ZbDragora 3.0 Installer" \
106 --hfile "HELP" \
107 --title "INSTALLER INFORMATION" \
108 --msgbox \
109 "Welcome to \Z3${PROGRAM}\Zn.\n\n\
110 This program prepares Dragora 3.0 to run on your computer.\n\n\
111 - To set up Dragora now, press \Zb\Z7ENTER\Zn.\n\n\
112 - To quit, press \Zb\Z7ESC\Zn.\n\n\
113 Please read the installer's help before proceeding (\Zb\Z7F1\Zn)." 14 63
115 # Try to detect and mount the hybrid ISO image, there may be a USB memory
116 # stick already inserted. If not, the media menu will be displayed.
118 if ! blkid -t LABEL="Dragora Packages" 2> /dev/null
119 then
120 dialog --colors \
121 --backtitle "\ZbInstallation Medium" \
122 --title "Pendrive/SDCard/CDROM" \
123 --msgbox \
124 "Please insert the media labeled as \"Dragora Packages\" and\n\
125 press \Zb\Z7ENTER\Zn to continue. Otherwise a media selection menu\n\
126 will be displayed." 7 63
127 if blkid -t LABEL="Dragora Packages" 2> /dev/null
128 then
129 mkdir -p -- /media/dragora-mount
130 mount -t iso9660 LABEL="Dragora Packages" /media/dragora-mount 2> /dev/null
131 echo "/media/dragora-mount/packages" > ${SUBTMPDIR}/MediumFound
132 else
133 . ./parts/MenuMedia
137 # Double-check to see the installation directory
138 if test ! -f "${SUBTMPDIR}/MediumFound"
139 then
140 dialog --colors \
141 --backtitle "\ZbInstallation Medium" \
142 --title "MEDIUM NOT FOUND" \
143 --sleep 7 --infobox \
144 "\nNo means of installation was found to proceed with\n\
145 the installation of Dragora. Please check your\n\
146 drives and the directory containing the software\n\
147 packages." 8 55
148 exit 99;