OSDN Git Service

another fix
[instantos/instantARCH.git] / ask.sh
1 #!/bin/bash
2
3 mkdir /root/instantARCH/config
4 mkdir config
5
6 source <(curl -Ls git.io/paperbash)
7 pb dialog
8
9 if [ -e /usr/share/liveutils ]; then
10     echo "GUI Mode active"
11     export GUIMODE="True"
12     GUIMODE="True"
13 fi
14
15 # check if the install session is GUI or cli
16 guimode() {
17     if [ -e /opt/noguimode ]; then
18         return 1
19     fi
20
21     if [ -n "$GUIMODE" ]; then
22         return 0
23     else
24         return 1
25     fi
26 }
27
28 if guimode; then
29     pgrep instantmenu && pkill instantmenu
30     imenu -m "Welcome to the instantOS installer"
31 else
32     messagebox "Welcome to the instantOS installer"
33 fi
34
35 # go back to the beginning if user isn't happy with settings
36 while ! [ -e /root/instantARCH/config/confirm ]; do
37     cd /root/instantARCH/data/lang/keyboard
38     while [ -z "$NEWKEY" ]; do
39         if guimode; then
40             feh --bg-scale /usr/share/liveutils/worldmap.jpg &
41             NEWKEY="$(ls | imenu -l 'Select keyboard layout')"
42         else
43             NEWKEY="$(ls | fzf --prompt 'Select keyboard layout> ')"
44         fi
45
46         # allow directly typing in layout name
47         if [ "$NEWKEY" = "other" ]; then
48             if guimode; then
49                 OTHERKEY="$(localectl list-x11-keymap-layouts | instantmenu -l 20 -c -p 'select keyboard layout')"
50             else
51                 OTHERKEY="$(localectl list-x11-keymap-layouts | fzf --prompt 'select keyboard layout')"
52             fi
53
54             if [ -z "$OTHERKEY" ]; then
55                 unset NEWKEY
56             else
57                 echo "
58 $OTHERKEY" >/root/instantARCH/data/lang/keyboard/other
59             fi
60         fi
61
62     done
63
64     # option to cancel the installer
65     if [ "${NEWKEY}" = "forcequit" ]; then
66         exit 1
67     fi
68
69     echo "$NEWKEY" >/root/instantARCH/config/keyboard
70
71     if head -1 /root/instantARCH/data/lang/keyboard/"$NEWKEY" | greo -q '[^ ][^ ]'; then
72         loadkeys $(head -1 /root/instantARCH/data/lang/keyboard/"$NEWKEY")
73     fi
74
75     guimode && setxkbmap -layout $(tail -1 /root/instantARCH/data/lang/keyboard/"$NEWKEY")
76
77     cd ../locale
78     while [ -z "$NEWLOCALE" ]; do
79         if guimode; then
80             NEWLOCALE="$(ls | imenu -l 'Select language> ')"
81         else
82             NEWLOCALE="$(ls | fzf --prompt 'Select language> ')"
83         fi
84     done
85
86     echo "$NEWLOCALE" >/root/instantARCH/config/locale
87
88     cd /usr/share/zoneinfo
89
90     while [ -z "$REGION" ]; do
91         if guimode; then
92             REGION=$(ls | imenu -l "select region")
93         else
94             REGION=$(ls | fzf --prompt "select region> ")
95         fi
96     done
97
98     if [ -d "$REGION" ]; then
99         cd "$REGION"
100         while [ -z "$CITY" ]; do
101             if guimode; then
102                 CITY=$(ls | imenu -l "select the City nearest to you")
103             else
104                 CITY=$(ls | fzf --prompt "select the City nearest to you> ")
105             fi
106         done
107     fi
108
109     echo "$REGION" >/root/instantARCH/config/region
110     [ -n "$CITY" ] && echo "$CITY" >/root/instantARCH/config/city
111
112     while [ -z "$DISK" ]; do
113         if guimode; then
114             feh --bg-scale /usr/share/liveutils/install.jpg &
115             DISK=$(fdisk -l | grep -i '^Disk /.*:' | imenu -l "select disk> ")
116             if ! echo "Install on $DISK ?
117 this will delete all existing data" | imenu -C; then
118                 unset DISK
119             fi
120         else
121             DISK=$(fdisk -l | grep -i '^Disk /.*:' | fzf --prompt "select disk> ")
122             if ! confirm "Install on $DISK ?\n this will delete all existing data"; then
123                 unset DISK
124             fi
125         fi
126     done
127
128     echo "$DISK" | grep -o '/dev/[^:]*' >/root/instantARCH/config/disk
129
130     # select drivers
131     if lspci | grep -iq 'nvidia'; then
132         echo "nvidia card detected"
133         while [ -z "$DRIVERCHOICE" ]; do
134             if guimode; then
135                 DRIVERCHOICE="$(echo 'nvidia proprietary (recommended)
136 nvidia-dkms (try if proprietary doesn't work)
137 nouveau open source
138 install without graphics drivers (not recommended)' | imenu -l 'select graphics drivers')"
139
140                 if grep -q "without" <<<"$DRIVERCHOICE"; then
141                     if ! echo "are you sure you do not want to install graphics drivers?
142 This could prevent the system from booting" | imenu -C; then
143                         unset DRIVERCHOICE
144                     fi
145                 fi
146             else
147
148                 while [ -z "$DRIVERCHOICE" ]; do
149                     while [ -z "$DRIVERCHOICE" ]; do
150                         DRIVERCHOICE="$(echo 'nvidia proprietary (recommended)
151 nvidia-dkms (try if proprietary doesn't work)
152 nouveau open source
153 install without graphics (not recommended)' | fzf --prompt 'select graphics drivers')"
154
155                     done
156
157                     if grep -q "without" <<<"$DRIVERCHOICE"; then
158                         if ! confirm "are you sure you do not want to install graphics drivers?
159 This could prevent the system from booting"; then
160                             unset DRIVERCHOICE
161                         fi
162                     fi
163                 done
164
165             fi
166         done
167
168         if grep -qi "dkms" <<<"$DRIVERCHOICE"; then
169             echo "dkms" >/root/instantARCH/config/graphics
170         elif grep -qi "nvidia" <<<"$DRIVERCHOICE"; then
171             echo "nvidia" >/root/instantARCH/config/graphics
172         elif grep -qi "open" <<<"$DRIVERCHOICE"; then
173             echo "open" >/root/instantARCH/config/graphics
174         elif [ -z "$DRIVERCHOICE" ]; then
175             echo "nodriver" >/root/instantARCH/config/graphics
176         fi
177
178     else
179         echo "no nvidia card detected"
180     fi
181
182     while [ -z $NEWUSER ]; do
183         if guimode; then
184             feh --bg-scale /usr/share/liveutils/user.jpg &
185             NEWUSER="$(imenu -i 'set username')"
186         else
187             NEWUSER="$(textbox 'set username')"
188         fi
189
190         # validate input as a unix name
191         if ! grep -Eq '^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$' <<<"$NEWUSER"; then
192             if guimode; then
193                 imenu -m "invalid username"
194             else
195                 msgbox "invalid username"
196             fi
197             unset NEWUSER
198         fi
199     done
200
201     while ! [ "$NEWPASS" = "$NEWPASS2" ] || [ -z "$NEWPASS" ]; do
202         if guimode; then
203             NEWPASS="$(imenu -P 'set password')"
204             NEWPASS2="$(imenu -P 'confirm password')"
205         else
206             NEWPASS="$(passwordbox 'set password')"
207             NEWPASS2="$(passwordbox 'confirm password')"
208         fi
209     done
210
211     echo "$NEWUSER" >/root/instantARCH/config/user
212     echo "$NEWPASS" >/root/instantARCH/config/password
213
214     while [ -z "$NEWHOSTNAME" ]; do
215         if guimode; then
216             NEWHOSTNAME=$(imenu -i "enter name of this computer")
217         else
218             NEWHOSTNAME=$(textbox "enter name of this computer")
219         fi
220     done
221
222     echo "$NEWHOSTNAME" >/root/instantARCH/config/hostname
223
224     guimode && feh --bg-scale /usr/share/liveutils/install.jpg &
225     SUMMARY="Installation Summary:"
226
227     addsum() {
228         SUMMARY="$SUMMARY
229         $1: $(cat /root/instantARCH/config/$2)"
230     }
231
232     addsum "Username" "user"
233     addsum "Locale" "locale"
234     addsum "Region" "region"
235     addsum "Nearest City" "city"
236     addsum "Keyboard layout" "keyboard"
237     addsum "Target install drive" "disk"
238     addsum "Hostname" "hostname"
239
240     if efibootmgr; then
241         SUMMARY="$SUMMARY
242 GRUB: UEFI"
243     else
244         SUMMARY="$SUMMARY
245 GRUB: BIOS"
246     fi
247
248     SUMMARY="$SUMMARY
249 Should installation proceed with these parameters?"
250
251     if guimode; then
252         if imenu -C <<<"$SUMMARY"; then
253             touch /root/instantARCH/config/confirm
254         else
255             unset CITY
256             unset REGION
257             unset DISK
258             unset NEWKEY
259             unset NEWLOCALE
260             unset NEWPASS2
261             unset NEWPASS
262             unset NEWHOSTNAME
263             unset NEWUSER
264         fi
265     else
266         if confirm "$SUMMARY"; then
267             touch /root/instantARCH/config/confirm
268         else
269             unset CITY
270             unset REGION
271             unset DISK
272             unset NEWKEY
273             unset NEWLOCALE
274             unset NEWPASS2
275             unset NEWPASS
276             unset NEWHOSTNAME
277             unset NEWUSER
278         fi
279     fi
280 done
281
282 if guimode; then
283     imenu -M <<<"The installation will now begin.
284     This could take a while.
285     Keep the machine powered and connected to the internet" &
286 else
287     messagebox "The installation will now begin. This could take a while. Keep the machine powered and connected to the internet"
288     clear
289 fi