Files
NetAlertX/install/ubuntu/install.ubuntu.sh
Ingo Ratsdorf b0d117c3b8 Update install/ubuntu/install.ubuntu.sh
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-09-10 08:49:48 +12:00

87 lines
3.0 KiB
Bash

#!/usr/bin/env bash
# 🛑 Important: This is only used for the bare-metal install 🛑
# Update /install/start.ubuntu.sh in most cases is preferred
echo "---------------------------------------------------------"
echo "[INSTALL] Starting NetAlertX installation for Ubuntu"
echo "---------------------------------------------------------"
echo
echo "This script will install NetAlertX on your Ubuntu system."
echo "It will clone the repository, set up necessary files, and start the application."
echo "Please ensure you have a stable internet connection."
echo "---------------------------------------------------------"
# Set environment variables
INSTALL_DIR=/app # Specify the installation directory here
# Check if script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use 'sudo'."
exit 1
fi
# Prepare the environment
echo "Updating packages"
echo "-----------------"
apt-get update
echo "Making sure sudo is installed"
apt-get install sudo -y
# Install Git
echo "Installing Git"
apt-get install -y git
# Clean the directory, ask for confirmation
if [ -d "$INSTALL_DIR" ]; then
echo "The installation directory exists. Removing it to ensure a clean install."
echo "Are you sure you want to continue? This will delete all existing files in $INSTALL_DIR."
echo "Type:"
echo " - 'install' to continue"
echo " - 'update' to just update from GIT"
echo " - 'start' to do nothing, leave install as-is"
if [ "$1" == "install" ] || [ "$1" == "update" ] || [ "$1" == "start" ]; then
confirmation=$1
else
read -p "Enter your choice: " confirmation
fi
if [ "$confirmation" == "install" ]; then
if [ -n "$INSTALL_DIR" ] && [ "$INSTALL_DIR" != "" ]; then
echo "Removing existing installation..."
service nginx stop 2>/dev/null
pkill -f "python /app/server" 2>/dev/null
umount "$INSTALL_DIR/api" 2>/dev/null
umount "$INSTALL_DIR/front" 2>/dev/null
rm -rf "$INSTALL_DIR/"
git clone https://github.com/jokob-sk/NetAlertX "$INSTALL_DIR/"
else
echo "INSTALL_DIR is not set or is root. Aborting for safety."
exit 1
fi
elif [ "$confirmation" == "update" ]; then
echo "Updating the existing installation..."
service nginx stop 2>/dev/null
pkill -f "python ${INSTALL_DIR}/server" 2>/dev/null
cd "$INSTALL_DIR" || { echo "Failed to change directory to $INSTALL_DIR"; exit 1; }
git pull
elif [ "$confirmation" == "start" ]; then
echo "Continuing without changes."
else
echo "Installation aborted."
exit 1
fi
else
git clone https://github.com/jokob-sk/NetAlertX "$INSTALL_DIR/"
fi
# Check for buildtimestamp.txt existence, otherwise create it
if [ ! -f "$INSTALL_DIR/front/buildtimestamp.txt" ]; then
date +%s > "$INSTALL_DIR/front/buildtimestamp.txt"
fi
# Start NetAlertX
# This is where we setup the virtual environment and install dependencies
cd "$INSTALL_DIR/install/ubuntu" || { echo "Failed to change directory to $INSTALL_DIR/install/ubuntu"; exit 1; }
"$INSTALL_DIR/install/ubuntu/start.ubuntu.sh"