oginstaller/non_graf_installer/component-installer/component-installer.sh

195 lines
7.6 KiB
Bash

#!/usr/bin/bash
set -x
# Paso 1: Seleccionar los componentes
# Los componentes a instalar se encuentran en el directorio /tmp/opengnsys-installer-configs
# Set configuration
COMPONENTS="ogCore ogGui ogDhcp ogBoot ogRepository"
CONFIGS_DIR=/tmp/oginstall
# 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"ls
OPENGNSYS_BASE_URL="https://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
## Functions
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=/opt/opengnsys/ogCore/bin/provision_ogcore.sh
ExecStop=/usr/bin/docker compose -f /opt/opengnsys/ogCore/etc/docker-compose-deploy.yml stop
Restart=always
TimeoutStartSec=600
[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 '.release' /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=/opt/opengnsys/ogGui/bin/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
TimeoutStartSec=600
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now oggui-app
}
function git_checkout_release() {
git clone --no-checkout "$1" "$2"
cd "$2" || exit
git checkout tags/"$3"
cd - || exit
}
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=$(jq -r '.release' /opt/opengnsys/ogCore/installer/config.json)
container_version=$(jq -r '.release' /opt/opengnsys/ogCore/installer/config.json)
git_checkout_release "$OGCORE_REPO" "$component_dir/repo" "$OGCORE_BRANCH"
mkdir -p $component_dir/etc
cp $component_dir/repo/.env $component_dir/etc/
cp $component_dir/repo/env.json $component_dir/etc/
chown 82:82 $component_dir/etc/
mkdir -p $component_dir/bin/
cp $CONFIGS_DIR/provision_ogcore.sh $component_dir/bin/
chmod 755 $component_dir/bin/provision_ogcore.sh
cp $component_dir/repo/docker-compose-deploy.yml $component_dir/etc/
sed -i "s/static/$container_version/g" $component_dir/etc/docker-compose-deploy.yml
cat $component_dir/etc/docker-compose-deploy.yml
echo - ogCore >> /etc/issue
install_docker
install_ogcore_docker
;;
ogGui)
echo "Instalando ogGui..."
OGGUI_BRANCH=$(jq -r '.container_version' /opt/opengnsys/ogGui/installer/config.json)
mkdir -p $component_dir/bin
cp $CONFIGS_DIR/provision_oggui.sh $component_dir/bin/
chmod 755 $component_dir/bin/provision_oggui.sh
git_checkout_release "$OGGUI_REPO" "$component_dir/repo" "$OGGUI_BRANCH"
echo - ogGui >> /etc/issue
install_docker
install_oggui_docker
;;
ogDhcp)
echo "Instalando ogDhcp..."
OGCORE_BRANCH=$(jq -r '.release' /opt/opengnsys/ogDhcp/installer/config.json)
git_checkout_release "$OGDHCP_REPO" "$component_dir/repo" "$OGCORE_BRANCH"
cp $CONFIGS_DIR/$config_file $component_dir/repo/installer/config_ogdhcp.json
cd $component_dir/repo/installer || exit
chmod 755 ogdhcp_installer.sh
./ogdhcp_installer.sh
cd - || exit
echo - ogDhcp >> /etc/issue
;;
ogBoot)
OGCORE_BRANCH=$(jq -r '.release' /opt/opengnsys/ogBoot/installer/config.json)
echo "Instalando ogBoot..."
git_checkout_release "$OGBOOT_REPO" "$component_dir/repo" "$OGCORE_BRANCH"
cp $CONFIGS_DIR/$config_file $component_dir/repo/installer/config.json
apt install -y python3 git vim
cd $component_dir/repo/installer || exit
python3 ogboot_installer.py
cd - || exit
echo - ogBoot >> /etc/issue
;;
ogRepository)
echo "Instalando ogRepository..."
OGCORE_BRANCH=$(jq -r '.release' /opt/opengnsys/ogRepository/installer/config.json)
git_checkout_release "$OGREPOSITORY_REPO" "$component_dir/repo" "$OGCORE_BRANCH"
cp $CONFIGS_DIR/$config_file $component_dir/installer/config.json
REPO_IP=$(jq -r '.ogrepository_ip' $component_dir/installer/config.json)
CORE_IP=$(jq -r '.ogcore_server_ip' $component_dir/installer/config.json)
OGUSER=$(jq -r '.ogrepository_samba_user' $component_dir/installer/config.json)
OGPASS=$(jq -r '.ogrepository_samba_pass' $component_dir/installer/config.json)
mkdir -p $component_dir/bin
cp $CONFIGS_DIR/provision_ogrepository.sh $component_dir/bin/
chmod 755 $component_dir/bin/provision_ogrepository.sh
$component_dir/bin/provision_ogrepository.sh $REPO_IP $CORE_IP $OGUSER $OGPASS $component_dir/repo
echo - ogRepository >> /etc/issue
;;
*)
echo "Componente $component no reconocido"
;;
esac
continue
fi
done
echo ======================================== >> /etc/issue
# rm -f $PAT_FILE