OSDN Git Service

initial support for gui installer
[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     echo "> Welcome to the instantOS installation
30 Continue" | instantmenu -w 600 -l 20 -c
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             NEWKEY="$(ls | instantmenu -p 'Select keyboard layout')"
41         else
42             NEWKEY="$(ls | fzf --prompt 'Select keyboard layout> ')"
43         fi
44     done
45
46     echo "$NEWKEY" >/root/instantARCH/config/keyboard
47
48     loadkeys $(tail -1 /root/instantARCH/data/lang/keyboard/"$NEWKEY")
49     guimode && setxkbmap -layout $(head -1 /root/instantARCH/data/lang/keyboard/"$NEWKEY")
50
51     cd ../locale
52     while [ -z "$NEWLOCALE" ]; do
53         if guimode; then
54             NEWLOCALE="$(ls | instantmenu -p 'Select language> ')"
55         else
56             NEWLOCALE="$(ls | fzf --prompt 'Select language> ')"
57         fi
58     done
59
60     echo "$NEWLOCALE" >/root/instantARCH/config/locale
61
62     cd /usr/share/zoneinfo
63
64     while [ -z "$REGION" ]; do
65         if guimode; then
66             REGION=$(ls | instantmenu -p "select region")
67         else
68             REGION=$(ls | fzf --prompt "select region> ")
69         fi
70     done
71
72     if [ -d "$REGION" ]; then
73         cd "$REGION"
74         while [ -z "$CITY" ]; do
75             if guimode; then
76                 CITY=$(ls | instantmenu -p "select the City nearest to you")
77             else
78                 CITY=$(ls | fzf --prompt "select the City nearest to you> ")
79             fi
80         done
81     fi
82
83     echo "$REGION" >/root/instantARCH/config/region
84     [ -n "$CITY" ] && echo "$CITY" >/root/instantARCH/config/city
85
86     while [ -z "$DISK" ]; do
87         DISK=$(fdisk -l | grep -i '^Disk /.*:' | fzf --prompt "select disk> ")
88         if guimode; then
89             if ! imenu -c "Install on $DISK ?\n this will delete all existing data"; then
90                 unset DISK
91             fi
92         else
93             if ! confirm "Install on $DISK ?\n this will delete all existing data"; then
94                 unset DISK
95             fi
96         fi
97     done
98
99     echo "$DISK" | grep -o '/dev/[^:]*' >/root/instantARCH/config/disk
100
101     NEWUSER="$(textbox 'set username')"
102
103     while ! [ "$NEWPASS" = "$NEWPASS2" ] || [ -z "$NEWPASS" ]; do
104         if guimode; then
105             NEWPASS="$(imenu -P 'set password')"
106             NEWPASS2="$(imenu -P 'confirm password')"
107         else
108             NEWPASS="$(passwordbox 'set password')"
109             NEWPASS2="$(passwordbox 'confirm password')"
110         fi
111     done
112
113     echo "$NEWUSER" >/root/instantARCH/config/user
114     echo "$NEWPASS" >/root/instantARCH/config/password
115
116     while [ -z "$NEWHOSTNAME" ]; do
117         if guimode; then
118             NEWHOSTNAME=$(imenu -i "enter name of this computer")
119         else
120             NEWHOSTNAME=$(textbox "enter name of this computer")
121         fi
122     done
123
124     echo "$NEWHOSTNAME" >/root/instantARCH/config/hostname
125
126     SUMMARY="Installation Summary:"
127
128     addsum() {
129         SUMMARY="$SUMMARY
130         $1: $(cat /root/instantARCH/config/$2)"
131     }
132
133     addsum "Username" "user"
134     addsum "Locale" "locale"
135     addsum "Region" "region"
136     addsum "Nearest City" "city"
137     addsum "Keyboard layout" "keyboard"
138     addsum "Target install drive" "disk"
139     addsum "Hostname" "hostname"
140     if efibootmgr; then
141         addsum "GRUB" "UEFI"
142     else
143         addsum "GRUB" "BIOS"
144     fi
145
146     SUMMARY="$SUMMARY
147 Should installation proceed with these parameters?"
148
149     if guimode; then
150         if imenu -C <<<"$SUMMARY"; then
151             touch /root/instantARCH/config/confirm
152         else
153             unset CITY
154             unset REGION
155             unset DISK
156             unset NEWKEY
157             unset NEWLOCALE
158             unset NEWPASS2
159             unset NEWPASS
160             unset NEWHOSTNAME
161             unset NEWUSER
162         fi
163     else
164         if confirm "$SUMMARY"; then
165             touch /root/instantARCH/config/confirm
166         else
167             unset CITY
168             unset REGION
169             unset DISK
170             unset NEWKEY
171             unset NEWLOCALE
172             unset NEWPASS2
173             unset NEWPASS
174             unset NEWHOSTNAME
175             unset NEWUSER
176         fi
177     fi
178 done
179
180 messagebox "The installation will now begin. This could take a while. Keep the machine powered and connected to the internet"
181 clear