Skip to content

Commit cd761a0

Browse files
committed
Merge branch 'main' of https://github.com/jokob-sk/Pi.Alert
2 parents bf137a9 + 81cfa72 commit cd761a0

File tree

8 files changed

+94
-47
lines changed

8 files changed

+94
-47
lines changed

back/update_vendors.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
23
# ------------------------------------------------------------------------------
34
# Pi.Alert
45
# Open Source Network Guard / WIFI & LAN intrusion detector
@@ -20,15 +21,15 @@ echo "---------------------------------------------------------"
2021

2122
# ----------------------------------------------------------------------
2223
echo Updating... /usr/share/ieee-data/
23-
cd /usr/share/ieee-data/
24+
cd /usr/share/ieee-data/ || { echo "could not enter /usr/share/ieee-data directory"; exit 1; }
2425

2526
sudo mkdir -p 2_backup
26-
sudo cp *.txt 2_backup
27-
sudo cp *.csv 2_backup
27+
sudo cp -- *.txt 2_backup
28+
sudo cp -- *.csv 2_backup
2829
echo ""
2930
echo Download Start
3031
echo ""
31-
sudo curl $1 -LO https://standards-oui.ieee.org/iab/iab.csv \
32+
sudo curl "$1" -LO https://standards-oui.ieee.org/iab/iab.csv \
3233
-LO https://standards-oui.ieee.org/iab/iab.txt \
3334
-LO https://standards-oui.ieee.org/oui28/mam.csv \
3435
-LO https://standards-oui.ieee.org/iab/iab.txt \
@@ -44,10 +45,10 @@ echo Download Finished
4445
# ----------------------------------------------------------------------
4546
echo ""
4647
echo Updating... /usr/share/arp-scan/
47-
cd /usr/share/arp-scan
48+
cd /usr/share/arp-scan || { echo "could not enter /usr/share/arp-scan directory"; exit 1; }
4849

4950
sudo mkdir -p 2_backup
50-
sudo cp *.txt 2_backup
51+
sudo cp -- *.txt 2_backup
5152

5253
# Update from /usb/lib/ieee-data
5354
sudo get-iab -v

dockerfiles/start.sh

+39-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
echo "---------------------------------------------------------"
44
echo "[INSTALL] Run start.sh"
@@ -7,6 +7,12 @@ echo "---------------------------------------------------------"
77

88
INSTALL_DIR=/home/pi # Specify the installation directory here
99

10+
# DO NOT CHANGE ANYTHING BELOW THIS LINE!
11+
WEB_UI_DIR=/var/www/html/pialert
12+
NGINX_CONFIG_FILE=/etc/nginx/conf.d/pialert.conf
13+
OUI_FILE="/usr/share/arp-scan/ieee-oui.txt" # Define the path to ieee-oui.txt and ieee-iab.txt
14+
# DO NOT CHANGE ANYTHING ABOVE THIS LINE!
15+
1016
# if custom variables not set we do not need to do anything
1117
if [ -n "${TZ}" ]; then
1218
FILECONF=$INSTALL_DIR/pialert/config/pialert.conf
@@ -29,38 +35,50 @@ echo "[INSTALL] Run setup scripts"
2935
"$INSTALL_DIR/pialert/dockerfiles/user-mapping.sh"
3036
"$INSTALL_DIR/pialert/install/install_dependencies.sh" # if modifying this file transfer the chanegs into the root Dockerfile as well!
3137

32-
# Change port number if set
33-
if [ -n "${PORT}" ]; then
34-
sed -ie 's/listen 20211/listen '${PORT}'/g' /etc/nginx/sites-available/default
35-
fi
36-
3738
echo "[INSTALL] Setup NGINX"
3839

39-
# Remove /html folder if exists
40-
sudo rm -R /var/www/html
40+
# Remove default NGINX site if it is symlinked, or backup it otherwise
41+
if [ -L /etc/nginx/sites-enabled/default ] ; then
42+
echo "Disabling default NGINX site, removing sym-link in /etc/nginx/sites-enabled"
43+
sudo rm /etc/nginx/sites-enabled/default
44+
elif [ -f /etc/nginx/sites-enabled/default ]; then
45+
echo "Disabling default NGINX site, moving config to /etc/nginx/sites-available"
46+
sudo mv /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default.bkp_pialert
47+
fi
48+
49+
# Clear existing directories and files
50+
if [ -d $WEB_UI_DIR ]; then
51+
echo "Removing existing PiAlert web-UI"
52+
sudo rm -R $WEB_UI_DIR
53+
fi
54+
55+
if [ -f $NGINX_CONFIG_FILE ]; then
56+
echo "Removing existing PiAlert NGINX config"
57+
sudo rm $NGINX_CONFIG_FILE
58+
fi
4159

