push comp
oginstaller/pipeline/head There was a failure building this commit
Details
oginstaller/pipeline/head There was a failure building this commit
Details
parent
8162f5b3c3
commit
5a7952efe3
|
@ -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/ogrepo.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,50 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
set -x
|
||||
|
||||
cd /opt/opengnsys/ogCore/repo/
|
||||
|
||||
# Preparar el fichero .yaml
|
||||
CONF_DIR=/opt/opengnsys/ogCore/etc/
|
||||
mkdir -p $CONF_DIR
|
||||
|
||||
# Copiar el fichero de configuración a CONF_DIR
|
||||
cp docker-compose-deploy.yml $CONF_DIR/
|
||||
|
||||
if [ -f /opt/opengnsys/ogCore/installer/.deployed ]; then
|
||||
echo "ogCore ya instalado"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while ! docker compose -f $CONF_DIR/docker-compose-deploy.yml ps --format json |jq -r '"\(.Name) \(.State)"' |grep -q 'ogcore-php running'; do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
adminuser=$(jq -r '.username' /opt/opengnsys/ogCore/installer/config.json)
|
||||
adminpass=$(jq -r '.password' /opt/opengnsys/ogCore/installer/config.json)
|
||||
|
||||
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php composer install
|
||||
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php php bin/console lexik:jwt:generate-keypair --overwrite
|
||||
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php php bin/console doctrine:migrations:migrate --no-interaction
|
||||
## TODO we need to feed $adminuser and $adminpass to doctrine:fixtures:load somehow
|
||||
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php php bin/console doctrine:fixtures:load --no-interaction
|
||||
|
||||
|
||||
# Provision user admin
|
||||
bearer=$(curl -k -X 'POST' 'https://localhost:8443/auth/login' -H 'accept: application/json' -H 'Content-Type: application/json' -d "{ \"username\": \"ogadmin\", \"password\": \"12345678\" }" | jq .token | sed 's/"//g' )
|
||||
|
||||
|
||||
if [ $adminuser == "ogadmin" ]; then
|
||||
echo "Cambiando password a ogadmin no puede ser el usuario administrador"
|
||||
ogadmin_uuid=$(curl -q -k -L https://localhost:8443/users/?username=ogadmin -H 'accept: application/json' -H "Authorization: Bearer $bearer" | jq .[0].uuid | sed 's/"//g')
|
||||
curl -k -L -X PUT "https://localhost:8443/users/$ogadmin_uuid/reset-password" -H 'accept: application/ld+json' -H 'Content-Type: application/ld+json' -d "{\"currentPassword\": \"12345678\", \"newPassword\": \"$adminpass\", \"repeatNewPassword\": \"$adminpass\"}" -H "Authorization: Bearer $bearer"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
curl -k -L --location 'https://localhost:8443/users' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header "Authorization: Bearer $bearer" \
|
||||
--data "{ \"username\": \"$adminuser\", \"password\": \"$adminpass\", \"roles\": [\"ROLE_SUPER_ADMIN\"] }"
|
||||
|
||||
touch /opt/opengnsys/ogCore/installer/.deployed
|
||||
exit 0
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
set -x
|
||||
|
||||
# preparar el fichero .env
|
||||
ENV_DIR=/opt/opengnsys/ogGui/etc/
|
||||
ENV_FILE=$ENV_DIR/.env
|
||||
mkdir -p $ENV_DIR
|
||||
|
||||
# Comprobar si ya se ha instalado ogCore
|
||||
#if [ -f /opt/opengnsys/ogGui/installer/.deployed ]; then
|
||||
# echo "ogCore ya instalado"
|
||||
# exit 0
|
||||
#fi
|
||||
|
||||
# Sacar la IP del ogCore de la configuración
|
||||
ogcore_ip=$(jq -r '.ogcore_ip' /opt/opengnsys/ogGui/installer/config.json)
|
||||
export OGCORE_IP="$ogcore_ip"
|
||||
|
||||
# Si no se ha configurado la IP del ogCore, se intenta obtener de la interfaz de red
|
||||
if [ -z "$ogcore_ip" ]; then
|
||||
# Obtiene el nombre del interfaz asociado a la ruta por defecto
|
||||
interface=$(ip route | grep default | awk '{print $5}')
|
||||
|
||||
# Si se encuentra el interfaz, obtiene su dirección IP
|
||||
if [ -n "$interface" ]; then
|
||||
ip_address=$(ip -o -4 addr show "$interface" | awk '{print $4}' | cut -d'/' -f1)
|
||||
ogcore_ip=$ip_address
|
||||
# Si no se ha configurado la IP del ogCore, se escribe en el fichero .env
|
||||
echo "NG_APP_BASE_API_URL=https://$ogcore_ip:8443" > $ENV_FILE
|
||||
exit 0
|
||||
else
|
||||
echo "No se pudo determinar el interfaz asociado a la ruta por defecto."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Si se ha configurado la IP del ogCore, se escribe en el fichero .env
|
||||
echo "NG_APP_BASE_API_URL=$OGCORE_IP" > $ENV_FILE
|
||||
|
||||
touch /opt/opengnsys/ogGui/installer/.deployed
|
|
@ -0,0 +1,134 @@
|
|||
import curses
|
||||
import json
|
||||
import os
|
||||
|
||||
CONFIGS_DIR = "/tmp/opengnsys-installer-configs"
|
||||
os.makedirs(CONFIGS_DIR, exist_ok=True)
|
||||
|
||||
def main(stdscr):
|
||||
# Inicializar colores
|
||||
curses.start_color()
|
||||
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) # Texto blanco sobre fondo azul
|
||||
stdscr.bkgd(' ', curses.color_pair(1)) # Aplicar fondo azul a la pantalla
|
||||
|
||||
curses.curs_set(0) # Ocultar el cursor en el menú de selección
|
||||
stdscr.clear()
|
||||
|
||||
# Paso 1: Seleccionar componentes
|
||||
components = ["ogCore", "ogGui", "ogDhcp", "ogBoot", "ogRepository"]
|
||||
selected_components = []
|
||||
current_index = 0 # Índice para saber en qué componente está el cursor
|
||||
|
||||
# Mostrar instrucciones y opciones de componentes
|
||||
stdscr.addstr(1, 2, "Selecciona los componentes (usa Flechas para navegar, Espacio para seleccionar, Enter para continuar):", curses.color_pair(1) | curses.A_BOLD)
|
||||
|
||||
while True:
|
||||
# Mostrar el estado actual de selección de cada componente
|
||||
for idx, comp in enumerate(components):
|
||||
if comp in selected_components:
|
||||
stdscr.addstr(idx + 3, 4, f"[X] {comp}", curses.color_pair(1))
|
||||
else:
|
||||
stdscr.addstr(idx + 3, 4, f"[ ] {comp}", curses.color_pair(1))
|
||||
|
||||
# Mueve el cursor visualmente para resaltar la selección actual
|
||||
stdscr.addstr(current_index + 3, 4, f"> {components[current_index]}", curses.color_pair(1))
|
||||
|
||||
key = stdscr.getch()
|
||||
|
||||
if key == curses.KEY_UP and current_index > 0: # Navegar hacia arriba
|
||||
current_index -= 1
|
||||
elif key == curses.KEY_DOWN and current_index < len(components) - 1: # Navegar hacia abajo
|
||||
current_index += 1
|
||||
elif key == ord(" "): # Marcar/desmarcar con espacio
|
||||
component = components[current_index]
|
||||
if component in selected_components:
|
||||
selected_components.remove(component)
|
||||
else:
|
||||
selected_components.append(component)
|
||||
elif key == ord("\n"): # Confirma la selección con Enter
|
||||
break
|
||||
|
||||
stdscr.refresh()
|
||||
|
||||
# Ahora pasamos a la configuración específica de cada componente seleccionado
|
||||
curses.echo() # Activar eco para mostrar la entrada
|
||||
for component in selected_components:
|
||||
stdscr.clear()
|
||||
stdscr.addstr(1, 2, f"Configuración para {component}:", curses.color_pair(1) | curses.A_BOLD)
|
||||
curses.curs_set(1) # Mostrar el cursor para las entradas de configuración
|
||||
|
||||
config_data = {}
|
||||
if component == "ogCore":
|
||||
stdscr.addstr(3, 4, "Usuario administrador:", curses.color_pair(1))
|
||||
user = stdscr.getstr(3, 26, 20).decode("utf-8")
|
||||
stdscr.addstr(4, 4, "Contraseña:", curses.color_pair(1))
|
||||
password = stdscr.getstr(4, 26, 20).decode("utf-8")
|
||||
stdscr.addstr(5, 4, "Tag del contenedor:", curses.color_pair(1))
|
||||
container_tag = stdscr.getstr(5, 26, 20).decode("utf-8")
|
||||
|
||||
config_data = {"username": user, "password": password, "container_version": container_tag}
|
||||
|
||||
elif component == "ogGui":
|
||||
stdscr.addstr(3, 4, "IP del servidor de ogCore:", curses.color_pair(1))
|
||||
ogcore_ip = stdscr.getstr(3, 32, 20).decode("utf-8")
|
||||
stdscr.addstr(4, 4, "Tag del contenedor:", curses.color_pair(1))
|
||||
container_version = stdscr.getstr(4, 32, 20).decode("utf-8")
|
||||
|
||||
config_data = {"ogcore_ip": ogcore_ip, "container_version": container_version}
|
||||
|
||||
elif component == "ogDhcp":
|
||||
stdscr.addstr(3, 4, "Configuración IP servidor de Boot:", curses.color_pair(1))
|
||||
ogbootIP = stdscr.getstr(3, 37, 20).decode("utf-8")
|
||||
stdscr.addstr(4, 4, "Interfaces Boot (separadas por coma):", curses.color_pair(1))
|
||||
interfaces = stdscr.getstr(4, 40, 20).decode("utf-8")
|
||||
json_array_interfaces = interfaces.split(",")
|
||||
|
||||
config_data = {"ogbootIP": ogbootIP, "interfaces": json_array_interfaces}
|
||||
|
||||
elif component == "ogBoot":
|
||||
stdscr.addstr(3, 4, "ogCore Ip Server:", curses.color_pair(1))
|
||||
ogcore_ip = stdscr.getstr(3, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(4, 4, "ogCore Server:", curses.color_pair(1))
|
||||
ogcore_server = stdscr.getstr(4, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(5, 4, "ogCore Dir:", curses.color_pair(1))
|
||||
ogcore_dir = stdscr.getstr(5, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(6, 4, "ogBoot GitRepo:", curses.color_pair(1))
|
||||
ogboot_gitrepo = stdscr.getstr(6, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(7, 4, "ogBoot Samba User:", curses.color_pair(1))
|
||||
ogboot_samba_user = stdscr.getstr(7, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(8, 4, "ogBoot Samba Pass:", curses.color_pair(1))
|
||||
ogboot_samba_pass = stdscr.getstr(8, 28, 20).decode("utf-8")
|
||||
|
||||
config_data = {
|
||||
"ogcore_ip": ogcore_ip,
|
||||
"ogcore_server": ogcore_server,
|
||||
"ogcore_dir": ogcore_dir,
|
||||
"ogboot_gitrepo": ogboot_gitrepo,
|
||||
"ogboot_samba_user": ogboot_samba_user,
|
||||
"ogboot_samba_pass": ogboot_samba_pass,
|
||||
}
|
||||
elif component == "ogRepository":
|
||||
stdscr.addstr(3, 4, "ogRepository IP Server: ", curses.color_pair(1))
|
||||
ogrepository_ip = stdscr.getstr(3, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(4, 4, "ogRepository Sambauser: ", curses.color_pair(1))
|
||||
ogrepository_samba_user = stdscr.getstr(4, 28, 20).decode("utf-8")
|
||||
stdscr.addstr(5, 4, "ogRepository Sambapass: ", curses.color_pair(1))
|
||||
ogrepository_samba_pass = stdscr.getstr(5, 28, 20).decode("utf-8")
|
||||
|
||||
config_data = {
|
||||
"ogrepository_ip": ogrepository_ip,
|
||||
"ogrepository_samba_user": ogrepository_samba_user,
|
||||
"ogrepository_samba_pass": ogrepository_samba_pass,
|
||||
}
|
||||
# Guardar en archivo JSON
|
||||
config_file = os.path.join(CONFIGS_DIR, f"config_{component}.json")
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config_data, f)
|
||||
stdscr.clear()
|
||||
stdscr.addstr(2, 2, f"Configuración de {component} guardada en {config_file}", curses.color_pair(1))
|
||||
stdscr.refresh()
|
||||
stdscr.getch()
|
||||
|
||||
curses.noecho() # Desactivar el eco después de la entrada
|
||||
|
||||
curses.wrapper(main)
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Setup installer environment
|
||||
|
||||
|
||||
BRANCH=${BRANCH:-main}
|
||||
GIT_SSL_NO_VERIFY=1
|
||||
GIT_REPO="https://ognproject.evlt.uma.es/gitea/api/v1/repos/opengnsys/oginstaller/archive/$BRANCH.zip"
|
||||
export GIT_SSL_NO_VERIFY
|
||||
|
||||
|
||||
|
||||
install_packages() {
|
||||
apt-get update
|
||||
apt-get install -y curl jq unzip python3
|
||||
}
|
||||
|
||||
download_installer() {
|
||||
|
||||
rm -f /tmp/oginstaller.zip
|
||||
rm -rf /tmp/oginstaller-$BRANCH
|
||||
rm -rf /tmp/oginstaller
|
||||
|
||||
curl -q -k $GIT_REPO -H 'accept: application/json' -o /tmp/oginstaller.zip
|
||||
unzip /tmp/oginstaller.zip -d /tmp
|
||||
mv /tmp/oginstaller /tmp/oginstaller-$BRANCH
|
||||
}
|
||||
|
||||
extract_installer() {
|
||||
rm -rf /tmp/oginstall
|
||||
mkdir -p /tmp/oginstall
|
||||
cp -r /tmp/oginstaller-$BRANCH/python-installer/* /tmp/oginstall/
|
||||
cp -r /tmp/oginstaller-$BRANCH/component-installer/* /tmp/oginstall/
|
||||
}
|
||||
|
||||
create_questions() {
|
||||
echo "Creating questions..."
|
||||
python3 /tmp/oginstall/oginstaller.py
|
||||
}
|
||||
|
||||
|
||||
install_packages
|
||||
download_installer
|
||||
extract_installer
|
||||
create_questions
|
||||
|
Loading…
Reference in New Issue