#!/bin/bash # Detect installed components. INSTALLER_BRANCH=${INSTALLER_BRANCH:-main} OPENGNSYS_BASE=/opt/opengnsys OPENGNSYS_COMPONENTS=(ogCore ogGui ogDhcp ogBoot ogRepository) GIT_SSL_NO_VERIFY=1 INSTALLED_COMPONENTS=() GIT_REPO="https://ognproject.evlt.uma.es/gitea/api/v1/repos/opengnsys/oginstaller/archive/$INSTALLER_BRANCH.zip" export GIT_SSL_NO_VERIFY INSTALLED_COMPONENTS=() check_os(){ if [ -f /etc/os-release ]; then . /etc/os-release # Just support Ubuntu 24.04 for now if [ $ID == "ubuntu" ] && [ $VERSION_ID == "24.04" ]; then echo "OS supported." else echo "OS not supported." exit 1 fi else echo "OS not supported." exit 1 fi } detect_installed_components() { local OGNODE=0 for component in "${OPENGNSYS_COMPONENTS[@]}"; do if [ -f "${OPENGNSYS_BASE}/${component}/installer/config.json" ]; then echo "Component $component is installed." INSTALLED_COMPONENTS+=($component) OGNODE=1 else echo "Component $component is not installed." fi done if [ $OGNODE -eq 0 ]; then echo "No OpenGnsys components installed." else echo "Installed components:" "${INSTALLED_COMPONENTS[@]}" fi } # Assume taht all components are at the same release version, get the first installed compoenent and return its version get_og_installed_version() { local component=$1 local version=$(jq -r '.release' ${OPENGNSYS_BASE}/${component}/installer/config.json) echo $version } start_stop_component() { local component=$1 local action=$2 case $component in ogCore) handle_ogcore $action ;; ogGui) handle_oggui $action ;; ogDhcp) handle_ogdhcp $action ;; ogBoot) handle_ogboot $action ;; ogRepository) handle_ogrepository $action ;; *) echo "Component $component not found." ;; esac } stop_installed_services() { echo "Stopping services..." for component in "${INSTALLED_COMPONENTS[@]}"; do echo "Stopping component $component..." start_stop_component $component stop done } start_installed_services() { echo "Starting services..." for component in "${INSTALLED_COMPONENTS[@]}"; do echo "Starting component $component..." start_stop_component $component start done } handle_ogboot() { case $1 in stop) echo "Stopping ogBoot..." systemctl stop nginx systemctl stop tftpd-hpa systemctl stop smbd systemctl stop nmbd ;; start) echo "Starting ogBoot..." systemctl start nginx systemctl start tftpd-hpa systemctl start smbd systemctl start nmbd ;; *) echo "Invalid action." ;; esac } handle_ogdhcp() { case $1 in stop) echo "Stopping ogDhcp..." systemctl stop kea-dhcp4-server systemctl stop kea-ctrl-agent ;; start) echo "Starting ogDhcp..." systemctl start kea-dhcp4-server systemctl start kea-ctrl-agent ;; *) echo "Invalid action." ;; esac } handle_ogrepository() { case $1 in stop) echo "Stopping ogRepository..." systemctl stop smbd systemctl stop nmbd systemctl stop ogrepo-api ;; start) echo "Starting ogRepository..." systemctl start smbd systemctl start nmbd systemctl start ogrepo-api ;; *) echo "Invalid action." ;; esac } handle_ogcore() { case $1 in stop) echo "Stopping ogCore..." systemctl stop ogcore ;; start) echo "Starting ogCore..." systemctl start ogcore ;; *) echo "Invalid action." ;; esac } handle_oggui() { case $1 in stop) echo "Stopping ogGui..." systemctl stop oggui-app ;; start) echo "Starting ogGui..." systemctl start oggui-app ;; *) echo "Invalid action." ;; esac } update_installed_components() { local version=$1 echo "Updating components to version $version..." for component in "${INSTALLED_COMPONENTS[@]}"; do echo "Updating component $component..." update_component $component $version done } #### Main check_os detect_installed_components installed_version=$(get_og_installed_version "${INSTALLED_COMPONENTS[0]}") select_version_to_update stop_installed_services update_installed_components $installed_version start_installed_services