From 377da58b04e385f384a53c03efa5f3f11a32660a Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:31:34 +0100 Subject: [PATCH 01/17] 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 + + + From 853ade27769b3f8d780e53343473b67998b2af03 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:40:41 +0100 Subject: [PATCH 02/17] Fix user in service --- installer/files/ogrepo-api.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/files/ogrepo-api.service b/installer/files/ogrepo-api.service index f127ffa..136de86 100644 --- a/installer/files/ogrepo-api.service +++ b/installer/files/ogrepo-api.service @@ -3,8 +3,8 @@ Description=Gunicorn instance to serve repo_api After=network.target [Service] -User=root -Group=root +User=ogrepository +Group=ogrepository WorkingDirectory=/opt/opengnsys/ogrepository/api ExecStart=/usr/bin/gunicorn -w 4 -b 0.0.0.0:8006 repo_api:app From 56e7418c716b7324227e65d20b7692e546453527 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:45:48 +0100 Subject: [PATCH 03/17] Fix service --- installer/installer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/installer.sh b/installer/installer.sh index 19a9b55..595ac69 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -62,7 +62,7 @@ install_files() { check_root install_dependencies add_user_ogrepository -git_clone_repository "$GIT_BRANCH" +clone_repository "$GIT_BRANCH" create_directories install_ogrepo-api_service From 18d7bd4ddfae9c12a977e5587d873587801b5019 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:48:42 +0100 Subject: [PATCH 04/17] Enable ssl no verify for GIT --- installer/installer.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/installer/installer.sh b/installer/installer.sh index 595ac69..c609cda 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -4,9 +4,11 @@ set -e GIT_BRANCH=$1 GIT_REPO=https://ognproject.evlt.uma.es/gitea/opengnsys/ogrepository.git +GIT_SSL_NO_VERIFY=true INSTALL_DIR=/opt/opengnsys/ogrepository DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND +export GIT_SSL_NO_VERIFY clone_repository() { local BRANCH=$1 From 2e78e3d0124c997674a29a902ae84913a3f91e07 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:51:50 +0100 Subject: [PATCH 05/17] Fixes download dir --- installer/installer.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index c609cda..53c462e 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -6,14 +6,15 @@ GIT_BRANCH=$1 GIT_REPO=https://ognproject.evlt.uma.es/gitea/opengnsys/ogrepository.git GIT_SSL_NO_VERIFY=true INSTALL_DIR=/opt/opengnsys/ogrepository +DOWNLOAD_DIR=/tmp/ogrepository DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND export GIT_SSL_NO_VERIFY clone_repository() { local BRANCH=$1 - git clone -b "$BRANCH" $GIT_REPO /tmp/ogrepository - chown -R ogrepository:ogrepository /tmp/ogrepository + git clone -b "$BRANCH" $GIT_REPO $DOWNLOAD_DIR + chown -R ogrepository:ogrepository $DOWNLOAD_DIR } check_root() { @@ -48,12 +49,14 @@ install_external_packages() { } install_ogrepo-api_service() { + cd $DOWNLOAD_DIR cp -r installer/files/ogrepo-api.service /etc/systemd/system/ogrepo-api.service systemctl enable --now ogrepo-api systemctl start ogrepository } install_files() { + cd $DOWNLOAD_DIR install bin/* /opt/opengnsys/bin/ install bin/clients/* /opt/opengnsys/bin/clients install etc/* /opt/opengnsys/etc/ From 7f6be093a792887decb752091ea672c811250222 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 09:53:13 +0100 Subject: [PATCH 06/17] Fix typo --- installer/installer.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/installer/installer.sh b/installer/installer.sh index 53c462e..9ec7546 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -13,6 +13,7 @@ export GIT_SSL_NO_VERIFY clone_repository() { local BRANCH=$1 + rm -rf $DOWNLOAD_DIR git clone -b "$BRANCH" $GIT_REPO $DOWNLOAD_DIR chown -R ogrepository:ogrepository $DOWNLOAD_DIR } From e51e935c11f9cbfe37c21593bd736231ed43e5f1 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 10:31:13 +0100 Subject: [PATCH 07/17] Fixing files --- installer/installer.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index 9ec7546..589f83e 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -31,7 +31,7 @@ add_user_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/ + mkdir -p $INSTALL_DIR/images $INSTALL_DIR/images_trash/ $INSTALL_DIR/bin/ $INSTALL_DIR/etc/ $INSTALL_DIR/log/ $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR } @@ -50,18 +50,17 @@ install_external_packages() { } install_ogrepo-api_service() { - cd $DOWNLOAD_DIR - cp -r installer/files/ogrepo-api.service /etc/systemd/system/ogrepo-api.service + cp -r $DOWNLOAD_DIR/installer/files/ogrepo-api.service /etc/systemd/system/ogrepo-api.service systemctl enable --now ogrepo-api systemctl start ogrepository } install_files() { - cd $DOWNLOAD_DIR - install bin/* /opt/opengnsys/bin/ - install bin/clients/* /opt/opengnsys/bin/clients - install etc/* /opt/opengnsys/etc/ - install api/* /opt/opengnsys/api + install $DOWNLOAD_DIR/bin/* $INSTALL_DIR/bin/ + install $DOWNLOAD_DIR/bin/clients/* $INSTALL_DIR/bin/clients + install $DOWNLOAD_DIR/etc/* $INSTALL_DIR/etc/ + install $DOWNLOAD_DIR/api/* $INSTALL_DIR/api + chown -R ogrepository:ogrepository $INSTALL_DIR } ## Main program @@ -70,6 +69,7 @@ install_dependencies add_user_ogrepository clone_repository "$GIT_BRANCH" create_directories +install_files install_ogrepo-api_service From 212b4e9eac1392584e82112daa34aad2958d1618 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 10:41:28 +0100 Subject: [PATCH 08/17] Changing install dirs --- installer/installer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index 589f83e..2ae5666 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -31,7 +31,7 @@ add_user_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/ $INSTALL_DIR/api/ + mkdir -p $INSTALL_DIR/images $INSTALL_DIR/images_trash/ $INSTALL_DIR/bin/clients $INSTALL_DIR/etc/ $INSTALL_DIR/log/ $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR } @@ -57,9 +57,9 @@ install_ogrepo-api_service() { install_files() { install $DOWNLOAD_DIR/bin/* $INSTALL_DIR/bin/ - install $DOWNLOAD_DIR/bin/clients/* $INSTALL_DIR/bin/clients + install $DOWNLOAD_DIR/bin/clients/* $INSTALL_DIR/bin/clients/ install $DOWNLOAD_DIR/etc/* $INSTALL_DIR/etc/ - install $DOWNLOAD_DIR/api/* $INSTALL_DIR/api + install $DOWNLOAD_DIR/api/* $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR } From d8a428f9a80b983731fcd6afde3eefdcd3145d6d Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 10:51:46 +0100 Subject: [PATCH 09/17] Change install for pr --- installer/installer.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index 2ae5666..434f834 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -31,7 +31,7 @@ add_user_ogrepository() { create_directories() { mkdir -p $INSTALL_DIR - mkdir -p $INSTALL_DIR/images $INSTALL_DIR/images_trash/ $INSTALL_DIR/bin/clients $INSTALL_DIR/etc/ $INSTALL_DIR/log/ $INSTALL_DIR/api/ + mkdir -p $INSTALL_DIR/images $INSTALL_DIR/images_trash/ $INSTALL_DIR/bin/ $INSTALL_DIR/etc/ $INSTALL_DIR/log/ $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR } @@ -56,10 +56,9 @@ install_ogrepo-api_service() { } install_files() { - install $DOWNLOAD_DIR/bin/* $INSTALL_DIR/bin/ - install $DOWNLOAD_DIR/bin/clients/* $INSTALL_DIR/bin/clients/ - install $DOWNLOAD_DIR/etc/* $INSTALL_DIR/etc/ - install $DOWNLOAD_DIR/api/* $INSTALL_DIR/api/ + cp -pr $DOWNLOAD_DIR/bin/* $INSTALL_DIR/bin/ + cp -pr $DOWNLOAD_DIR/etc/* $INSTALL_DIR/etc/ + cp -pr $DOWNLOAD_DIR/api/* $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR } From fe9e38bc0e8781d1ea05dd681cd01958b6065ea3 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 10:57:12 +0100 Subject: [PATCH 10/17] Remove wrong line --- installer/installer.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/installer/installer.sh b/installer/installer.sh index 434f834..d356cf4 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -52,7 +52,6 @@ install_external_packages() { install_ogrepo-api_service() { cp -r $DOWNLOAD_DIR/installer/files/ogrepo-api.service /etc/systemd/system/ogrepo-api.service systemctl enable --now ogrepo-api - systemctl start ogrepository } install_files() { From c93e6493096c0d2a76dede2b52f5b4b719a6c923 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 11:07:17 +0100 Subject: [PATCH 11/17] Configure sudo --- installer/installer.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/installer/installer.sh b/installer/installer.sh index d356cf4..282ddc9 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -27,6 +27,7 @@ check_root() { add_user_ogrepository() { useradd -r -s /bin/bash ogrepository + echo 'ogrepository ALL=(ALL) NOPASSWD: /usr/bin/python3' > ogrepository } create_directories() { From 69509d6fa170967509ae8402f685734611075d1a Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 11:17:36 +0100 Subject: [PATCH 12/17] Install external packages --- installer/installer.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index 282ddc9..f7716f9 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -25,9 +25,17 @@ check_root() { fi } +install_uftp() { + apt install uftp -y +} + +install_updcast () { + apt install $DOWNLOAD_DIR/packets/udpcast_20230924_amd64.deb +} + add_user_ogrepository() { - useradd -r -s /bin/bash ogrepository - echo 'ogrepository ALL=(ALL) NOPASSWD: /usr/bin/python3' > ogrepository + useradd -r -s /bin/bash ogrepository + echo 'ogrepository ALL=(ALL) NOPASSWD: ALL' > ogrepository } create_directories() { @@ -65,6 +73,9 @@ install_files() { ## Main program check_root install_dependencies +install_external_packages +install_uftp +install_updcast add_user_ogrepository clone_repository "$GIT_BRANCH" create_directories From dffe6c1744c6b144b31fcbbe35a34629f916048b Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 11:30:40 +0100 Subject: [PATCH 13/17] Fix route to install deb keyring sources --- installer/installer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/installer.sh b/installer/installer.sh index f7716f9..5948d9e 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -50,7 +50,7 @@ install_dependencies() { } install_ext_repo() { - cp installer/files/ctorrent.sources /etc/apt/sources.list.d/ctorrent.sources + cp $DOWNLOAD_DIR/installer/files/ctorrent.sources /etc/apt/sources.list.d/ctorrent.sources apt update -y } From 094ce0ecc1cf19826c99745cb1095ff34242ea20 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 11:47:41 +0100 Subject: [PATCH 14/17] Fix user creation --- installer/installer.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index 5948d9e..7090ce0 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -34,8 +34,15 @@ install_updcast () { } add_user_ogrepository() { - useradd -r -s /bin/bash ogrepository - echo 'ogrepository ALL=(ALL) NOPASSWD: ALL' > ogrepository + if ! id "ogrepository" &>/dev/null; then + echo "User ogrepository does not exist, creating it" + useradd -r -s /bin/bash ogrepository + fi + if [ ! -f /etc/sudoers.d/ogrepository ]; then + echo "User ogrepository does not have sudo permissions, adding it" + echo 'ogrepository ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/ogrepository + fi + } create_directories() { @@ -72,6 +79,7 @@ install_files() { ## Main program check_root +install_ext_repo install_dependencies install_external_packages install_uftp From c278105f55273c7e660527e89a27d33e10481764 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 11:58:31 +0100 Subject: [PATCH 15/17] Fixing command order to proper installation --- installer/installer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index 7090ce0..55023b2 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -79,13 +79,13 @@ install_files() { ## Main program check_root -install_ext_repo install_dependencies +add_user_ogrepository +clone_repository "$GIT_BRANCH" +install_ext_repo install_external_packages install_uftp install_updcast -add_user_ogrepository -clone_repository "$GIT_BRANCH" create_directories install_files install_ogrepo-api_service From 33ff1c2b7f008ecdf04411d274256457b49f4015 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 14:13:32 +0100 Subject: [PATCH 16/17] Configure Samba Configure REPO_IP --- installer/files/ogrepo-smb.conf | 8 ++++++++ installer/installer.sh | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 installer/files/ogrepo-smb.conf diff --git a/installer/files/ogrepo-smb.conf b/installer/files/ogrepo-smb.conf new file mode 100644 index 0000000..3b76b2b --- /dev/null +++ b/installer/files/ogrepo-smb.conf @@ -0,0 +1,8 @@ +[ogimages] +comment = OpenGnsys Repository +browseable = no +writeable = yes +locking = no +path = /opt/opengnsys/ogrepository/images +guest ok = no +valid users = %%OGREPOSITORY_USER%% diff --git a/installer/installer.sh b/installer/installer.sh index 55023b2..3d18c7e 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -5,6 +5,9 @@ set -e GIT_BRANCH=$1 GIT_REPO=https://ognproject.evlt.uma.es/gitea/opengnsys/ogrepository.git GIT_SSL_NO_VERIFY=true +REPO_IP=${REPO_IP:-"127.0.0.1"} +SMBUSER=${SMBUSER:-"ogrepository"} +SMBPASS=${SMBPASS:-"ogrepository"} INSTALL_DIR=/opt/opengnsys/ogrepository DOWNLOAD_DIR=/tmp/ogrepository DEBIAN_FRONTEND=noninteractive @@ -75,6 +78,17 @@ install_files() { cp -pr $DOWNLOAD_DIR/etc/* $INSTALL_DIR/etc/ cp -pr $DOWNLOAD_DIR/api/* $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR + echo IPlocal="$REPO_IP" > $INSTALL_DIR/etc/ogAdmRepo.cfg +} + +configure_samba() { + echo "include = /etc/samba/smb.conf.ogrepository" >> /etc/samba/smb.conf + cp $DOWNLOAD_DIR/installer/files/ogrepo-smb.conf /etc/samba/smb.conf.ogrepository + sed -i "s/%%OGREPOSITORY_USER%%/$SMBUSER/g" /etc/samba/smb.conf.ogrepository + systemctl restart smbd + # Create default user ogrepository + (echo $SMBPASS; echo $SMBPASS) | smbpasswd -s -a $SMBUSER + } ## Main program @@ -89,6 +103,6 @@ install_updcast create_directories install_files install_ogrepo-api_service - +configure_samba From 146ca64ad5f1da282eb6f9033dce04716ede3f92 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 11 Nov 2024 14:23:37 +0100 Subject: [PATCH 17/17] Set proper permissions to ogrepository user --- installer/installer.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/installer/installer.sh b/installer/installer.sh index 3d18c7e..0015672 100644 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -79,6 +79,7 @@ install_files() { cp -pr $DOWNLOAD_DIR/api/* $INSTALL_DIR/api/ chown -R ogrepository:ogrepository $INSTALL_DIR echo IPlocal="$REPO_IP" > $INSTALL_DIR/etc/ogAdmRepo.cfg + sudo chown ogrepository:ogrepository $INSTALL_DIR/etc/ogAdmRepo.cfg } configure_samba() {