4260
# create symbolic link to the pialert install directory
43-
ln -s $INSTALL_DIR/pialert/front /var/www/html
44-
# remove dfault NGINX site
45-
sudo rm /etc/nginx/sites-available/default
61+
ln -s $INSTALL_DIR/pialert/front $WEB_UI_DIR
4662
# create symbolic link to NGINX configuaration coming with PiAlert
47-
sudo ln -s "$INSTALL_DIR/pialert/install/default" /etc/nginx/sites-available/default
48-
# use user-supplied port
49-
sudo sed -i 's/listen 80/listen '"$PORT"'/g' /etc/nginx/sites-available/default
63+
sudo ln -s "$INSTALL_DIR/pialert/install/pialert.conf" /etc/nginx/conf.d/pialert.conf
64+
65+
# Use user-supplied port if set
66+
if [ -n "${PORT}" ]; then
67+
echo "Setting webserver to user-supplied port ($PORT)"
68+
sudo sed -i 's/listen 20211/listen '"$PORT"'/g' /etc/nginx/conf.d/pialert.conf
69+
fi
5070

5171
# Change web interface address if set
52-
if [ -n "${LISTEN_ADDR}" ]; then
53-
sed -ie 's/listen /listen '${LISTEN_ADDR}:'/g' /etc/nginx/sites-available/default
72+
if [ -n "${LISTEN_ADDR}" ]; then
73+
echo "Setting webserver to user-supplied address ($LISTEN_ADDR)"
74+
sed -ie 's/listen /listen '"${LISTEN_ADDR}":'/g' /etc/nginx/conf.d/pialert.conf
5475
fi
5576

5677
# Run the hardware vendors update at least once
5778
echo "[INSTALL] Run the hardware vendors update"
5879

59-
# Define the path to ieee-oui.txt and ieee-iab.txt
60-
oui_file="/usr/share/arp-scan/ieee-oui.txt"
61-
6280
# Check if ieee-oui.txt or ieee-iab.txt exist
63-
if [ -f "$oui_file" ]; then
81+
if [ -f "$OUI_FILE" ]; then
6482
echo "The file ieee-oui.txt exists. Skipping update_vendors.sh..."
6583
else
6684
echo "The file ieee-oui.txt does not exist. Running update_vendors..."
@@ -77,7 +95,7 @@ fi
7795
echo "[INSTALL] Fixing file permissions"
7896

7997

80-
chmod -R a+rwx /var/www/html
98+
chmod -R a+rwx $WEB_UI_DIR
8199
chmod -R a+rw $INSTALL_DIR/pialert/front/log
82100
chmod -R a+rwx $INSTALL_DIR
83101

dockerfiles/user-mapping.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
echo "---------------------------------------------------------"
44
echo "[INSTALL] Run user-mapping.sh"
@@ -9,7 +9,7 @@ if [ -z "${USER}" ]; then
99
fi
1010

1111
# if both not set we do not need to do anything
12-
if [ -z "${HOST_USER_ID}" -a -z "${HOST_USER_GID}" ]; then
12+
if [ -z "${HOST_USER_ID}" ] && [ -z "${HOST_USER_GID}" ]; then
1313
echo "Nothing to do here." ; exit 0
1414
fi
1515

@@ -20,20 +20,20 @@ USER_GID=${HOST_USER_GID:=$USER_GID}
2020

