Skip to content

Commit baec65f

Browse files
committed
Install rewrite v2
1 parent 9f5884c commit baec65f

File tree

11 files changed

+72
-54
lines changed

11 files changed

+72
-54
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vscode
22
.DS_Store
3+
config/*
34
config/pialert.conf
45
db/*
56
db/pialert.db

Dockerfile

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,24 @@ RUN groupadd --gid "${USER_GID}" "${USER}" && \
2525

2626
COPY --chmod=775 --chown=${USER_ID}:${USER_GID} . /home/pi/pialert/
2727

28-
# ENTRYPOINT ["tini", "--"]
28+
29+
# ❗ IMPORTANT - if you modify this file modify the /install/install_dependecies.sh file as well ❗
30+
31+
RUN apt-get install -y \
32+
tini snmp ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo \
33+
nginx-light php php-cgi php-fpm php-sqlite3 php-curl sqlite3 dnsutils net-tools \
34+
python3 iproute2 nmap python3-pip zip systemctl usbutils traceroute
35+
36+
# Alternate dependencies
37+
RUN apt-get install nginx nginx-core mtr php-fpm php8.2-fpm php-cli php8.2 php8.2-sqlite3 -y
38+
RUN phpenmod -v 8.2 sqlite3
39+
40+
# Setup virtual python environment and use pip3 to install packages
41+
RUN apt-get install -y python3-venv
42+
RUN python3 -m venv myenv
43+
RUN /bin/bash -c "source myenv/bin/activate && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && pip3 install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet"
44+
2945

3046
CMD ["/home/pi/pialert/dockerfiles/start.sh"]
3147

32-
## command to build docker: DOCKER_BUILDKIT=1 docker build . --iidfile dockerID
48+
File renamed without changes.
File renamed without changes.

docker-compose.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ services:
1111
network_mode: host
1212
# restart: unless-stopped
1313
volumes:
14-
# - ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config
15-
- ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
16-
# - ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db
17-
- ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
14+
- ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config
15+
# - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
16+
- ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db
17+
# - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
1818
# (optional) useful for debugging if you have issues setting up the container
1919
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
2020
# ---------------------------------------------------------------------------
@@ -33,11 +33,10 @@ services:
3333
- ${DEV_LOCATION}/front/js:/home/pi/pialert/front/js
3434
- ${DEV_LOCATION}/dockerfiles/start.sh:/home/pi/pialert/dockerfiles/start.sh
3535
- ${DEV_LOCATION}/dockerfiles/user-mapping.sh:/home/pi/pialert/dockerfiles/user-mapping.sh
36-
- ${DEV_LOCATION}/install/install.sh:/home/pi/pialert/install/install.sh
37-
- ${DEV_LOCATION}/install/install_python.sh:/home/pi/pialert/install/install_python.sh
36+
- ${DEV_LOCATION}/install/install.sh:/home/pi/pialert/install/install.sh
3837
- ${DEV_LOCATION}/install/install_dependencies.sh:/home/pi/pialert/install/install_dependencies.sh
3938
- ${DEV_LOCATION}/front/api:/home/pi/pialert/front/api
40-
- ${DEV_LOCATION}/front/php:/home/pi/pialert/front/php
39+
- ${DEV_LOCATION}/front/php:/home/pi/pialert/front/php
4140
- ${DEV_LOCATION}/front/deviceDetails.php:/home/pi/pialert/front/deviceDetails.php
4241
- ${DEV_LOCATION}/front/deviceDetailsTools.php:/home/pi/pialert/front/deviceDetailsTools.php
4342
- ${DEV_LOCATION}/front/devices.php:/home/pi/pialert/front/devices.php

dockerfiles/start.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ fi
2727
echo "[INSTALL] Run setup scripts"
2828

2929
"$INSTALL_DIR/pialert/dockerfiles/user-mapping.sh"
30-
"$INSTALL_DIR/pialert/install/install_dependencies.sh"
31-
"$INSTALL_DIR/pialert/install/install_python.sh"
30+
"$INSTALL_DIR/pialert/install/install_dependencies.sh" # if modifying this file transfer the chanegs into the root Dockerfile as well!
3231

3332
# Change port number if set
3433
if [ -n "${PORT}" ]; then
@@ -73,26 +72,27 @@ fi
7372
# Fixing file permissions
7473
echo "[INSTALL] Fixing file permissions"
7574

76-
chmod -R a+rwx $INSTALL_DIR
75+
7776
chmod -R a+rwx /var/www/html
7877
chmod -R a+rw $INSTALL_DIR/pialert/front/log
79-
chmod -R a+rw $INSTALL_DIR/pialert/config
80-
sudo chgrp -R www-data $INSTALL_DIR/pialert
78+
chmod -R a+rwx $INSTALL_DIR
8179

8280
FILEDB=$INSTALL_DIR/pialert/db/pialert.db
8381

8482
if [ -f "$FILEDB" ]; then
8583
chown -R www-data:www-data $INSTALL_DIR/pialert/db/pialert.db
8684
fi
8785

86+
echo "[INSTALL] Copy starter pialert.db and pialert.conf if they don't exist"
8887

89-
echo "[INSTALL] Create pialert.db and pialert.conf backups"
88+
# Copy starter pialert.db and pialert.conf if they don't exist
89+
cp -n "$INSTALL_DIR/pialert/back/pialert.conf" "$INSTALL_DIR/pialert/config/pialert.conf"
90+
cp -n "$INSTALL_DIR/pialert/back/pialert.db" "$INSTALL_DIR/pialert/db/pialert.db"
9091

91-
# Create a backup of pialert.conf
92-
cp "$INSTALL_DIR/pialert/config/pialert.conf" "$INSTALL_DIR/pialert/back/pialert.conf_bak"
9392

94-
# Create a backup of pialert.db
95-
cp "$INSTALL_DIR/pialert/db/pialert.db" "$INSTALL_DIR/pialert/back/pialert.db_bak"
93+
chmod -R a+rwx $INSTALL_DIR # second time after we copied the files
94+
chmod -R a+rw $INSTALL_DIR/pialert/config
95+
sudo chgrp -R www-data $INSTALL_DIR/pialert
9696

9797
# Create buildtimestamp.txt
9898
date +%s > "$INSTALL_DIR/pialert/front/buildtimestamp.txt"

front/php/templates/language/en_us.json

+2
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@
607607
"Systeminfo_USB_Devices" : "USB Devices",
608608
"report_select_format": "Select Format:",
609609
"report_time": "Notification time:",
610+
"report_guid": "Notification guid:",
611+
"report_guid_missing": "Linked notification not found. The selected notification might have been deleted during maintenance as specified in the <code>DBCLNP_NOTIFI_HIST</code> setting. The latest notification is dispalyed instead. The missing notification has the following GUID:",
610612
"Donations_Title" : "Donations",
611613
"Donations_Text" : "Hey 👋! </br> Thanks for clicking on this menu item 😅 </br> </br> I'm trying to collect some donations to make you better software. Also, it would help me not to get burned out. Me burning out might mean end of support for this app. Any small (recurring or not) sponsorship makes me want ot put more effort into this app. I don't want to lock features (new plugins) behind paywalls 🔐. </br> Currently, I'm waking up 2h before work so I contribute to the app a bit. If I had some recurring income I could shorten my workweek and in the remaining time fully focus on PiAlert. You'd get more functionality, a more polished app and less bugs. </br> </br> Thanks for reading - I'm super grateful for any support ❤🙏 </br> </br> TL;DR: By supporting me you get: </br> </br> <ul><li>Regular updates to keep your data and family safe 🔄</li><li>Less bugs 🐛🔫</li><li>Better and more functionality➕</li><li>I don't get burned out 🔥🤯</li><li>Less rushed releases 💨</li><li>Better docs📚</li><li>Quicker and better support with issues 🆘</li><li>Less grumpy me 😄</li></ul> </br> 📧Email me to <a href='mailto:[email protected]?subject=PiAlert'>[email protected]</a> if you want to get in touch or if I should add other sponsorship platforms. </br>",
612614
"Donations_Platforms" : "Sponsor platforms",

front/report.php

+21-6
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@
5858
</div>
5959

6060

61-
<div class="col-sm-8">
61+
<div class="col-sm-4">
6262
<label><?= lang('report_time') ;?></label>
63-
<span id="timestamp">Timestamp</span>
63+
<span id="timestamp"></span>
64+
</div>
65+
66+
<div class="col-sm-4">
67+
<label><?= lang('report_guid') ;?></label>
68+
<span id="guid"></span>
6469
</div>
6570

6671

@@ -77,6 +82,7 @@
7782
document.addEventListener('DOMContentLoaded', function() {
7883
const notificationData = document.getElementById('notificationData');
7984
const timestamp = document.getElementById('timestamp');
85+
const notiGuid = document.getElementById('guid');
8086
const prevButton = document.getElementById('prevButton');
8187
const nextButton = document.getElementById('nextButton');
8288
const formatSelect = document.getElementById('formatSelect');
@@ -113,7 +119,10 @@ function updateData(format, index) {
113119
break;
114120
}
115121

122+
// console.log(notification)
123+
116124
timestamp.textContent = notification.DateTimeCreated;
125+
notiGuid.textContent = notification.GUID;
117126
currentIndex = index;
118127

119128
$("#notificationOutOff").html(`${currentIndex + 1}/${data.data.length}`);
@@ -125,7 +134,7 @@ function updateData(format, index) {
125134

126135
// Function to find the index of a notification by GUID
127136
function findIndexByGUID(data, guid) {
128-
return data.findIndex(notification => notification.GUID === guid);
137+
return data.findIndex(notification => notification.GUID == guid);
129138
}
130139

131140
// Listen for format selection changes
@@ -151,10 +160,16 @@ function findIndexByGUID(data, guid) {
151160
.then(response => response.json())
152161
.then(data => {
153162
const index = findIndexByGUID(data.data, guid);
154-
if (index !== -1) {
155-
// Load the notification with the specified GUID
156-
updateData(formatSelect.value, index);
163+
164+
console.log(index)
165+
166+
if (index == -1) {
167+
showModalOk('WARNING', `${getString("report_guid_missing")} <br/> <br/> <code>${guid}</code>`)
157168
}
169+
170+
// Load the notification with the specified GUID
171+
updateData(formatSelect.value, index);
172+
158173
})
159174
.catch(error => {
160175
console.error('Error:', error);

install/install_dependencies.sh

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@ echo "---------------------------------------------------------"
44
echo "[INSTALL] Run install_dependencies.sh"
55
echo "---------------------------------------------------------"
66

7-
# Set environment variables
8-
INSTALL_DIR=/home/pi # Specify the installation directory here
7+
# ❗ IMPORTANT - if you modify this file modify the root Dockerfile as well ❗
98

109
# Check if script is run as root
1110
if [[ $EUID -ne 0 ]]; then
1211
echo "This script must be run as root. Please use 'sudo'."
1312
exit 1
1413
fi
1514

16-
1715
# Install dependencies
1816
apt-get install -y \
1917
tini snmp ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo \
2018
nginx-light php php-cgi php-fpm php-sqlite3 php-curl sqlite3 dnsutils net-tools \
2119
python3 iproute2 nmap python3-pip zip systemctl usbutils traceroute
2220

23-
# ---------------------------------------------------------------
2421
# alternate dependencies
25-
# sudo apt-get install mtr-tiny -y
26-
sudo apt-get install nginx nginx-core mtr php-fpm php8.2-fpm -y
27-
sudo apt-get install php-cli php8.2 php8.2-fpm -y
28-
sudo apt-get install php8.2-sqlite3 -y
22+
sudo apt-get install nginx nginx-core mtr php-fpm php8.2-fpm php-cli php8.2 php8.2-sqlite3 -y
2923
sudo phpenmod -v 8.2 sqlite3
30-
# sudo apt-get install net-tools -y
31-
# ---------------------------------------------------------------
24+
25+
# setup virtual python environment so we can use pip3 to install packages
26+
apt-get install python3.11-venv -y
27+
python3 -m venv myenv
28+
source myenv/bin/activate
29+
30+
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
31+
32+
# install packages thru pip3
33+
pip3 install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet

install/install_python.sh

-17
This file was deleted.

pialert/helper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ def filePermissions():
191191
(confR_access, dbR_access) = checkPermissionsOK() # Initial check
192192

193193
if confR_access == False:
194-
initialiseFile(fullConfPath, "/home/pi/pialert/back/pialert.conf_bak" )
194+
initialiseFile(fullConfPath, "/home/pi/pialert/back/pialert.conf" )
195195

196196
# check and initialize pialert.db
197197
if dbR_access == False:
198-
initialiseFile(fullDbPath, "/home/pi/pialert/back/pialert.db_bak")
198+
initialiseFile(fullDbPath, "/home/pi/pialert/back/pialert.db")
199199

200200
# last attempt
201201
fixPermissions()

0 commit comments

Comments
 (0)