-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHAREsetupScript.sh
executable file
·87 lines (61 loc) · 2.6 KB
/
HAREsetupScript.sh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
###################################################################################
# Script to setup an interface on BATMAN-adv #
# To run the script type: #
# ./setupScript.sh ip_address mtu frequency #
# Examples: #
# All 3 arguments specified: #
# ./setupScript.sh 192.168.100.4 1560 2417 #
# No mtu specified: #
# ./setupScript.sh 192.168.100.4 " " 2417 #
# No arguments:(the default values of 192.168.100.1, 1500, 2412 will be assigned)#
# ./setupScript.sh #
###################################################################################
# Script arguments
# ip address
ARG1=${1:-192.168.100.71}
# mtu
ARG2=${2:-1560}
# frequency
ARG3=${3:-2412}
#Stopping network manager is necessary if trying to setup
#on a machine's native wireless card. No necessary for wifi adapters
#sudo systemctl stop NetworkManager
#sudo service networking stop #for Raspberry Pis
#
#get wifi adapter's logical name (for VM and machine with no wireless card)
tmpVar=$(iw dev | awk '$1=="Interface"{print $2}')
#get the top device name returned. Assumes the top listing is what is needed
arr=($(echo $tmpVar | tr " " "\n"))
devID=wlx001986513db2
#bring down ip link in order to set up ip address, mtu and mode
sudo ip link set $devID down
echo "Device ID: $devID"
#set ip address (Diane edit added /24)
sudo ip addr add $ARG1/24 dev $devID
#set mtu
sudo ip link set $devID mtu $ARG2
#set mode to ad-hoc
sudo iw dev $devID set type ibss
#bring the device online
sudo ip link set $devID up
#join network with specified frequency, cell address and HT20
sudo iw dev $devID ibss join HARE $ARG3 HT20 fixed-freq 02:0f:00:73:09:07
#check to see if the interface exsists and delete it if it does
tmpVar2=$(ip link show | grep bat0)
if [ "{$tmpVar2}" != "" ];
then
sudo ip link delete bat0
fi
#bring up BATMAN-adv
sudo ip link add name bat0 type batadv
#add the interface
# 3/13/19 edit do not set as master
#sudo ip link set dev $devID master bat0
# 3/13/19 use batctl to add interface
sudo batctl if add $devID
sudo ip link set up dev bat0
# diane edit, 3/13/19 added /24
sudo ip addr add $ARG1/24 dev bat0
# edit, 3/13/19 do not flush
#sudo ip addr flush dev $devID