mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 11:39:26 +01:00
143 lines
7.4 KiB
Bash
143 lines
7.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Project N.O.M.A.D. Update Script
|
|
|
|
###################################################################################################################################################################################################
|
|
|
|
# Script | Project N.O.M.A.D. Update Script
|
|
# Version | 1.0.1
|
|
# Author | Crosstalk Solutions, LLC
|
|
# Website | https://crosstalksolutions.com
|
|
|
|
###################################################################################################################################################################################################
|
|
# #
|
|
# Color Codes #
|
|
# #
|
|
###################################################################################################################################################################################################
|
|
|
|
RESET='\033[0m'
|
|
YELLOW='\033[1;33m'
|
|
WHITE_R='\033[39m' # Same as GRAY_R for terminals with white background.
|
|
GRAY_R='\033[39m'
|
|
RED='\033[1;31m' # Light Red.
|
|
GREEN='\033[1;32m' # Light Green.
|
|
|
|
###################################################################################################################################################################################################
|
|
# #
|
|
# Functions #
|
|
# #
|
|
###################################################################################################################################################################################################
|
|
|
|
check_has_sudo() {
|
|
if sudo -n true 2>/dev/null; then
|
|
echo -e "${GREEN}#${RESET} User has sudo permissions.\\n"
|
|
else
|
|
echo "User does not have sudo permissions"
|
|
header_red
|
|
echo -e "${RED}#${RESET} This script requires sudo permissions to run. Please run the script with sudo.\\n"
|
|
echo -e "${RED}#${RESET} For example: sudo bash $(basename "$0")"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_is_bash() {
|
|
if [[ -z "$BASH_VERSION" ]]; then
|
|
header_red
|
|
echo -e "${RED}#${RESET} This script requires bash to run. Please run the script using bash.\\n"
|
|
echo -e "${RED}#${RESET} For example: bash $(basename "$0")"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}#${RESET} This script is running in bash.\\n"
|
|
}
|
|
|
|
check_is_debian_based() {
|
|
if [[ ! -f /etc/debian_version ]]; then
|
|
header_red
|
|
echo -e "${RED}#${RESET} This script is designed to run on Debian-based systems only.\\n"
|
|
echo -e "${RED}#${RESET} Please run this script on a Debian-based system and try again."
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}#${RESET} This script is running on a Debian-based system.\\n"
|
|
}
|
|
|
|
get_update_confirmation(){
|
|
read -p "This script will update Project N.O.M.A.D. and its dependencies on your machine. No data loss is expected, but you should always back up your data before proceeding. Are you sure you want to continue? (y/n): " choice
|
|
case "$choice" in
|
|
y|Y )
|
|
echo -e "${GREEN}#${RESET} User chose to continue with the update."
|
|
;;
|
|
n|N )
|
|
echo -e "${RED}#${RESET} User chose not to continue with the update."
|
|
exit 0
|
|
;;
|
|
* )
|
|
echo "Invalid Response"
|
|
echo "User chose not to continue with the update."
|
|
exit 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
ensure_docker_installed_and_running() {
|
|
if ! command -v docker &> /dev/null; then
|
|
echo -e "${RED}#${RESET} Docker is not installed. This is unexpected, as Project N.O.M.A.D. requires Docker to run. Did you mean to use the install script instead of the update script?"
|
|
exit 1
|
|
fi
|
|
|
|
if ! systemctl is-active --quiet docker; then
|
|
echo -e "${RED}#${RESET} Docker is not running. Attempting to start Docker..."
|
|
sudo systemctl start docker
|
|
if ! systemctl is-active --quiet docker; then
|
|
echo -e "${RED}#${RESET} Failed to start Docker. Please start Docker and try again."
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
ensure_docker_compose_file_exists() {
|
|
if [ ! -f "/opt/project-nomad/docker-compose-management.yml" ]; then
|
|
echo -e "${RED}#${RESET} docker-compose-management.yml file not found. Please ensure it exists at /opt/project-nomad/docker-compose-management.yml."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
force_recreate() {
|
|
echo -e "${YELLOW}#${RESET} Forcing recreation of containers..."
|
|
docker-compose -f /opt/project-nomad/docker-compose-management.yml up -d --force-recreate
|
|
}
|
|
|
|
get_local_ip() {
|
|
local_ip_address=$(hostname -I | awk '{print $1}')
|
|
if [[ -z "$local_ip_address" ]]; then
|
|
echo -e "${RED}#${RESET} Unable to determine local IP address. Please check your network configuration."
|
|
# Don't exit if we can't determine the local IP address, it's not critical for the installation
|
|
fi
|
|
}
|
|
|
|
success_message() {
|
|
echo -e "${GREEN}#${RESET} Project N.O.M.A.D installation completed successfully!\\n"
|
|
echo -e "${GREEN}#${RESET} Installation files are located at /opt/project-nomad\\n\n"
|
|
echo -e "${GREEN}#${RESET} Project N.O.M.A.D's Command Center should automatically start whenever your device reboots. However, if you need to start it manually, you can always do so by running: ${WHITE_R}${nomad_dir}/start_nomad.sh${RESET}\\n"
|
|
echo -e "${GREEN}#${RESET} You can now access the management interface at http://localhost:8080 or http://${local_ip_address}:8080\\n"
|
|
echo -e "${GREEN}#${RESET} Thank you for supporting Project N.O.M.A.D!\\n"
|
|
}
|
|
|
|
###################################################################################################################################################################################################
|
|
# #
|
|
# Main Script #
|
|
# #
|
|
###################################################################################################################################################################################################
|
|
|
|
# Pre-flight checks
|
|
check_is_debian_based
|
|
check_is_bash
|
|
check_has_sudo
|
|
|
|
# Main update
|
|
get_update_confirmation
|
|
ensure_docker_installed_and_running
|
|
ensure_docker_compose_file_exists
|
|
force_recreate
|
|
get_local_ip
|
|
success_message
|