OSDN Git Service

fix mirrorlist generator
[instantos/instantARCH.git] / askutils.sh
index 687cc9e..e18d64c 100755 (executable)
@@ -4,6 +4,12 @@
 # like topinstall.sh
 
 # check if the install session is GUI or cli
+
+if [ -z "$INSTANTARCH" ]; then
+    echo "defaulting instantarch location to /root/instantARCH"
+    INSTANTARCH="/root/instantARCH"
+fi
+
 guimode() {
     if [ -e /opt/noguimode ]; then
         return 1
@@ -27,25 +33,47 @@ wallstatus() {
     guimode && feh --bg-scale /usr/share/liveutils/$1.jpg &
 }
 
+artixinfo() {
+    if command -v systemctl; then
+        echo "regular arch/manjaro detected"
+        return
+    fi
+
+    echo "You appear to be installing the non-systemd version of instantOS.
+Support for non-systemd setups is experimental
+Any issues should be solvable with manual intervention
+Here's a list of things that do not work from the installer and how to work around them:
+disk editor: set up partitions beforehand or use automatic partitioning
+keyboard locale: set it manually after installation in the settings
+systemd-swap (obviously)" | imenu -M
+
+}
+
 # ask for keyboard layout
 asklayout() {
-    cd /root/instantARCH/data/lang/keyboard
+    cd "$INSTANTARCH"/data/lang/keyboard
     while [ -z "$NEWKEY" ]; do
         wallstatus worldmap
         NEWKEY="$(ls | imenu -l 'Select keyboard layout ')"
 
         # allow directly typing in layout name
         if [ "$NEWKEY" = "other" ]; then
-            OTHERKEY="$(localectl list-x11-keymap-layouts | imenu -l 'select keyboard layout ')"
-
-            if [ -z "$OTHERKEY" ]; then
-                unset NEWKEY
-            else
-                # newline is intentional!!!
-                echo "
+            if command -v localectl; then
+                OTHERKEY="$(localectl list-x11-keymap-layouts | imenu -l 'select keyboard layout ')"
+
+                if [ -z "$OTHERKEY" ]; then
+                    unset NEWKEY
+                else
+                    # newline is intentional!!!
+                    echo "
 $OTHERKEY" >/root/instantARCH/data/lang/keyboard/other
+                fi
+            else
+                imenu -m "not supported yet without systemd"
+                unset NEWKEY
             fi
         fi
+
     done
 
     # option to cancel the installer
@@ -57,7 +85,7 @@ $OTHERKEY" >/root/instantARCH/data/lang/keyboard/other
 
 # ask for default locale
 asklocale() {
-    cd /root/instantARCH/data/lang/locale
+    cd "$INSTANTARCH"/data/lang/locale
     while [ -z "$NEWLOCALE" ]; do
         NEWLOCALE="$(ls | imenu -l 'Select language> ')"
     done
@@ -79,6 +107,7 @@ askregion() {
         done
     fi
 
+    iroot region "$REGION"
     [ -n "$CITY" ] && iroot city "$CITY"
 
 }
@@ -120,35 +149,34 @@ This could prevent the system from booting" | imenu -C; then
 
 # offer to choose mirror country
 askmirrors() {
-    curl -s 'https://www.archlinux.org/mirrorlist/' | grep -i '<option value' >/tmp/mirrors.html
-    grep -v '>All<' /tmp/mirrors.html | sed 's/.*<option value=".*">\(.*\)<\/option>.*/\1/g' |
-        sed -e "1iauto detect mirrors" |
-        imenu -l "choose mirror location" >/tmp/mirrorselect
-    if ! grep -q 'auto detect' </tmp/mirrorselect; then
-        cat /tmp/mirrors.html | grep ">$(cat /tmp/mirrorselect)<" | grep -o '".*"' | grep -o '[^"]*' >/tmp/countrycode
-        echo "fetching mirrors for $(cat /tmp/mirrorselect)"
-        curl -s "https://www.archlinux.org/mirrorlist/?country=$(cat /tmp/countrycode)&protocol=http&protocol=https&ip_version=4" |
-            sed 's/^#Server /Server /g' >/tmp/mirrorlist
-        cat /etc/pacman.d/mirrorlist >/tmp/oldmirrorlist
-
-        cat /tmp/mirrorlist >/etc/pacman.d/mirrorlist
-        cat /tmp/oldmirrorlist >>/etc/pacman.d/mirrorlist
+    iroot askmirrors 1
+    MIRRORCODE="$({
+        echo 'auto detect mirrors (not recommended for speed)'
+        curl -s 'https://archlinux.org/mirrorlist/all/' | grep '##' | grep -iEv '(linux|arch|generated|filter)' |
+            grep -o '[^# ]*' | grep '.....'
+    } | imenu -l 'select mirror location')"
+
+    if grep -q 'auto detect' <<<"$MIRRORCODE"; then
+        iroot automirrors 1
     else
-        echo "ranking mirrors"
-        reflector --latest 40 --protocol http --protocol https --sort rate --save /etc/pacman.d/mirrorlist
-        iroot automirror 1
+        iroot countrycode "$MIRRORCODE"
+        if echo '> manually sorting mirrors may take a long time
+use arch ranking score (recommended)
+sort all mirrors by speed' | imenu -l 'choose mirror settings' | grep -q 'speed'; then
+            iroot sortmirrors 1
+        fi
     fi
 }
 
 # ask for user details
 askuser() {
-    while [ -z $NEWUSER ]; do
+    while [ -z "$NEWUSER" ]; do
         wallstatus user
         NEWUSER="$(imenu -i 'set username')"
 
         # validate input as a unix name
         if ! grep -Eq '^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$' <<<"$NEWUSER"; then
-            imenu -m "invalid username"
+            imenu -e "invalid username, usernames must not contain spaces or special symbols and start with a lowercase letter"
             unset NEWUSER
         fi
     done
@@ -156,6 +184,10 @@ askuser() {
     while ! [ "$NEWPASS" = "$NEWPASS2" ] || [ -z "$NEWPASS" ]; do
         NEWPASS="$(imenu -P 'set password')"
         NEWPASS2="$(imenu -P 'confirm password')"
+        if ! [ "$NEWPASS" = "$NEWPASS2" ]; then
+            echo "the confirmation password doesn't match.
+Please enter a new password" | imenu -M
+        fi
     done
 
     iroot user "$NEWUSER"
@@ -184,7 +216,7 @@ giving the wrong answer here might greatly decrease performance. " | imenu -C; t
 
     echo "virtualbox
 kvm/qemu
-other" | imenu -l "what hypervisor is being used?" >/tmp/vmtype
+other" | imenu -l "which hypervisor is being used?" >/tmp/vmtype
 
     HYPERVISOR="$(cat /tmp/vmtype)"
     case "$HYPERVISOR" in
@@ -209,6 +241,9 @@ until this is fixed" | imenu -M
         ;;
     virtualbox)
         iroot virtualbox 1
+        if imenu -c "would you like to install virtualbox guest additions?"; then
+            iroot guestadditions 1
+        fi
         ;;
     other)
         iroot othervm 1