169 lines
5.6 KiB
Bash
169 lines
5.6 KiB
Bash
#!/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() {
|
|
# Leer el JSON y extraer los valores con jq
|
|
user=$(jq -r '.username' /opt/opengnsys/ogCore/installer/config.json)
|
|
password=$(jq -r '.password' /opt/opengnsys/ogCore/installer/config.json)
|
|
ogcore_version=$(jq -r '.container_version' /opt/opengnsys/ogCore/installer/config.json)
|
|
|
|
# Exportar los valores como variables de entorno
|
|
export USER_NAME="$user"
|
|
export USER_PASSWORD="$password"
|
|
cd /opt/opengnsys/ogCore/repo
|
|
git checkout develop
|
|
docker compose up --build -d
|
|
docker exec ogcore-php composer install
|
|
docker exec ogcore-php php bin/console lexik:jwt:generate-keypair --overwrite
|
|
docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction
|
|
docker exec ogcore-php php bin/console doctrine:fixtures:load --no-interaction
|
|
|
|
curl -k -X 'POST' \
|
|
'https://localhost:8443/auth/login' \
|
|
-H 'accept: application/json' \
|
|
-H 'Content-Type: application/json' \
|
|
-d "{
|
|
\"username\": \"$USER_NAME\",
|
|
\"password\": \"$USER_PASSWORD\"
|
|
}"
|
|
docker compose down
|
|
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 up -d
|
|
ExecStop=/usr/bin/docker compose down
|
|
Restart=always
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl enable ogcore
|
|
|
|
}
|
|
|
|
function install_oggui_docker() {
|
|
# Leer el JSON y extraer los valores con jq
|
|
ogcore_ip=$(jq -r '.ogcore_ip' /opt/opengnsys/ogGui/installer/config.json)
|
|
oggui_version=$(jq -r '.container_version' /opt/opengnsys/ogGui/installer/config.json)
|
|
# Exportar los valores como variables de entorno
|
|
export OGCORE_IP="$ogcore_ip"
|
|
ENV_DIR=/opt/opengnsys/ogGui/etc/
|
|
ENV_FILE=$ENV_DIR/.env
|
|
mkdir -p $ENV_DIR
|
|
echo "NG_APP_BASE_API_URL=$OGCORE_IP" > $ENV_FILE
|
|
|
|
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
|
|
ExecStart=/usr/bin/docker run --name ogGui-app -p 4200:4200 -v $ENV_FILE:/app/.env -d opengnsys/oggui:$oggui_version
|
|
ExecStop=/usr/bin/docker stop angular-app
|
|
ExecStopPost=/usr/bin/docker rm -f angular-app
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl enable 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/oggui.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..."
|
|
git clone "$OGCORE_REPO" "$component_dir/repo"
|
|
echo - ogCore >> /etc/issueq
|
|
install_docker
|
|
install_ogcore_docker
|
|
;;
|
|
ogGui)
|
|
echo "Instalando ogGui..."
|
|
git clone "$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
|