-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
177 lines (149 loc) · 4.62 KB
/
Copy pathinstall.sh
File metadata and controls
177 lines (149 loc) · 4.62 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# InkFrame installation script
# This script installs and configures InkFrame on a Raspberry Pi Zero W
set -e
# ANSI colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}=========================================${NC}"
echo -e "${BLUE} InkFrame Installation Script${NC}"
echo -e "${BLUE} E-Ink Photo Frame for Raspberry Pi${NC}"
echo -e "${BLUE}=========================================${NC}"
echo
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root (use sudo)${NC}"
exit 1
fi
# Get the directory where the script is located
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cd "$SCRIPT_DIR"
echo -e "${GREEN}Updating system packages...${NC}"
apt-get update
apt-get upgrade -y
echo -e "${GREEN}Installing required packages...${NC}"
apt-get install -y \
python3 \
python3-pip \
python3-venv \
python3-dev \
libopenjp2-7 \
libtiff5 \
imagemagick \
git \
nginx
echo -e "${GREEN}Setting up Python virtual environment...${NC}"
python3 -m venv venv
source venv/bin/activate
echo -e "${GREEN}Installing Python dependencies...${NC}"
pip install --upgrade pip
pip install \
flask \
pillow \
requests \
RPi.GPIO \
spidev \
pytz \
gunicorn
echo -e "${GREEN}Installing Waveshare e-Paper library...${NC}"
if [ ! -d "waveshare_epd" ]; then
# Clone the Waveshare e-Paper library repository
git clone https://github.com/waveshare/e-Paper.git waveshare_repo
# Copy the required Python files
mkdir -p waveshare_epd
cp -r waveshare_repo/RaspberryPi_JetsonNano/python/lib/waveshare_epd/*.py waveshare_epd/
# Clean up
rm -rf waveshare_repo
fi
echo -e "${GREEN}Creating directories...${NC}"
mkdir -p static/images/photos/thumbnails
mkdir -p static/images/photos/uploads
mkdir -p config
mkdir -p logs
echo -e "${GREEN}Setting permissions...${NC}"
chown -R spencer:spencer .
chmod +x src/web/app.py
chmod +x src/display/photo_manager.py
echo -e "${GREEN}Creating service files...${NC}"
# Create web service file
cat > /etc/systemd/system/inkframe-web.service << EOF
[Unit]
Description=InkFrame Web Interface
After=network.target
[Service]
User=spencer
WorkingDirectory=${SCRIPT_DIR}
ExecStart=${SCRIPT_DIR}/venv/bin/gunicorn --workers 1 --bind 0.0.0.0:5000 src.web.app:app
Restart=always
RestartSec=5
Environment=PYTHONPATH=${SCRIPT_DIR}
[Install]
WantedBy=multi-user.target
EOF
# Create display service file
cat > /etc/systemd/system/inkframe-display.service << EOF
[Unit]
Description=InkFrame Photo Display
After=network.target
[Service]
User=spencer
WorkingDirectory=${SCRIPT_DIR}
ExecStart=${SCRIPT_DIR}/venv/bin/python3 ${SCRIPT_DIR}/src/display/photo_manager.py
Restart=always
RestartSec=5
Environment=PYTHONPATH=${SCRIPT_DIR}
[Install]
WantedBy=multi-user.target
EOF
echo -e "${GREEN}Enabling SPI interface...${NC}"
if ! grep -q "dtparam=spi=on" /boot/config.txt; then
echo "dtparam=spi=on" >> /boot/config.txt
echo "SPI interface enabled. A reboot will be required."
else
echo "SPI interface already enabled."
fi
echo -e "${GREEN}Enabling and starting services...${NC}"
systemctl daemon-reload
systemctl enable inkframe-web.service
systemctl enable inkframe-display.service
systemctl start inkframe-web.service
systemctl start inkframe-display.service
# Set up Nginx as a reverse proxy (optional)
echo -e "${GREEN}Configuring Nginx as reverse proxy...${NC}"
cat > /etc/nginx/sites-available/inkframe << EOF
server {
listen 80;
server_name _;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
client_max_body_size 16M;
}
EOF
# Enable the Nginx site
ln -sf /etc/nginx/sites-available/inkframe /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
systemctl restart nginx
# Get IP address for user reference
IP_ADDRESS=$(hostname -I | cut -d' ' -f1)
echo -e "${BLUE}=========================================${NC}"
echo -e "${GREEN}Installation complete!${NC}"
echo -e "${BLUE}=========================================${NC}"
echo
echo -e "You can access the InkFrame web interface at:"
echo -e "${GREEN}http://$IP_ADDRESS/${NC}"
echo
echo -e "Default configuration:"
echo -e "- Web interface port: 5000 (via Nginx on port 80)"
echo -e "- Photo directory: ${SCRIPT_DIR}/static/images/photos"
echo -e "- Config file: ${SCRIPT_DIR}/config/config.json"
echo
echo -e "A reboot is recommended to ensure all changes take effect."
echo -e "Run ${GREEN}sudo reboot${NC} to restart your Raspberry Pi."
echo