Modifying Files
oginstaller/pipeline/head There was a failure building this commit
Details
oginstaller/pipeline/head There was a failure building this commit
Details
parent
105340b165
commit
3fe3fc9a5c
|
@ -0,0 +1,150 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
# Paso 1: Seleccionar los componentes
|
||||||
|
# Los componentes a instalar se encuentran en el directorio /tmp/opengnsys-installer-configs
|
||||||
|
|
||||||
|
# Set configuration
|
||||||
|
|
||||||
|
function install_docker() {
|
||||||
|
apt-get -y update
|
||||||
|
apt-get -y install ca-certificates curl
|
||||||
|
install -m 0755 -d /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
||||||
|
chmod a+r /etc/apt/keyrings/docker.asc
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
|
||||||
|
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
apt-get -y update
|
||||||
|
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
systemctl enable docker
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_ogcore_docker() {
|
||||||
|
cat <<EOF > /etc/systemd/system/ogcore.service
|
||||||
|
[Unit]
|
||||||
|
Description=Servicio para ejecutar Docker Compose de ogCore
|
||||||
|
After=docker.service
|
||||||
|
Requires=docker.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/opt/opengnsys/ogCore/repo/
|
||||||
|
ExecStart=/usr/bin/docker compose -f /opt/opengnsys/ogCore/etc/docker-compose-deploy.yml up
|
||||||
|
ExecStartPost=/opengnsys-installer/provision_ogcore.sh
|
||||||
|
ExecStop=/usr/bin/docker compose -f /opt/opengnsys/ogCore/etc/docker-compose-deploy.yml stop
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now ogcore
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function install_oggui_docker() {
|
||||||
|
# Sacar la IP del ogCore de la configuración
|
||||||
|
oggui_version=$(jq -r '.container_version' /opt/opengnsys/ogGui/installer/config.json)
|
||||||
|
# Exportar los valores como variables de entorno
|
||||||
|
ENV_DIR=/opt/opengnsys/ogGui/etc/
|
||||||
|
ENV_FILE=$ENV_DIR/.env
|
||||||
|
|
||||||
|
cat <<EOF > /etc/systemd/system/oggui-app.service
|
||||||
|
[Unit]
|
||||||
|
Description=Servicio para contenedor Docker de OgGui
|
||||||
|
After=docker.service
|
||||||
|
Requires=docker.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Restart=always
|
||||||
|
ExecStartPre=/opengnsys-installer/provision_oggui.sh
|
||||||
|
ExecStart=/usr/bin/docker run --rm --name ogGui-app -p 4200:4200 -v $ENV_FILE:/app/.env opengnsys/oggui:$oggui_version
|
||||||
|
ExecStop=/usr/bin/docker stop ogGui-app
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now oggui-app
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
COMPONENTS="ogCore ogGui ogDhcp ogBoot ogRepository"
|
||||||
|
CONFIGS_DIR=/opengnsys-installer/
|
||||||
|
PAT_FILE=/opengnsys-installer/pat.txt
|
||||||
|
PAT=$(cat $PAT_FILE | tr -d '\n\r\t')
|
||||||
|
|
||||||
|
OPENGNSYS_BASE_URL="https://$PAT@ognproject.evlt.uma.es/gitea/opengnsys"
|
||||||
|
|
||||||
|
OGBOOT_REPO="$OPENGNSYS_BASE_URL/ogboot.git"
|
||||||
|
OGCORE_REPO="$OPENGNSYS_BASE_URL/ogcore.git"
|
||||||
|
OGDHCP_REPO="$OPENGNSYS_BASE_URL/ogdhcp.git"
|
||||||
|
OGGUI_REPO="$OPENGNSYS_BASE_URL/oggui.git"
|
||||||
|
OGREPOSITORY_REPO="$OPENGNSYS_BASE_URL/ogrepository.git"
|
||||||
|
|
||||||
|
export GIT_SSL_NO_VERIFY=1
|
||||||
|
echo ======================================== > /etc/issue
|
||||||
|
echo "OpenGnSys Installer" >> /etc/issue
|
||||||
|
echo "Componentes instalados:" >> /etc/issue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for component in $COMPONENTS
|
||||||
|
do
|
||||||
|
config_file="config_${component}.json"
|
||||||
|
if [ -f $CONFIGS_DIR/$config_file ]; then
|
||||||
|
echo "Componente $component seleccionado, instalando configuración..."
|
||||||
|
component_dir=/opt/opengnsys/$component
|
||||||
|
mkdir -p $component_dir/installer
|
||||||
|
mkdir -p $component_dir/repo
|
||||||
|
cp $CONFIGS_DIR/$config_file /opt/opengnsys/$component/installer/config.json
|
||||||
|
|
||||||
|
case $component in
|
||||||
|
ogCore)
|
||||||
|
echo "Instalando ogCore..."
|
||||||
|
OGCORE_BRANCH=main
|
||||||
|
container_version=$(jq -r '.container_version' /opt/opengnsys/ogCore/installer/config.json)
|
||||||
|
git clone --branch "$OGCORE_BRANCH" "$OGCORE_REPO" "$component_dir/repo"
|
||||||
|
# Copy the docker-compose-deploy.yml file to /opt/opengnsys/ogCore/etc/
|
||||||
|
mkdir -p $component_dir/etc/
|
||||||
|
cp $component_dir/repo/docker-compose-deploy.yml $component_dir/etc/
|
||||||
|
sed -i "s/static/$container_version/g" $component_dir/repo/docker-compose-deploy.yml
|
||||||
|
echo - ogCore >> /etc/issue
|
||||||
|
install_docker
|
||||||
|
install_ogcore_docker
|
||||||
|
;;
|
||||||
|
ogGui)
|
||||||
|
echo "Instalando ogGui..."
|
||||||
|
OGGUI_BRANCH=main
|
||||||
|
git clone --branch "$OGGUI_BRANCH" "$OGGUI_REPO" "$component_dir/repo"
|
||||||
|
echo - ogGui >> /etc/issue
|
||||||
|
install_docker
|
||||||
|
install_oggui_docker
|
||||||
|
;;
|
||||||
|
ogDhcp)
|
||||||
|
echo "Instalando ogDhcp..."
|
||||||
|
git clone "$OGDHCP_REPO" "$component_dir/repo"
|
||||||
|
echo - ogDhcp >> /etc/issue
|
||||||
|
;;
|
||||||
|
ogBoot)
|
||||||
|
echo "Instalando ogBoot..."
|
||||||
|
git clone "$OGBOOT_REPO" "$component_dir/repo"
|
||||||
|
echo - ogBoot >> /etc/issue
|
||||||
|
;;
|
||||||
|
ogRepository)
|
||||||
|
echo "Instalando ogRepository..."
|
||||||
|
git clone "$OGREPOSITORY_REPO" "$component_dir/repo"
|
||||||
|
echo - ogRepository >> /etc/issue
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Componente $component no reconocido"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ======================================== >> /etc/issue
|
||||||
|
rm -f $PAT_FILE
|
|
@ -0,0 +1,54 @@
|
||||||
|
import os
|
||||||
|
from git import Repo
|
||||||
|
from packaging.version import Version
|
||||||
|
|
||||||
|
def get_highest_remote_tag(repo_path):
|
||||||
|
try:
|
||||||
|
# Abre el repositorio local
|
||||||
|
repo = Repo(repo_path)
|
||||||
|
|
||||||
|
# Asegúrate de que el repositorio tiene un remoto
|
||||||
|
if not repo.remotes:
|
||||||
|
return None # No hay remotos configurados
|
||||||
|
|
||||||
|
# Obtén el remoto por defecto (origin o el primero disponible)
|
||||||
|
remote = repo.remotes.origin
|
||||||
|
|
||||||
|
# Recupera los tags remotos
|
||||||
|
remote.fetch(tags=True)
|
||||||
|
remote_tags = [ref.name.split('/')[-1] for ref in repo.references if ref.path.startswith('refs/tags/')]
|
||||||
|
if not remote_tags:
|
||||||
|
return None # No hay tags remotos
|
||||||
|
|
||||||
|
# Ordena los tags remotos por versión
|
||||||
|
tags_sorted = sorted(remote_tags, key=lambda t: Version(t) if t.replace('.', '').isdigit() else Version('0.0.0'), reverse=True)
|
||||||
|
return tags_sorted[0] if tags_sorted else None
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error al procesar el repositorio {repo_path}: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def process_selected_repositories(base_path, repo_names):
|
||||||
|
repo_highest_tags = {}
|
||||||
|
for repo_name in repo_names:
|
||||||
|
repo_path = os.path.join(base_path, repo_name)
|
||||||
|
if os.path.exists(repo_path) and os.path.isdir(os.path.join(repo_path, '.git')):
|
||||||
|
highest_tag = get_highest_remote_tag(repo_path)
|
||||||
|
repo_highest_tags[repo_name] = highest_tag
|
||||||
|
else:
|
||||||
|
repo_highest_tags[repo_name] = "No es un repositorio Git válido"
|
||||||
|
return repo_highest_tags
|
||||||
|
|
||||||
|
# Ruta base donde están los repositorios locales
|
||||||
|
base_path = "../"
|
||||||
|
|
||||||
|
# Lista de nombres de repositorios específicos
|
||||||
|
repo_names = [ "ogcore" , "oggui" , "ogboot" , "ogdhcp" , "ogrepository" ]
|
||||||
|
|
||||||
|
result = process_selected_repositories(base_path, repo_names)
|
||||||
|
|
||||||
|
# Muestra los resultados
|
||||||
|
for repo_name, tag in result.items():
|
||||||
|
print(f'{repo_name}:{tag}')
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,214 @@
|
||||||
|
#!/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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue