From 377da58b04e385f384a53c03efa5f3f11a32660a Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:31:34 +0100 Subject: [PATCH] First installer version --- installer/files/ctorrent.sources | 6 +++ installer/files/ogrepo-api.service | 12 +++++ installer/installer.sh | 70 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 installer/files/ctorrent.sources create mode 100644 installer/files/ogrepo-api.service create mode 100644 installer/installer.sh diff --git a/installer/files/ctorrent.sources b/installer/files/ctorrent.sources new file mode 100644 index 0000000..dc5dea0 --- /dev/null +++ b/installer/files/ctorrent.sources @@ -0,0 +1,6 @@ +Types: deb +URIs: http://ftp.de.debian.org/debian +Suites: buster +Components: main +Signed-By: /usr/share/keyrings/debian-archive-buster-stable.gpg + diff --git a/installer/files/ogrepo-api.service b/installer/files/ogrepo-api.service new file mode 100644 index 0000000..f127ffa --- /dev/null +++ b/installer/files/ogrepo-api.service @@ -0,0 +1,12 @@ +[Unit] +Description=Gunicorn instance to serve repo_api +After=network.target + +[Service] +User=root +Group=root +WorkingDirectory=/opt/opengnsys/ogrepository/api +ExecStart=/usr/bin/gunicorn -w 4 -b 0.0.0.0:8006 repo_api:app + +[Install] +WantedBy=multi-user.target diff --git a/installer/installer.sh b/installer/installer.sh new file mode 100644 index 0000000..19a9b55 --- /dev/null +++ b/installer/installer.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -e + +GIT_BRANCH=$1 +GIT_REPO=https://ognproject.evlt.uma.es/gitea/opengnsys/ogrepository.git +INSTALL_DIR=/opt/opengnsys/ogrepository +DEBIAN_FRONTEND=noninteractive +export DEBIAN_FRONTEND + +clone_repository() { + local BRANCH=$1 + git clone -b "$BRANCH" $GIT_REPO /tmp/ogrepository + chown -R ogrepository:ogrepository /tmp/ogrepository +} + +check_root() { + if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 + fi +} + +add_user_ogrepository() { + useradd -r -s /bin/bash ogrepository +} + +create_directories() { + mkdir -p $INSTALL_DIR + mkdir -p $INSTALL_DIR/images $INSTALL_DIR/images_trash/ $INSTALL_DIR/bin/ $INSTALL_DIR/etc/ $INSTALL_DIR/log/ + chown -R ogrepository:ogrepository $INSTALL_DIR +} + +install_dependencies() { + apt update -y + apt install -y git python3 python3-pip python3-flask python3-paramiko python3-psutil python3-flasgger debian-archive-keyring samba gunicorn +} + +install_ext_repo() { + cp installer/files/ctorrent.sources /etc/apt/sources.list.d/ctorrent.sources + apt update -y +} + +install_external_packages() { + apt install -y bittorrent bittornado ctorrent +} + +install_ogrepo-api_service() { + cp -r installer/files/ogrepo-api.service /etc/systemd/system/ogrepo-api.service + systemctl enable --now ogrepo-api + systemctl start ogrepository +} + +install_files() { + install bin/* /opt/opengnsys/bin/ + install bin/clients/* /opt/opengnsys/bin/clients + install etc/* /opt/opengnsys/etc/ + install api/* /opt/opengnsys/api +} + +## Main program +check_root +install_dependencies +add_user_ogrepository +git_clone_repository "$GIT_BRANCH" +create_directories +install_ogrepo-api_service + + +