From bae22ebf82829e9b7f0e4b67cae4e394b6700021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Fri, 22 Aug 2025 14:09:00 +0200 Subject: [PATCH] Refactor (#7094) --- ct/plant-it.sh | 55 ++++++++++++++++--------------------- install/plant-it-install.sh | 30 ++++---------------- 2 files changed, 30 insertions(+), 55 deletions(-) diff --git a/ct/plant-it.sh b/ct/plant-it.sh index 54dee84c4..4dc90d1a4 100644 --- a/ct/plant-it.sh +++ b/ct/plant-it.sh @@ -20,38 +20,31 @@ color catch_errors function update_script() { - header_info - check_container_storage - check_container_resources - - if [[ ! -d /opt/plant-it ]]; then - msg_error "No ${APP} Installation Found!" - exit - fi - - RELEASE=$(curl -fsSL https://api.github.com/repos/MDeLuise/plant-it/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') - if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then - msg_info "Stopping $APP" - systemctl stop plant-it - msg_ok "Stopped $APP" - - msg_info "Updating $APP to v${RELEASE}" - curl -fsSL "https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/server.jar" -o "/opt/plant-it/server.jar" - cd /opt/plant-it/frontend - curl -fsSL "https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/client.tar.gz" -o $(basename "https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/client.tar.gz") - tar -xzf client.tar.gz - rm -f client.tar.gz - echo "${RELEASE}" >/opt/${APP}_version.txt - msg_ok "Updated $APP to v${RELEASE}" - - msg_info "Starting $APP" - systemctl start plant-it - msg_ok "Started $APP" - msg_ok "Update Successful" - else - msg_ok "No update required. ${APP} is already at v${RELEASE}" - fi + header_info + check_container_storage + check_container_resources + if [[ ! -d /opt/plant-it ]]; then + msg_error "No ${APP} Installation Found!" exit + fi + + RELEASE=$(curl -fsSL https://api.github.com/repos/MDeLuise/plant-it/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') + if [[ "${RELEASE}" != "$(cat ~/.plant-it 2>/dev/null)" ]] || [[ ! -f ~/.plant-it ]]; then + msg_info "Stopping $APP" + systemctl stop plant-it + msg_ok "Stopped $APP" + + USE_ORIGINAL_FILENAME="true" fetch_and_deploy_gh_release "plant-it" "MDeLuise/plant-it" "singlefile" "latest" "/opt/plant-it/backend" "server.jar" + fetch_and_deploy_gh_release "plant-it-front" "MDeLuise/plant-it" "prebuild" "latest" "/opt/plant-it/frontend" "client.tar.gz" + + msg_info "Starting $APP" + systemctl start plant-it + msg_ok "Started $APP" + msg_ok "Update Successful" + else + msg_ok "No update required. ${APP} is already at v${RELEASE}" + fi + exit } start diff --git a/install/plant-it-install.sh b/install/plant-it-install.sh index 73ebf1440..0b11d4c1d 100644 --- a/install/plant-it-install.sh +++ b/install/plant-it-install.sh @@ -20,17 +20,7 @@ $STD apt-get install -y \ msg_ok "Installed Dependencies" setup_mariadb - -msg_info "Setting up Adoptium Repository" -mkdir -p /etc/apt/keyrings -curl -fsSL "https://packages.adoptium.net/artifactory/api/gpg/key/public" | gpg --dearmor >/etc/apt/trusted.gpg.d/adoptium.gpg -echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" >/etc/apt/sources.list.d/adoptium.list -$STD apt-get update -msg_ok "Set up Adoptium Repository" - -msg_info "Installing Temurin JDK 21 (LTS)" -$STD apt-get install -y temurin-21-jdk -msg_ok "Setup Temurin JDK 21 (LTS)" +JAVA_VERSION="21" setup_java msg_info "Setting up MariaDB" JWT_SECRET=$(openssl rand -base64 24 | tr -d '/+=') @@ -48,13 +38,11 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS } >>~/plant-it.creds msg_ok "Set up MariaDB" -msg_info "Setup Plant-it" -RELEASE=$(curl -fsSL https://api.github.com/repos/MDeLuise/plant-it/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -curl -fsSL "https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/server.jar" -o "server.jar" -mkdir -p /opt/plant-it/{backend,frontend} -mkdir -p /opt/plant-it-data -mv -f server.jar /opt/plant-it/backend/server.jar +USE_ORIGINAL_FILENAME="true" fetch_and_deploy_gh_release "plant-it" "MDeLuise/plant-it" "singlefile" "latest" "/opt/plant-it/backend" "server.jar" +fetch_and_deploy_gh_release "plant-it-front" "MDeLuise/plant-it" "prebuild" "latest" "/opt/plant-it/frontend" "client.tar.gz" +msg_info "Configured Plant-it" +mkdir -p /opt/plant-it-data cat </opt/plant-it/backend/server.env MYSQL_HOST=localhost MYSQL_PORT=3306 @@ -78,12 +66,7 @@ CACHE_TTL=86400 CACHE_HOST=localhost CACHE_PORT=6379 EOF - -cd /opt/plant-it/frontend -curl -fsSL "https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/client.tar.gz" -o "client.tar.gz" -tar -xzf client.tar.gz -echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" -msg_ok "Setup Plant-it" +msg_ok "Configured Plant-it" msg_info "Creating Service" cat </etc/systemd/system/plant-it.service @@ -136,7 +119,6 @@ motd_ssh customize msg_info "Cleaning up" -rm -rf /opt/plant-it/frontend/client.tar.gz $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"