OSDN Git Service

fix mirrorlist generator
[instantos/instantARCH.git] / askutils.sh
1 #!/bin/bash
2
3 # User questions are seperated into functions to be reused in alternative installers
4 # like topinstall.sh
5
6 # check if the install session is GUI or cli
7
8 if [ -z "$INSTANTARCH" ]; then
9     echo "defaulting instantarch location to /root/instantARCH"
10     INSTANTARCH="/root/instantARCH"
11 fi
12
13 guimode() {
14     if [ -e /opt/noguimode ]; then
15         return 1
16     fi
17
18     if [ -n "$GUIMODE" ]; then
19         return 0
20     else
21         return 1
22     fi
23 }
24
25 # add installation info to summary
26 addsum() {
27     SUMMARY="$SUMMARY
28         $1: $(iroot $2)"
29 }
30
31 # set status wallpaper
32 wallstatus() {
33     guimode && feh --bg-scale /usr/share/liveutils/$1.jpg &
34 }
35
36 artixinfo() {
37     if command -v systemctl; then
38         echo "regular arch/manjaro detected"
39         return
40     fi
41
42     echo "You appear to be installing the non-systemd version of instantOS.
43 Support for non-systemd setups is experimental
44 Any issues should be solvable with manual intervention
45 Here's a list of things that do not work from the installer and how to work around them:
46 disk editor: set up partitions beforehand or use automatic partitioning
47 keyboard locale: set it manually after installation in the settings
48 systemd-swap (obviously)" | imenu -M
49
50 }
51
52 # ask for keyboard layout
53 asklayout() {
54     cd "$INSTANTARCH"/data/lang/keyboard
55     while [ -z "$NEWKEY" ]; do
56         wallstatus worldmap
57         NEWKEY="$(ls | imenu -l 'Select keyboard layout ')"
58
59         # allow directly typing in layout name
60         if [ "$NEWKEY" = "other" ]; then
61             if command -v localectl; then
62                 OTHERKEY="$(localectl list-x11-keymap-layouts | imenu -l 'select keyboard layout ')"
63
64                 if [ -z "$OTHERKEY" ]; then
65                     unset NEWKEY
66                 else
67                     # newline is intentional!!!
68                     echo "
69 $OTHERKEY" >/root/instantARCH/data/lang/keyboard/other
70                 fi
71             else
72                 imenu -m "not supported yet without systemd"
73                 unset NEWKEY
74             fi
75         fi
76
77     done
78
79     # option to cancel the installer
80     if [ "${NEWKEY}" = "forcequit" ]; then
81         exit 1
82     fi
83     iroot keyboard "$NEWKEY"
84 }
85
86 # ask for default locale
87 asklocale() {
88     cd "$INSTANTARCH"/data/lang/locale
89     while [ -z "$NEWLOCALE" ]; do
90         NEWLOCALE="$(ls | imenu -l 'Select language> ')"
91     done
92     iroot locale "$NEWLOCALE"
93
94 }
95
96 # ask for region with region/city
97 askregion() {
98     cd /usr/share/zoneinfo
99     while [ -z "$REGION" ]; do
100         REGION=$(ls | imenu -l "select region ")
101     done
102
103     if [ -d "$REGION" ]; then
104         cd "$REGION"
105         while [ -z "$CITY" ]; do
106             CITY=$(ls | imenu -l "select the City nearest to you ")
107         done
108     fi
109
110     iroot region "$REGION"
111     [ -n "$CITY" ] && iroot city "$CITY"
112
113 }
114
115 # choose between different nvidia drivers
116 askdrivers() {
117     if lspci | grep -iq 'nvidia'; then
118         echo "nvidia card detected"
119         while [ -z "$DRIVERCHOICE" ]; do
120             DRIVERCHOICE="$(echo 'nvidia proprietary (recommended)
121 nvidia-dkms (try if proprietary does not work)
122 nouveau open source
123 install without graphics drivers (not recommended)' | imenu -l 'select graphics drivers')"
124
125             if grep -q "without" <<<"$DRIVERCHOICE"; then
126                 if ! echo "are you sure you do not want to install graphics drivers?
127 This could prevent the system from booting" | imenu -C; then
128                     unset DRIVERCHOICE
129                 fi
130             fi
131
132         done
133
134         if grep -qi "dkms" <<<"$DRIVERCHOICE"; then
135             iroot graphics "dkms"
136         elif grep -qi "nvidia" <<<"$DRIVERCHOICE"; then
137             iroot graphics "nvidia"
138         elif grep -qi "open" <<<"$DRIVERCHOICE"; then
139             iroot graphics "open"
140         elif [ -z "$DRIVERCHOICE" ]; then
141             iroot graphics "nodriver"
142         fi
143
144     else
145         echo "no nvidia card detected"
146     fi
147
148 }
149
150 # offer to choose mirror country
151 askmirrors() {
152     iroot askmirrors 1
153     MIRRORCODE="$({
154         echo 'auto detect mirrors (not recommended for speed)'
155         curl -s 'https://archlinux.org/mirrorlist/all/' | grep '##' | grep -iEv '(linux|arch|generated|filter)' |
156             grep -o '[^# ]*' | grep '.....'
157     } | imenu -l 'select mirror location')"
158
159     if grep -q 'auto detect' <<<"$MIRRORCODE"; then
160         iroot automirrors 1
161     else
162         iroot countrycode "$MIRRORCODE"
163         if echo '> manually sorting mirrors may take a long time
164 use arch ranking score (recommended)
165 sort all mirrors by speed' | imenu -l 'choose mirror settings' | grep -q 'speed'; then
166             iroot sortmirrors 1
167         fi
168     fi
169 }
170
171 # ask for user details
172 askuser() {
173     while [ -z "$NEWUSER" ]; do
174         wallstatus user
175         NEWUSER="$(imenu -i 'set username')"
176
177         # validate input as a unix name
178         if ! grep -Eq '^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$' <<<"$NEWUSER"; then
179             imenu -e "invalid username, usernames must not contain spaces or special symbols and start with a lowercase letter"
180             unset NEWUSER
181         fi
182     done
183
184     while ! [ "$NEWPASS" = "$NEWPASS2" ] || [ -z "$NEWPASS" ]; do
185         NEWPASS="$(imenu -P 'set password')"
186         NEWPASS2="$(imenu -P 'confirm password')"
187         if ! [ "$NEWPASS" = "$NEWPASS2" ]; then
188             echo "the confirmation password doesn't match.
189 Please enter a new password" | imenu -M
190         fi
191     done
192
193     iroot user "$NEWUSER"
194     iroot password "$NEWPASS"
195
196 }
197
198 # ask about which hypervisor is used
199 askvm() {
200     if imvirt | grep -iq 'physical'; then
201         echo "system does not appear to be a virtual machine"
202         return
203     fi
204
205     while [ -z "$VIRTCONFIRM" ]; do
206         if ! imenu -c "is this system a virtual machine?"; then
207             if echo "Are you sure it's not?
208 giving the wrong answer here might greatly decrease performance. " | imenu -C; then
209                 return
210             fi
211         else
212             VIRTCONFIRM="true"
213         fi
214     done
215     iroot isvm 1
216
217     echo "virtualbox
218 kvm/qemu
219 other" | imenu -l "which hypervisor is being used?" >/tmp/vmtype
220
221     HYPERVISOR="$(cat /tmp/vmtype)"
222     case "$HYPERVISOR" in
223     kvm*)
224         if grep 'vendor' /proc/cpuinfo | grep -iq 'AMD'; then
225             echo "WARNING:
226         kvm/QEMU on AMD is not meant for desktop use and
227         is lacking some graphics features.
228         This installation will work, but some features will have to be disabled and
229         others might not perform well. 
230         It is highly recommended to use Virtualbox instead." | imenu -M
231             iroot kvm 1
232             if lshw -c video | grep -iq 'qxl'; then
233                 echo "WARNING:
234 QXL graphics detected
235 These may trigger a severe Xorg memory leak on kvm/QEMU on AMD,
236 leading to degraded video and input performance,
237 please switch your video card to either virtio or passthrough
238 until this is fixed" | imenu -M
239             fi
240         fi
241         ;;
242     virtualbox)
243         iroot virtualbox 1
244         if imenu -c "would you like to install virtualbox guest additions?"; then
245             iroot guestadditions 1
246         fi
247         ;;
248     other)
249         iroot othervm 1
250         echo "selecting other"
251         ;;
252     esac
253
254 }