summaryrefslogtreecommitdiffstats
path: root/networking/wifi/device-files/networks/add_network.sh
blob: 04c93dab002a81dd5ac9b62936d78114c17b6c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (C) 2016, 2017 Filippo Fil Bergamo
#
# This file is part of "RepWifi", a set of shell scripts to ease libre wifi connectivity.
#
# RepWifi is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RepWifi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# setup environment variables:
source "/data/misc/wifi/setup_variables.sh"
if [ $? -ne 0 ]; then
	exit 1
fi


# parse arguments <ssid> [<password>]
# If no <password>, then assume no authentication
if [ $# -eq 0 ]; then
    echo "Usage: bash add_network.sh <ssid> [<password>] "
    exit 1
elif [ $# -eq 1 ]; then
    # If no password, we assume that no authentication is necessary
    curnet=$1
    NO_PASSWORD=1
elif [ $# -eq 2 ]; then
    #If a a password is passed, we assume WPA-Personal
    curnet=$1
    pass=$2
    NO_PASSWORD=0
else
    echo "Usage: bash add_network.sh <ssid> [<password>]"
    exit 1
fi

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

if [$NO_PASSWORD -eq 1]; then
    echo -e "$curnet" >> $knets_file
else
    echo -e "$curnet""\t""$pass" >> $knets_file
fi