-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
68 lines (54 loc) · 1.81 KB
/
install.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
#!/bin/bash
# Update package manager
apt-get update
apt-get upgrade
# Install packages
sudo apt-get install python3-pip python-smbus python3-dev i2c-tools
# Install Python packages using pip
pip3 install requests
pip3 install OPi.GPIO
pip3 install ping3
pip3 install i2clcd
# Check if overlays already exist in armbianEnv.txt
if grep -q "overlays=" /boot/armbianEnv.txt; then
# Replace the value of the overlays parameter
sudo sed -i "s/^overlays=.*/overlays=i2c0 i2c1/" /boot/armbianEnv.txt
else
# Add overlays parameter to armbianEnv.txt
echo "overlays=i2c0 i2c1" | sudo tee -a /boot/armbianEnv.txt
fi
# Check if i2c-dev module is already in /etc/modules
if ! grep -q "^i2c-dev$" /etc/modules; then
# Add i2c-dev module to /etc/modules
echo "i2c-dev" | sudo tee -a /etc/modules
fi
chmod +x coin_slot.py
# Set the file name and path
file_path="/lib/systemd/system/coin_slot.service"
# Set the Python script path
script_path="/root/PisoWifi/coin_slot.py"
# Set the Python script parent path
script_parent_path="/root/PisoWifi"
# Check if the file already exists
if [ -f "$file_path" ]; then
echo "Service file already exists"
else
# Write the file contents
echo "[Unit]" > $file_path
echo "Description=My Coin Slot Service" >> $file_path
echo "After=multi-user.target" >> $file_path
echo "" >> $file_path
echo "[Service]" >> $file_path
echo "Type=simple" >> $file_path
echo "WorkingDirectory=$script_parent_path" >> $file_path
echo "Environment=PYTHONOATH=$script_parent_path" >> $file_path
echo "Restart=always" >> $file_path
echo "ExecStart=/usr/bin/python3 $script_path" >> $file_path
echo "" >> $file_path
echo "[Install]" >> $file_path
echo "WantedBy=multi-user.target" >> $file_path
fi
sudo chmod 644 $file_path
sudo systemctl daemon-reload
sudo systemctl enable coin_slot.service
sudo reboot