-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirewall-setup.sh
executable file
·65 lines (45 loc) · 1.79 KB
/
firewall-setup.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
#/bin/bash
# This sets up iptables to run initially on startup by placing it at the bottom of rc.local
# cd to dir script is run from
cd "$( dirname "${BASH_SOURCE[0]}" )"
if [ `id -u` -ne 0 ]; then
echo "Must be root to run this script"
exit 1
fi
#Config dir exists
if [ ! -d "configs" ]; then
echo "Main configs dir missing. Can't do anything without it. This contains all the templates to deploy to the system"
echo "If you have assumed you don't need this, you're wrong. Please put it back"
exit 1
fi
#Temp dir exists
if [ ! -d "temp" ]; then
mkdir temp
fi
chmod 700 temp
# temp firewall dir exists
if [ -d "temp/firewall" ]; then
echo "Cleaning up old config files"
rm -r "temp/firewall"
fi
#copy files
cp -r configs/firewall temp/firewall
mkdir /etc/firewall
cp temp/firewall/iptables.sh /etc/firewall/iptables.sh
chmod +x /etc/firewall/iptables.sh
chmod -R 700 /etc/firewall
cp /etc/rc.local temp/firewall/rc.local.orig
sed -i 's#^exit 0$#/etc/firewall/iptables.sh\nexit 0#' /etc/rc.local
echo 'reading out non-commented lines in /etc/rc.local lines of rc.local to verify iptables line is properly there'
echo 'VERIFY THAT iptables.sh has been successfully added'
cat /etc/rc.local | grep -v '^#'
echo "the original rc.local has been copied to temp/firewall/rc.local.orig. If you're not happy with this new updated file. do NOT rerun this script or it'll overwrite it orig file with the new copy of rc.local that's now there"
echo "Do you wish to run iptables.sh now and enable firewall? (if services are already running, you should add rules for those ports first"
echo "(y/n)"
read runfirewall
if [ "$runfirewall" = "y" ]; then
echo "running firewall"
/etc/firewall/iptables.sh
else
echo "not running firewall. Edit the file in /etc/firewall/iptables.sh and run it when you're done"
fi