about summary refs log tree commit diff
path: root/installer.sh.in
diff options
context:
space:
mode:
authorJuan RP <xtraeme@gmail.com>2014-02-03 23:11:54 +0100
committerJuan RP <xtraeme@gmail.com>2014-02-03 23:11:54 +0100
commit08db3c6cb330ef4b5f51e6080fe2e95a5b38f63f (patch)
tree2f03d6542c98e7b3c85ed7bad3c9d55dc6035fb8 /installer.sh.in
parentc3c67ad641cc33f7a182bbe21d25cfe30bfbd5d9 (diff)
downloadhrmpf-08db3c6cb330ef4b5f51e6080fe2e95a5b38f63f.tar.gz
hrmpf-08db3c6cb330ef4b5f51e6080fe2e95a5b38f63f.tar.xz
hrmpf-08db3c6cb330ef4b5f51e6080fe2e95a5b38f63f.zip
installer: added basic wifi setup via dhcpcd (only WEP and WPA/PSK for now).
Diffstat (limited to 'installer.sh.in')
-rw-r--r--installer.sh.in59
1 files changed, 46 insertions, 13 deletions
diff --git a/installer.sh.in b/installer.sh.in
index f4ef93c..9bc3d77 100644
--- a/installer.sh.in
+++ b/installer.sh.in
@@ -1,6 +1,6 @@
 #!/bin/sh
 #-
-# Copyright (c) 2012-2013 Juan Romero Pardines <xtraeme@gmail.com>.
+# Copyright (c) 2012-2014 Juan Romero Pardines <xtraeme@gmail.com>.
 #               2012 Dave Elusive <davehome@redthumb.info.tm>.
 # All rights reserved.
 #
@@ -158,6 +158,7 @@ show_partitions() {
         # LVM
         for p in $(ls /dev/mapper 2>/dev/null|grep -v control); do
             [ "$p" = "live-rw" ] && continue
+            [ "$p" = "live-base" ] && continue
             fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
             fssize=$(lsblk -nr /dev/mapper/$p|awk '{print $4}')
             echo "/dev/mapper/$p"
@@ -439,15 +440,43 @@ test_network() {
 }
 
 configure_wifi() {
-    local dev="$1"
+    local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
+
+    DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
+        "SSID:" 1 1 "" 1 16 30 0 \
+        "Encryption:" 2 1 "" 2 16 3 0 \
+        "Password:" 3 1 "" 3 16 30 0 || return 1
+    set -- $(cat $ANSWER)
+    ssid="$1"; enc="$2"; pass="$3";
+
+    if [ -z "$ssid" ]; then
+        DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
+        return 1
+    elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
+        DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSXBOXSIZE}
+        return 1
+    elif [ -z "$pass" ]; then
+        DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
+    fi
 
-    DIALOG --form "Wireless configuration for $dev:" 0 0 0 \
-        "SSID:" 1 1 "add your AP name here" 1 21 20 0 \
-        "Encryption:" 2 1 "Only supported: WEP or WPA-PSK" 2 21 20 0 \
-        "Passphrase:" 3 1 "Enter the AP passphrase here" 3 21 20 0 || return 1
+    rm -f ${_wpasupconf%.conf}-${dev}.conf
+    cp -f ${_wpasupconf} ${_wpasupconf%.conf}-${dev}.conf
+    if [ "$enc" = "wep" ]; then
+        echo "network={" >> ${_wpasupconf%.conf}-${dev}.conf
+        echo "  ssid=\"$ssid\"" >> ${_wpasupconf%.conf}-${dev}.conf
+        echo "  wep_key0=\"$pass\"" >> ${_wpasupconf%.conf}-${dev}.conf
+        echo "  wep_tx_keyidx=0" >> ${_wpasupconf%.conf}-${dev}.conf
+        echo "  auth_alg=SHARED" >> ${_wpasupconf%.conf}-${dev}.conf
+        echo "}" >> ${_wpasupconf%.conf}-${dev}.conf
+    else
+        wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf%.conf}-${dev}.conf
+    fi
+
+    configure_net_dhcp $dev
+    return $?
 }
 
-configure_eth() {
+configure_net() {
     local dev="$1" rval
 
     DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
@@ -469,10 +498,10 @@ configure_net_dhcp() {
 
     iface_setup $dev
     if [ $? -eq 1 ]; then
-        dhcpcd -t 10 -w -4 -L $dev 2>&1 | tee $LOG | \
+        dhcpcd -t 10 -w -4 -L $dev -e "wpa_supplicant_conf=/etc/wpa_supplicant/wpa_supplicant-${dev}.conf" 2>&1 | tee $LOG | \
             DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
         if [ $? -ne 0 ]; then
-            DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run udhcpc. See $LOG for details." ${MSGBOXSIZE}
+            DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
             return 1
         fi
         iface_setup $dev
@@ -535,10 +564,10 @@ menu_network() {
         --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
     if [ $? -eq 0 ]; then
         dev=$(cat $ANSWER)
-        if $(echo $dev|grep -q "wlan[0-9]" 2>/dev/null); then
+        if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
             configure_wifi $dev
         else
-            configure_eth $dev
+            configure_net $dev
         fi
     fi
 }
@@ -818,8 +847,12 @@ ${BOLD}Do you want to continue?${RESET}" 20 80 || return
             # network type empty??!!!
             :
         elif [ "$_type" = "dhcp" ]; then
-            # if user had dhcp enabled, enable dhcpcd service for that device.
-            chroot $TARGETDIR systemctl enable dhcpcd.service >$LOG 2>&1
+            if [ -f /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf ]; then
+                cp /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf $TARGETDIR/etc/wpa_supplicant
+                chroot $TARGETDIR systemctl enable dhcpcd@${_dev}.service >$LOG 2>&1
+            else
+                chroot $TARGETDIR systemctl enable dhcpcd.service >$LOG 2>&1
+            fi
         elif [ -n "$dev" -a -n "$type" = "static" ]; then
             # static IP through dhcpcd.
             mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig