#!/bin/bash

loginpassword=rootpassword



ifinterface="$1"
WIFI_SSID="$2"
WIFI_PASSWORD="$3"

if [ "X${WIFI_SSID}" == "X" ];then
    echo "${loginpassword}" | sudo -S  nvram -d NWID
    echo "${loginpassword}" | sudo -S  nvram -d WPAKEY
else
    echo "${loginpassword}" | sudo -S  nvram NWID=${WIFI_SSID}
    if [ "X${WIFI_PASSWORD}" == "X" ];then
        echo "${loginpassword}" | sudo -S  nvram -d WPAKEY
        echo "${loginpassword}" | sudo -S  nvram WPA/WPA2=false
    else
         echo "${loginpassword}" | sudo -S  nvram WPAKEY=${WIFI_PASSWORD}
         echo "${loginpassword}" | sudo -S  nvram WPA/WPA2=true
    fi
fi
echo "${loginpassword}" | sudo -S  ifconfig ${ifinterface} down
echo "${loginpassword}" | sudo -S  ifconfig ${ifinterface} up
echo ""
echo ""
echo 切换完成
