-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
123 lines (97 loc) · 3.26 KB
/
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
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
#!/bin/bash
# Ensure the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root. Please run with sudo."
exit 1
fi
# Set hostname
echo "Setting hostname to 'feeder'..."
echo "feeder" > /etc/hostname
# Update /etc/hosts
echo "Updating /etc/hosts..."
sed -i '/127.0.1.1/d' /etc/hosts
echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 feeder" >> /etc/hosts
# Apply hostname changes
echo "Applying hostname changes..."
hostnamectl set-hostname feeder
systemctl restart systemd-hostnamed
# Install avahi-daemon
echo "Installing avahi-daemon..."
apt-get update
apt-get install -y avahi-daemon avahi-utils
# Configure avahi-daemon
echo "Configuring avahi-daemon..."
AVAHI_CONF="/etc/avahi/avahi-daemon.conf"
sed -i '/^host-name=/d' "$AVAHI_CONF"
sed -i '/\[server\]/a host-name=feeder' "$AVAHI_CONF"
sed -i '/\[server\]/a ratelimit-burst=1000' "$AVAHI_CONF"
sed -i '/\[server\]/a ratelimit-interval-usec=1000000' "$AVAHI_CONF"
# Add log-level setting if not present
if ! grep -q "^log-level=" "$AVAHI_CONF"; then
sed -i '/\[server\]/a log-level=debug' "$AVAHI_CONF"
fi
# Create Avahi service file for Flask app
echo "Creating Avahi service file for Flask app..."
cat <<EOT > /etc/avahi/services/flaskapp.service
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_http._tcp</type>
<port>80</port>
</service>
</service-group>
EOT
# Restart avahi-daemon
echo "Restarting avahi-daemon..."
systemctl restart avahi-daemon
# Check avahi-daemon status
systemctl status avahi-daemon --no-pager
# Install required packages
echo "Installing required packages..."
apt-get install -y python3-flask python3-git python3-requests
pip install apscheduler
sudo apt update
sudo apt upgrade -y
# Install pigpio and gpiozero
sudo apt install -y pigpio python3-gpiozero
sudo apt install -y python3-pip
pip3 install gpiozero
# Enable and start pigpiod service
sudo systemctl enable pigpiod
sudo systemctl start pigpiod
# Create systemd service for Flask app
echo "Creating systemd service for Flask app..."
cat <<EOT > /etc/systemd/system/flaskapp.service
[Unit]
Description=Flask Application
After=network.target
[Service]
User=root
WorkingDirectory=/home/pizero/RPI_Dog_Feeder
ExecStart=/usr/bin/python3 /home/pizero/RPI_Dog_Feeder/app.py
Restart=always
[Install]
WantedBy=multi-user.target
EOT
# Reload systemd manager configuration
echo "Reloading systemd manager configuration..."
systemctl daemon-reload
# Enable the Flask app service to start on boot
echo "Enabling Flask app service to start on boot..."
systemctl enable flaskapp.service
# Start the Flask app service immediately
echo "Starting Flask app service..."
systemctl start flaskapp.service
# Check the status of the Flask app service
systemctl status flaskapp.service --no-pager
# Change hotspot SSID and password
HOTSPOT_SSID="YourNewSSID"
HOTSPOT_PASSWORD="YourNewPassword"
HOSTAPD_CONF="/etc/hostapd/hostapd.conf"
echo "Changing hotspot SSID and password..."
sed -i "s/^ssid=.*/ssid=${HOTSPOT_SSID}/" "$HOSTAPD_CONF"
sed -i "s/^wpa_passphrase=.*/wpa_passphrase=${HOTSPOT_PASSWORD}/" "$HOSTAPD_CONF"
echo "Restarting hostapd service..."
systemctl restart hostapd
echo "Setup complete. You can now access your Flask app using http://feeder.local (after running the app)."