-
Notifications
You must be signed in to change notification settings - Fork 3
/
ap_check.sh
executable file
·97 lines (77 loc) · 1.99 KB
/
ap_check.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /bin/bash
HOSTPAD_DIR=../hostapd/hostapd/
BLUE='\e[1;34m'
GREEN='\e[1;32m'
CYAN='\e[1;36m'
RED='\e[1;31m'
PURPLE='\e[1;35m'
YELLOW='\e[1;33m'
# No Color
NC='\e[0m'
check_package(){
for i in {1..5}
do
echo -en "${GREEN}Check package - $1...${NC}"
status=$(dpkg -s $1 | grep "Status: install ok installed")
if [ "$status" == "" ]; then
echo -e "${PURPLE}Try to intall package $1...${NC}"
apt-get install -y $1
retval=2
else
echo -e "${GREEN}OK${NC}"
retval=1
break;
fi
done
return "$retval"
}
check_dhcp_server_config(){
dhcp_config_file="/etc/dhcp/dhcpd.conf"
echo -en "${YELLOW}Check DHCPD config...${NC}"
dhcp_config=$(grep "subnet 192.168.0.0 netmask 255.255.255.0" $dhcp_config_file)
if [ "$dhcp_config" == "" ]; then
echo -en "${YELLOW}Config $dhcp_config_file.....${NC}"
echo "subnet 192.168.0.0 netmask 255.255.255.0" >> $dhcp_config_file
echo "{" >> $dhcp_config_file
echo " range 192.168.0.2 192.168.0.10;" >> $dhcp_config_file
echo " option routers 192.168.0.1;" >> $dhcp_config_file
echo " option domain-name-servers 168.95.1.1;" >> $dhcp_config_file
echo "}" >> $dhcp_config_file
echo -e "${YELLOW}OK${NC}"
else
echo -e "${YELLOW}OK${NC}"
fi
}
check()
{
check_package $1
ret=$?
if test $ret -eq 2
then
echo -e "${RED}#############FAIL to CHECK PACKAGE for AP MODE#############${NC}"
exit 0;
fi
}
#############################################==MAIN==#############################################
#
if [ ! -d "$HOSTPAD_DIR" ]; then
echo -e "${RED}#############HOSTPAD needs to be put at the same level of the wireless driver#############${NC}"
exit 0;
fi
#
echo -e "${YELLOW}Check internet access...${NC}"
wget --spider http://www.google.com
if [ "$?" != 0 ]; then
echo -e "${RED}Please connect to internet firstly......${NC}"
exit 0;
fi
#
echo -e "${YELLOW}Check necessary packages to run AP mode${NC}"
check libnl1
check libnl-dev
check libssl-dev
check isc-dhcp-server
check_dhcp_server_config
#
cd $HOSTPAD_DIR
make