mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
138 lines
4.3 KiB
Bash
Executable File
138 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Runtime setup for devcontainer (executed after container starts).
|
|
# Prefer building setup into resources/devcontainer-Dockerfile when possible.
|
|
# Use this script for runtime-only adjustments (permissions, sockets, ownership,
|
|
# and services managed without init) that are difficult at build time.
|
|
id
|
|
|
|
# Define variables (paths, ports, environment)
|
|
|
|
export APP_DIR="/app"
|
|
export APP_COMMAND="/workspaces/NetAlertX/.devcontainer/scripts/restart-backend.sh"
|
|
export PHP_FPM_BIN="/usr/sbin/php-fpm83"
|
|
export CROND_BIN="/usr/sbin/crond -f"
|
|
|
|
|
|
export ALWAYS_FRESH_INSTALL=false
|
|
export INSTALL_DIR=/app
|
|
export LOGS_LOCATION=/app/logs
|
|
export CONF_FILE="app.conf"
|
|
export DB_FILE="app.db"
|
|
export FULL_FILEDB_PATH="${INSTALL_DIR}/db/${DB_FILE}"
|
|
export OUI_FILE="/usr/share/arp-scan/ieee-oui.txt" # Define the path to ieee-oui.txt and ieee-iab.txt
|
|
export TZ=Europe/Paris
|
|
export PORT=20211
|
|
export SOURCE_DIR="/workspaces/NetAlertX"
|
|
|
|
|
|
main() {
|
|
echo "=== NetAlertX Development Container Setup ==="
|
|
killall php-fpm83 nginx crond python3 2>/dev/null
|
|
sleep 1
|
|
echo "Setting up ${SOURCE_DIR}..."
|
|
sudo chown $(id -u):$(id -g) /workspaces
|
|
sudo chmod 755 /workspaces
|
|
configure_source
|
|
|
|
echo "--- Starting Development Services ---"
|
|
configure_php
|
|
|
|
|
|
start_services
|
|
}
|
|
|
|
isRamDisk() {
|
|
if [ -z "$1" ] || [ ! -d "$1" ]; then
|
|
echo "Usage: isRamDisk <directory>" >&2
|
|
return 2
|
|
fi
|
|
|
|
local fstype
|
|
fstype=$(df -T "$1" | awk 'NR==2 {print $2}')
|
|
|
|
if [ "$fstype" = "tmpfs" ] || [ "$fstype" = "ramfs" ]; then
|
|
return 0 # Success (is a ramdisk)
|
|
else
|
|
return 1 # Failure (is not a ramdisk)
|
|
fi
|
|
}
|
|
|
|
# Setup source directory
|
|
configure_source() {
|
|
echo "[1/4] Configuring System..."
|
|
echo " -> Setting up /services permissions"
|
|
sudo chown -R netalertx /services
|
|
|
|
echo "[2/4] Configuring Source..."
|
|
echo " -> Cleaning up previous instances"
|
|
|
|
test -e ${NETALERTX_LOG} && sudo umount "${NETALERTX_LOG}" 2>/dev/null || true
|
|
test -e ${NETALERTX_API} && sudo umount "${NETALERTX_API}" 2>/dev/null || true
|
|
test -e ${NETALERTX_APP} && sudo rm -Rf ${NETALERTX_APP}/
|
|
|
|
echo " -> Linking source to ${NETALERTX_APP}"
|
|
sudo ln -s ${SOURCE_DIR}/ ${NETALERTX_APP}
|
|
|
|
echo " -> Mounting ramdisks for /log and /api"
|
|
mkdir -p ${NETALERTX_LOG} ${NETALERTX_API}
|
|
sudo mount -o uid=$(id -u netalertx),gid=$(id -g netalertx),mode=775 -t tmpfs -o size=256M tmpfs "${NETALERTX_LOG}"
|
|
sudo mount -o uid=$(id -u netalertx),gid=$(id -g netalertx),mode=775 -t tmpfs -o size=256M tmpfs "${NETALERTX_API}"
|
|
mkdir -p ${NETALERTX_PLUGINS_LOG}
|
|
touch ${NETALERTX_PLUGINS_LOG}/.dockerignore ${NETALERTX_API}/.dockerignore
|
|
# tmpfs mounts configured with netalertx ownership and 775 permissions above
|
|
|
|
touch /app/log/nginx_error.log
|
|
echo " -> Empty log"|tee ${INSTALL_DIR}/log/app.log \
|
|
${INSTALL_DIR}/log/app_front.log \
|
|
${INSTALL_DIR}/log/stdout.log
|
|
touch ${INSTALL_DIR}/log/stderr.log \
|
|
${INSTALL_DIR}/log/execution_queue.log
|
|
echo 0 > ${INSTALL_DIR}/log/db_is_locked.log
|
|
for f in ${INSTALL_DIR}/log/*.log; do
|
|
sudo chown netalertx:www-data $f
|
|
sudo chmod 664 $f
|
|
echo "" > $f
|
|
done
|
|
|
|
mkdir -p /app/log/plugins
|
|
sudo chown -R netalertx:www-data ${INSTALL_DIR}
|
|
|
|
|
|
while ps ax | grep -v grep | grep python3 > /dev/null; do
|
|
killall python3 &>/dev/null
|
|
sleep 0.2
|
|
done
|
|
|
|
}
|
|
|
|
# configure_php: configure PHP-FPM and enable dev debug options
|
|
configure_php() {
|
|
echo "[3/4] Configuring PHP-FPM..."
|
|
sudo chown -R netalertx:netalertx ${SYSTEM_SERVICES_RUN} 2>/dev/null || true
|
|
|
|
}
|
|
|
|
# start_services: start crond, PHP-FPM, nginx and the application
|
|
start_services() {
|
|
echo "[4/4] Starting services"
|
|
|
|
sudo chmod +x /entrypoint.sh
|
|
setsid bash /entrypoint.sh&
|
|
sleep 1
|
|
}
|
|
|
|
|
|
sudo chmod 755 /app/
|
|
echo "Development $(git rev-parse --short=8 HEAD)"| sudo tee /app/.VERSION
|
|
# Run the main function
|
|
main
|
|
|
|
# create a services readme file
|
|
echo "This folder is auto-generated by the container and devcontainer setup.sh script." > /services/README.md
|
|
echo "Any changes here will be lost on rebuild. To make permanent changes, edit files in .devcontainer or production filesystem and rebuild the container." >> /services/README.md
|
|
echo "Only make temporary/test changes in this folder, then perform a rebuild to reset." >> /services/README.md
|
|
|
|
|
|
|
|
|