summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-01 00:12:37 +0100
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-01 00:26:04 +0100
commit920a3cdaf3cdfe0bca4573352d835a8da012229d (patch)
treebf3c10cfa7ca8229ec0dee67f79f288d172dfac2
parentccd1810d27598baaa5ce1a09ff8bbd26f5cabee6 (diff)
downloaduser-scripts-920a3cdaf3cdfe0bca4573352d835a8da012229d.zip
user-scripts-920a3cdaf3cdfe0bca4573352d835a8da012229d.tar.gz
user-scripts-920a3cdaf3cdfe0bca4573352d835a8da012229d.tar.bz2
Import version 1.3 of Filippo "Fil" Bergamo's wifi scripts
Full credit goes to him. I only changed the path of the scripts from "scripts" to "device-files".
-rw-r--r--networking/wifi/device-files/check_modules.sh124
-rw-r--r--networking/wifi/device-files/connect.sh88
-rw-r--r--networking/wifi/device-files/disconnect.sh12
-rw-r--r--networking/wifi/device-files/networks/add_network.sh32
-rw-r--r--networking/wifi/device-files/networks/get_network.sh72
-rw-r--r--networking/wifi/device-files/networks/known-networks10
-rw-r--r--networking/wifi/device-files/networks/remove_network.sh31
-rw-r--r--networking/wifi/device-files/rstr.sh51
-rw-r--r--networking/wifi/device-files/select_network.sh161
-rw-r--r--networking/wifi/device-files/setup_variables.sh36
-rw-r--r--networking/wifi/device-files/startwpa.sh9
-rw-r--r--networking/wifi/device-files/write_config.sh47
-rwxr-xr-xnetworking/wifi/setup.sh7
13 files changed, 680 insertions, 0 deletions
diff --git a/networking/wifi/device-files/check_modules.sh b/networking/wifi/device-files/check_modules.sh
new file mode 100644
index 0000000..814d8ed
--- /dev/null
+++ b/networking/wifi/device-files/check_modules.sh
@@ -0,0 +1,124 @@
+#
+# THIS IS FREE SOFTWARE
+#
+# Copyright 2016 Filippo "Fil" Bergamo
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+globresult=0
+
+# check, for every module, if it is running,
+# if not, insmod it.
+
+
+# ---- mac80211 ----
+mod=$(ls /sys/module | grep -c -Fx "mac80211")
+if [ "$mod" = "0" ]; then
+ echo -n -e "\tloading module mac80211.ko ..."
+ insmod $mod_mac80211
+ if [ $? = 0 ]; then
+ echo " [ OK! ]"
+ else
+ globresult=1
+ echo " [* FAIL! *]"
+ fi
+else
+ echo -e "\tmac80211.ko already loaded [ OK! ]"
+fi
+
+
+
+# ---- ath.ko ----
+mod=$(ls /sys/module | grep -c -Fx "ath")
+if [ "$mod" = "0" ]; then
+ echo -n -e "\tloading module ath.ko ..."
+ insmod "$mod_ath"
+ if [ $? = 0 ]; then
+ echo " [ OK! ]"
+ else
+ globresult=-1
+ echo " [* FAIL! *]"
+ fi
+else
+ echo -e "\tath.ko already loaded [ OK! ]"
+fi
+
+
+
+# ---- ath9k_hw ----
+mod=$(ls /sys/module | grep -c -Fx "ath9k_hw")
+if [ "$mod" = "0" ]; then
+ echo -n -e "\tloading module ath9k_hw.ko ..."
+ insmod "$mod_ath9k_hw"
+ if [ $? = 0 ]; then
+ echo " [ OK! ]"
+ else
+ globresult=1
+ echo " [* FAIL! *]"
+ fi
+else
+ echo -e "\tath9k_hw.ko already loaded [ OK! ]"
+fi
+
+
+
+# ---- ath9k_common ----
+mod=$(ls /sys/module | grep -c -Fx "ath9k_common")
+if [ "$mod" = "0" ]; then
+ echo -n -e "\tloading module ath9k_common.ko ..."
+ insmod "$mod_ath9k_common"
+ if [ $? = 0 ]; then
+ echo " [ OK! ]"
+ else
+ globresult=1
+ echo " [* FAIL! *]"
+ fi
+else
+ echo -e "\tath9k_common.ko already loaded [ OK! ]"
+fi
+
+
+
+# ---- ath0k_htc ----
+mod=$(ls /sys/module | grep -c -Fx "ath9k_htc")
+if [ "$mod" = "0" ]; then
+ echo -n -e "\tloading module ath9k_htc.ko ..."
+ insmod "$mod_ath9k_htc"
+ if [ $? = 0 ]; then
+ echo " [ OK! ]"
+ else
+ globresult=1
+ echo " [* FAIL! *]"
+ fi
+else
+ echo -e "\tath9k_htc.ko already loaded [ OK! ]"
+fi
+
+
+
+# check for global result:
+if [ "$globresult" -lt 0 ]; then
+ echo "ERRORS loading one or more modules.."
+ echo "Try re-running the script.."
+ exit $globresult
+else
+ echo "All modules loaded!"
+fi
+
+
diff --git a/networking/wifi/device-files/connect.sh b/networking/wifi/device-files/connect.sh
new file mode 100644
index 0000000..a5e2a4c
--- /dev/null
+++ b/networking/wifi/device-files/connect.sh
@@ -0,0 +1,88 @@
+#
+# THIS IS FREE SOFTWARE
+#
+# Copyright 2016 Filippo "Fil" Bergamo
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+# terminate both dhcpcd and wpa_supplicant, in case there are previous connections pending...
+bash "$scriptDiscon"
+
+# launch wpa_supplicant on interface wlan0
+# specifing our custom configuration and the socket file
+wpa_supplicant -B -dd -i"$ifacename" -c"$wpaconfile" -P"$pidfile"
+
+# negotiate a dhcp leasing
+dhcpcd "$ifacename"
+
+# set DNS's
+setprop net.dns1 "$ipDNS1"
+setprop net.dns2 "$ipDNS2"
+
+# re-give permissions on the pid file and on the socket folder,
+# in case wpa_supplicant changed them,
+# to be still able to interact with wpa_cli
+chmod 777 "$pidfile"
+chmod -R 777 "$socketfile"
+
+# read wpa status, to check if connection was successfull:
+state_variable="wpa_state"
+status_connected="COMPLETED"
+
+wpastatus=$(wpa_cli -p$socketfile -P$pidfile -i$ifacename status)
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+#sleep 2s
+
+tmpStatusFile="$workdir""/tmpStus"
+if [ -e "$tmpStatusFile" ]; then
+ rm "$tmpStatusFile"
+fi
+echo "$wpastatus" > "$tmpStatusFile"
+
+tmpLineFile="$workdir""/tmpln"
+
+# loop through wpa_cli's output, to find the wpa_state field:
+while IFS= read -r line
+do
+ if [ -e "$tmpLineFile" ]; then
+ rm "$tmpLineFile"
+ fi
+ echo "$line" > "$tmpLineFile"
+ # split the line into couples of <property>=<value>:
+ IFS='='
+ read -r -a FIELDS < "$tmpLineFile"
+ IFS=
+ if [ "${FIELDS[0]}" = "$state_variable" ]; then
+ # found the status property. Read its value:
+ currentStatus="${FIELDS[1]}"
+ if [ "$currentStatus" = "$status_connected" ]; then
+ # exit with success
+ exit 0
+ else
+ # exit fail
+ exit 1
+ fi
+ fi
+ idx=$(($idx+1))
+done < "$tmpStatusFile"
+
+
diff --git a/networking/wifi/device-files/disconnect.sh b/networking/wifi/device-files/disconnect.sh
new file mode 100644
index 0000000..3e43f89
--- /dev/null
+++ b/networking/wifi/device-files/disconnect.sh
@@ -0,0 +1,12 @@
+suppid=$(pidof wpa_supplicant)
+dhcppid=$(pidof dhcpcd)
+
+if ! [ -z "$suppid" ]; then
+ killall -SIGINT wpa_supplicant
+fi
+
+if ! [ -z "$dhcppid" ]; then
+ killall -SIGINT dhcpcd
+fi
+
+exit 0
diff --git a/networking/wifi/device-files/networks/add_network.sh b/networking/wifi/device-files/networks/add_network.sh
new file mode 100644
index 0000000..2e9bd1b
--- /dev/null
+++ b/networking/wifi/device-files/networks/add_network.sh
@@ -0,0 +1,32 @@
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+# parse arguments <ssid> <password>
+if [ $# -eq 0 ]; then
+ echo "Missing arguments <ssid> <password> "
+ exit 1
+fi
+
+if [ $# -ne 2 ]; then
+ echo "Wrong argument count!"
+ exit 1
+fi
+
+curnet=$1
+pass=$2
+foundnet=$(bash "$knets_get" "$curnet")
+if ! [ -z "$foundnet" ]; then
+ # the network is already a known one,
+ # remove it from the list, before adding the new password
+ source "$knets_rem" "$curnet"
+fi
+
+if ! [ -e "$knets_file" ]; then
+ echo -n "" > "$knets_file"
+fi
+
+echo -e "$curnet""\t""$pass" >> $knets_file
diff --git a/networking/wifi/device-files/networks/get_network.sh b/networking/wifi/device-files/networks/get_network.sh
new file mode 100644
index 0000000..cd580aa
--- /dev/null
+++ b/networking/wifi/device-files/networks/get_network.sh
@@ -0,0 +1,72 @@
+
+# this scripts outputs a tuple, formatted as <BSSID>[TAB]<PASSWORD>
+# IF the requested bssid is found in the known networks file.
+# it outputs nothing, if the bssid isn't found.
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+# validate input parameters
+if [ $# -eq 0 ]; then
+ echo "Missing arguments <bssid>"
+ exit 1
+fi
+
+if [ $# -ne 1 ]; then
+ echo "Wrong arguments count!"
+ exit 1
+fi
+
+# parse parameter <bssid>
+netName=$1
+
+# check if the known networks file exists
+if ! [ -e "$knets_file" ]; then
+ exit 0
+fi
+
+# read the file, omitting comments:
+networks=$(grep -v --invert-match '^#' $knets_file)
+
+if [ -z "$networks" ]; then
+ exit 0
+fi
+
+tempNetsFile="$workdir""/tmpnts"
+if [ -e "$tempNetsFile" ]; then
+ rm "$tempNetsFile"
+fi
+echo "$networks" > "$tempNetsFile"
+
+# count the number of saved networks:
+netnum=$(echo "$networks" | wc -l)
+
+# if there is no network in the list, return
+if [ "$netnum" == "" ] || [ "$netnum" -lt 1 ]; then
+ exit 0
+fi
+
+# iterate through networks, to see if the requested one is known:
+idx=1
+IFS=$'\t'
+while read -r line
+do
+ tempLineFile="$workdir""/tmpln"
+ if [ -e "$tempLineFile" ]; then
+ rm "$tempLineFile"
+ fi
+ echo "$line" > "$tempLineFile"
+ # split the line into the different properties:
+ #the SSID is the 1st field, password is the 2nd
+ read -r -a SUBAR < "$tempLineFile"
+ if [ "${SUBAR[0]}" = "$netName" ]; then
+ # found the desired network.
+ # outputs the tuple:
+ echo -e "${SUBAR[0]}""\t""${SUBAR[1]}"
+ fi
+done < "$tempNetsFile"
+IFS=
+
diff --git a/networking/wifi/device-files/networks/known-networks b/networking/wifi/device-files/networks/known-networks
new file mode 100644
index 0000000..ba20784
--- /dev/null
+++ b/networking/wifi/device-files/networks/known-networks
@@ -0,0 +1,10 @@
+# This is a simple file used to store the "known" wifi networks
+# lines starting with "#" are comments and are ignored by the parsing scripts.
+# networks credentials are stored using the format:
+# <SSID>[TAB]<password>
+# *DO NOT* SURROUND VALUES WITH QUOTES! store the bare naked stirngs as they are.
+# if you store a funky SSID name, or an over-complicated password
+# containing a [TAB], then the whole "known networks storage" will break.
+# Anyway it's highly unlikely to ever meet such a network.
+# Don't mess with the contents of this file, unless you feel like hacking
+# and you know what you're doing. Let the scripts do the magic. And enjoy!
diff --git a/networking/wifi/device-files/networks/remove_network.sh b/networking/wifi/device-files/networks/remove_network.sh
new file mode 100644
index 0000000..1914e43
--- /dev/null
+++ b/networking/wifi/device-files/networks/remove_network.sh
@@ -0,0 +1,31 @@
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+# parse arguments <bssid>
+if [ $# -eq 0 ]; then
+ echo "Missing arguments <bssid> "
+ exit 1
+fi
+
+if [ $# -ne 1 ]; then
+ echo "Wrong argument count!"
+ exit 1
+fi
+
+curnet=$1
+# check if the known networks file exists
+if ! [ -e "$knets_file" ]; then
+ exit 0
+fi
+
+# get all file contents that do not begin with the bssid of the network to remove.
+# read the file, omitting comments:
+keptLines=$(grep -v --invert-match "^$curnet" "$knets_file")
+
+# overwrite the file, keeping only the filtered lines
+echo "$keptLines" > "$knets_file"
+
+
diff --git a/networking/wifi/device-files/rstr.sh b/networking/wifi/device-files/rstr.sh
new file mode 100644
index 0000000..672e51c
--- /dev/null
+++ b/networking/wifi/device-files/rstr.sh
@@ -0,0 +1,51 @@
+#
+# THIS IS FREE SOFTWARE
+#
+# Copyright 2016 Filippo "Fil" Bergamo
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit
+fi
+
+echo "Beginning a best-effort attempt to setup/restore Libre WiFi connectivity:"
+
+idx=1
+
+echo -n $idx") chmod -R 777 $workdir... "
+chmod -R 777 $workdir
+if [ $? = 0 ]; then
+ echo " [ OK! ]"
+else
+ echo " [* FAIL! *]"
+fi
+
+if [ -e "$wpaconfile" ]; then
+
+ idx=$(($idx+1))
+ echo -n $idx") chmod 777 "$wpaconfile"... "
+ chmod 777 "$wpaconfile"
+ if [ $? = 0 ]; then
+ echo " [ OK! ]"
+ else
+ echo " [* FAIL! *]"
+ fi
+fi
+
+idx=$(($idx+1))
+echo $idx") Check and load needed modules:"
+source "$scriptChkMod"
+
diff --git a/networking/wifi/device-files/select_network.sh b/networking/wifi/device-files/select_network.sh
new file mode 100644
index 0000000..86beaa0
--- /dev/null
+++ b/networking/wifi/device-files/select_network.sh
@@ -0,0 +1,161 @@
+#
+# THIS IS FREE SOFTWARE
+#
+# Copyright 2016 Filippo "Fil" Bergamo
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+bash "$scriptDiscon"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+sleep 1s
+
+bash "$scriptStartWPA"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+sleep 1s
+
+
+# scan for networks
+echo -n "Scanning for networks... "
+wpa_cli -p"$socketfile" -P"$pidfile" -i"$ifacename" scan
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+sleep 2s
+
+
+# store the scan results on file
+if [ -e "$scanfile" ]; then
+ rm "$scanfile"
+fi
+#sleep 1s
+
+echo "Retrieving network list... "
+wpa_cli -p"$socketfile" -P"$pidfile" -i"$ifacename" scan_results > "$scanfile"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+#sleep 1s
+
+# read the results in a variable:
+networks=$(grep -v --invert-match '^bssid' $scanfile)
+
+tmpNetsFile="$workdir""/""tmpnts"
+if [ -e "$tmpNetsFile" ]; then
+ rm "$tmpNetsFile"
+fi
+echo "$tmpNetsFile"
+echo "$networks" > "$tmpNetsFile"
+
+# count the number of networks:
+netnum=$(echo "$networks" | wc -l)
+
+# check if there is at least one network in the list
+if [ "$netnum" == "" ] || [ "$netnum" -lt 1 ]; then
+ echo "No networks found!"
+ exit 1
+fi
+
+
+echo ""
+echo "Please input the number of the network you want to connect to:"
+echo -e "\t # | SSID"
+echo -e "\t---|------------------"
+
+tmpLineFile="$workdir""/""tmpln"
+idx=1
+declare -a AR
+while IFS= read -r line
+do
+ # split the line into the different properties:
+ if [ -e "$tmpLineFile" ]; then
+ rm "$tmpLineFile"
+ fi
+ echo "$line" > "$tmpLineFile"
+ # Set IFS to tab only. Needed to correctly parse SSIDs containig spaces.
+ IFS=' '
+ read -r -a SUBAR < "$tmpLineFile"
+ AR[$idx]="${SUBAR[4]}" #the SSID is the 4th field
+ echo -e "\t"$idx") | ""${SUBAR[4]}"
+
+ idx=$(($idx+1))
+done < "$tmpNetsFile"
+# reset default IFS
+IFS=
+
+# read user's choice
+read selnet
+
+if ! [[ "$selnet" =~ ^[0-9]+$ ]]; then
+ echo "Invalid input!"
+ exit
+fi
+
+if [ "$selnet" -le 0 ] || [ "$selnet" -gt "$netnum" ]; then
+ echo "Invalid number!"
+ exit
+fi
+
+selectedSSID="${AR[$selnet]}"
+
+# check if the selected network is a known one:
+knownnet=$(bash "$knets_get" "$selectedSSID")
+if [ -z "$knownnet" ]; then
+ # network not found among the known ones
+ # ask for a password:
+ echo "Enter a password for "$selectedSSID
+ read password
+else
+ # extract the password from the tuple:
+ tmpTupleFile="$workdir""/tmptpl"
+ if [ -e "$tmpTupleFile" ]; then
+ rm "$tmpTupleFile"
+ fi
+ echo "$knownnet" > "$tmpTupleFile"
+ IFS=$'\t'
+ read -r -a TUPLE < "$tmpTupleFile"
+ password="${TUPLE[1]}"
+ IFS=
+fi
+
+bash "$scriptWriteConf" "$selectedSSID" "$password"
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+#sleep 1s
+
+echo "Do you want to connect to ""$selectedSSID"" now? [y/n] "
+read answer
+
+if [ $answer = "y" ] || [ $answer = "Y" ]; then
+ bash "$scriptConnect"
+ if [ $? -eq 0 ]; then
+ # successfully connected
+ # save password for future connections
+ source "$knets_add" "$selectedSSID" "$password"
+ echo "CONNECTED"
+ else
+ echo "FAILED TO CONNECT"
+ fi
+fi
diff --git a/networking/wifi/device-files/setup_variables.sh b/networking/wifi/device-files/setup_variables.sh
new file mode 100644
index 0000000..3d6c9fc
--- /dev/null
+++ b/networking/wifi/device-files/setup_variables.sh
@@ -0,0 +1,36 @@
+
+# working directory path
+export workdir="/data/misc/wifi"
+
+# network parameters
+export ifacename="wlan0"
+export ipDNS1="193.183.98.154"
+export ipDNS2="87.98.175.85"
+
+# aux files
+export scanfile="$workdir""/scanres.txt"
+export socketfile="$workdir""/sockets"
+export pidfile="$workdir""/pidfile"
+export wpaconfile="$workdir""/wpa_supplicant.conf"
+
+# script paths
+export scriptChkMod="$workdir""/check_modules.sh"
+export scriptWriteConf="$workdir""/write_config.sh"
+export scriptStartWPA="$workdir""/startwpa.sh"
+export scriptConnect="$workdir""/connect.sh"
+export scriptDiscon="$workdir""/disconnect.sh"
+
+# kernel modules
+export modulesPath="/system/lib/modules"
+export mod_mac80211="$modulesPath""/mac80211.ko"
+export mod_ath="$modulesPath""/ath.ko"
+export mod_ath9k_hw="$modulesPath""/ath9k_hw.ko"
+export mod_ath9k_common="$modulesPath""/ath9k_common.ko"
+export mod_ath9k_htc="$modulesPath""/ath9k_htc.ko"
+
+# known networks database
+export knets_dir="networks"
+export knets_file="$workdir""/""$knets_dir""/known-networks"
+export knets_add="$workdir""/""$knets_dir""/add_network.sh"
+export knets_rem="$workdir""/""$knets_dir""/remove_network.sh"
+export knets_get="$workdir""/""$knets_dir""/get_network.sh"
diff --git a/networking/wifi/device-files/startwpa.sh b/networking/wifi/device-files/startwpa.sh
new file mode 100644
index 0000000..bed2b75
--- /dev/null
+++ b/networking/wifi/device-files/startwpa.sh
@@ -0,0 +1,9 @@
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit
+fi
+
+# run wpa_supplicant without configuration file,
+# but providing a PID file and a socket, to let wpa_cli communicate with it
+wpa_supplicant -B -dd -i"$ifacename" -C"$socketfile" -P"$pidfile"
diff --git a/networking/wifi/device-files/write_config.sh b/networking/wifi/device-files/write_config.sh
new file mode 100644
index 0000000..8c07eb1
--- /dev/null
+++ b/networking/wifi/device-files/write_config.sh
@@ -0,0 +1,47 @@
+#
+# THIS IS FREE SOFTWARE
+#
+# Copyright 2016 Filippo "Fil" Bergamo
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+
+# setup environment variables:
+source "/data/misc/wifi/setup_variables.sh"
+if [ $? -ne 0 ]; then
+ exit
+fi
+
+#read SSID and password from command line:
+ssid=$1
+pass=$2
+
+#check if config file exists
+if [ -e $wpaconfile ]; then
+ rm $wpaconfile
+fi
+
+#write fixed lines:
+echo -e "ctrl_interface=DIR=""$socketfile""
+update_config=1
+network={
+\tssid=\"$ssid\"
+\tpsk=\"$pass\"
+}" > $wpaconfile
+
+chmod 777 "$wpaconfile"
+
+echo "Network connection has been set up for "$ssid"!"
+
+
diff --git a/networking/wifi/setup.sh b/networking/wifi/setup.sh
new file mode 100755
index 0000000..d31acf5
--- /dev/null
+++ b/networking/wifi/setup.sh
@@ -0,0 +1,7 @@
+root_dir="/data/misc/wifi"
+adb root
+sleep 3
+adb shell rm -r "$root_dir"
+adb shell mkdir "$root_dir"
+adb push ./device-files "$root_dir"
+adb push ./device-files/networks "$root_dir""/networks"