2121
LINE=$(grep -F "${USER}" /etc/passwd)
2222
# replace all ':' with a space and create array
23-
array=( ${LINE//:/ } )
23+
array=( "${LINE//:/ }" )
2424

2525
# home is 5th element
2626
USER_HOME=${array[4]}
2727

2828
# print debug output
29-
echo USER_ID : ${USER_ID};
30-
echo USER_GID : ${USER_GID};
31-
echo USER_HOME: ${USER_HOME};
32-
echo TZ : ${TZ};
29+
echo USER_ID" ": "${USER_ID}";
30+
echo USER_GID : "${USER_GID}";
31+
echo USER_HOME: "${USER_HOME}";
32+
echo TZ" ": "${TZ}";
3333

3434
sed -i -e "s/^${USER}:\([^:]*\):[0-9]*:[0-9]*/${USER}:\1:${USER_ID}:${USER_GID}/" /etc/passwd
3535
sed -i -e "s/^${USER}:\([^:]*\):[0-9]*/${USER}:\1:${USER_GID}/" /etc/group
3636

37-
chown -R ${USER_ID}:${USER_GID} ${USER_HOME}
37+
chown -R "${USER_ID}:${USER_GID} ${USER_HOME}"
3838

39-
exec su - "${USER}"
39+
exec su - "${USER}"

docs/HW_INSTALL.md

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
# How to install PiAlert on the server hardware
22

3-
To download and install PiAlert on the hardware/server directly use `curl` or `wget` commands.
3+
To download and install PiAlert on the hardware/server directly use `curl` or `wget` commands.
44

5-
> [!NOTE]
6-
> This is an Experimental feature 🧪 and it relies on community support.
5+
> [!NOTE]
6+
> This is an Experimental feature 🧪 and it relies on community support.
7+
>
8+
> There is no guarantee that the install script or any other script will gracefully handle other installed software.
9+
> Data loss is a possibility, **it is recommended to install PiAlert using the supplied Docker image**.
10+
11+
A warning to the installation method below: Piping to bash is [controversial](https://pi-hole.net/2016/07/25/curling-and-piping-to-bash) and may
12+
be dangerous, as you cannot see the code that's about to be executed on your system.
13+
14+
Alternatively you can download the installation script `install/install.sh` from the repository and check the code yourself (beware other scripts are
15+
downloaded too - only from this repo).
716

817
PiAlert will be installed in `home/pi/pialert/` and run on port number `20211`.
918

19+
Some facts about what and where something will be changed/installed by the HW install setup (may not contain everything!):
20+
21+
- `/home/pi/pialert` directory will be deleted and newly created
22+
- `/home/pi/pialert` will contain the whole repository (downloaded by `install/install.sh`)
23+
- The default NGINX site `/etc/nginx/sites-enabled/default` will be disabled (sym-link deleted or backed up to `sites-available`)
24+
- `/var/www/html/pialert` directory will be deleted and newly created
25+
- `/etc/nginx/conf.d/pialert.conf` will be sym-linked to `/home/pi/pialert/install/pialert.conf`
26+
- Some files (IEEE device vendors info, ...) will be created in the directory where the installation script is executed
27+
28+
## Limitations
29+
30+
- No system service is provided. PiAlert must be started using `/home/pi/pialert/dockerfiles/start.sh`.
31+
- No checks for other running software is done.
32+
- Only tested to work on Debian Bookworm (Debian 12).
33+
- **EXPERIMENTAL** and not recommended way to install PiAlert.
34+
1035
## CURL
1136

1237
```bash
@@ -15,11 +40,10 @@ curl -o install.sh https://raw.githubusercontent.com/jokob-sk/Pi.Alert/main/inst
1540

1641
## WGET
1742

18-
1943
```bash
2044
wget https://raw.githubusercontent.com/jokob-sk/Pi.Alert/main/install/install.sh -O install.sh && sudo chmod +x install.sh && sudo ./install.sh
2145
```
2246

2347
These commands will download the `install.sh` script from the GitHub repository, make it executable with `chmod`, and then run it using `./install.sh`.
2448

25-
Make sure you have the necessary permissions to execute the script.
49+
Make sure you have the necessary permissions to execute the script.

front/buildtimestamp.txt

Whitespace-only changes.

install/install.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
echo "---------------------------------------------------------"
44
echo "[INSTALL] Run install.sh"
@@ -26,6 +26,10 @@ rm -R $INSTALL_DIR/pialert
2626
# Clone the application repository
2727
git clone https://github.com/jokob-sk/Pi.Alert "$INSTALL_DIR/pialert"
2828

29+
# Check for buildtimestamp.txt existence, otherwise create it
30+
if [ ! -f $INSTALL_DIR/pialert/front/buildtimestamp.txt ]; then
31+
date +%s > $INSTALL_DIR/pialert/front/buildtimestamp.txt
32+
fi
2933

3034
# Start PiAlert
3135
"$INSTALL_DIR/pialert/dockerfiles/start.sh"

install/install_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
echo "---------------------------------------------------------"
44
echo "[INSTALL] Run install_dependencies.sh"

install/default renamed to install/pialert.conf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server {
2-
listen 80 default_server;
3-
root /var/www/html;
2+
listen 20211 default_server;
3+
root /var/www/html/pialert;
44
index index.php;
55
#rewrite /pialert/(.*) / permanent;
66
add_header X-Forwarded-Prefix "/pialert" always;
@@ -15,4 +15,4 @@ server {
1515
fastcgi_send_timeout 600;
1616
fastcgi_read_timeout 600;
1717
}
18-
}
18+
}

0 commit comments

Comments
 (0)