-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·137 lines (101 loc) · 4.2 KB
/
install.sh
File metadata and controls
executable file
·137 lines (101 loc) · 4.2 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# Update and upgrade the system
sudo apt-get update
sudo apt-get -y upgrade
os=$(uname -a)
if [[ $os == *"kali-raspberry-pi"* ]]; then
# Install Python 3.8 and set it to path building it from source
echo "Kali Linux detected."
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -xf Python-3.8.0.tgz
cd Python-3.8.0
./configure --enable-optimizations
make -j 8
sudo make altinstall
# sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
# Creating a virtual encironment
cd ..
sudo pip3.8 install virtualenv
python3.8 -m virtualenv CMS
# Activate the virtual environment
source CMS/bin/activate
pip install --upgrade pip
# virtualenv -p /usr/bin/python3.8 CMS
# Set up the coral USB accelerator
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y libedgetpu1-std
python -m pip install --extra-index-url https://google-coral.github.io/py-repo/ pycoral~=2.0
elif [[ $os == *"raspberrypi"* ]]; then
echo "Raspberry Pi OS detected."
# Creating a virtual environment
sudo pip3 install virtualenv
python3 -m virtualenv CMS
# Activate the virtual environment
source CMS/bin/activate
# Set up the coral USB accelerator
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y libedgetpu1-std
python3 -m virtualenv CMS
sudo apt-get install -y python3-pycoral
else
echo "Unknown operating system."
fi
# Install dependencies
pip install -r requirements.txt
pip install rpi.gpio
# Run the script
cd controls/
# Get router IP address
router_ip=$(ip route | grep default | awk '{print $3}')
# Get router DNS server
router_dns=$(nmcli dev show | grep 'IP4.DNS' | awk '{print $2}')
# Set a static IP address
sudo sed -i '$a\interface eth0' /etc/dhcpcd.conf
sudo sed -i '$a\static ip_address='"${router_ip}"'157/24' /etc/dhcpcd.conf
sudo sed -i '$a\static routers='"${router_ip}" /etc/dhcpcd.conf
sudo sed -i '$a\static domain_name_servers='"${router_dns}" /etc/dhcpcd.conf
# Get the device's IP address
ip=$(hostname -I | awk '{print $1}')
# Enable port forwarding for port 5500
sudo iptables -t nat -A PREROUTING -p tcp --dport 5500 -j DNAT --to-destination "${ip}:80"
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
# Make port forwarding rules persistent across reboots
sudo sed -i '$a\iptables-restore < /etc/iptables.ipv4.nat' /etc/rc.local
# Replace the host parameter in the Python script with the IP address
sed -i "s/app.run(host=.*/app.run(host='${ip}', debug=False, port=5500)/" controls.py
# Restart the OpenVPN service
# TODO set up a crontab job on reboot to setup the ip address as host and set up openvpn and port forwarding as a separate bash script
# # Set a cronjob to start on boot with the ip address as host
# # Write out current crontab to a file
# sudo apt-get update
# sudo apt-get install -y cron
# # crontab -l > mycron
# # Changing to root
# sudo su
# cd ..
# source CMS/bin/activate
# cd controls/
# if [[ $os == *"kali-raspberry-pi"* ]]; then
# # Echo new cron into cron file
# (crontab -l 2>/dev/null; echo "@reboot /home/kali/CMS/CMS/bin/python /home/kali/CMS/controls/controls.py") | crontab -
# else
# echo "This script is only compatible with Kali Linux Raspberry Pi OS."
# fi
# # Check if user is root
# if [ "$EUID" -ne 0 ]
# then echo "Please run as root"
# fi
# # Add root privileges to run crontab
# sudo chmod u+s /usr/bin/crontab
# sudo chmod g+s /usr/bin/crontab
# sudo chown root:crontab /usr/bin/crontab
# sudo chown root:crontab /var/spool/cron/crontabs
# sudo chmod 1730 /var/spool/cron/crontabs
# echo "Root privileges added to run crontab successfully!"
python controls.py