|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: MickLesk (CanbiZ) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://plant-it.org/ |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt-get install -y \ |
| 18 | + curl \ |
| 19 | + mc \ |
| 20 | + sudo \ |
| 21 | + gnupg2 \ |
| 22 | + mariadb-server \ |
| 23 | + redis \ |
| 24 | + nginx |
| 25 | +msg_ok "Installed Dependencies" |
| 26 | + |
| 27 | +msg_info "Setting up Adoptium Repository" |
| 28 | +mkdir -p /etc/apt/keyrings |
| 29 | +wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor >/etc/apt/trusted.gpg.d/adoptium.gpg |
| 30 | +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 |
| 31 | +$STD apt-get update |
| 32 | +msg_ok "Set up Adoptium Repository" |
| 33 | + |
| 34 | +msg_info "Installing Temurin JDK 21 (LTS)" |
| 35 | +$STD apt-get install -y temurin-21-jdk |
| 36 | +msg_ok "Setup Temurin JDK 21 (LTS)" |
| 37 | + |
| 38 | +msg_info "Setting up MariaDB" |
| 39 | +JWT_SECRET=$(openssl rand -base64 24 | tr -d '/+=') |
| 40 | +DB_NAME=plantit |
| 41 | +DB_USER=plantit_usr |
| 42 | +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) |
| 43 | +$STD mysql -u root -e "CREATE DATABASE $DB_NAME;" |
| 44 | +$STD mysql -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password AS PASSWORD('$DB_PASS');" |
| 45 | +$STD mysql -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" |
| 46 | +{ |
| 47 | + echo "Plant-it Credentials" |
| 48 | + echo "Plant-it Database User: $DB_USER" |
| 49 | + echo "Plant-it Database Password: $DB_PASS" |
| 50 | + echo "Plant-it Database Name: $DB_NAME" |
| 51 | +} >>~/plant-it.creds |
| 52 | +msg_ok "Set up MariaDB" |
| 53 | + |
| 54 | +msg_info "Setup Plant-it" |
| 55 | +RELEASE=$(curl -s https://api.github.com/repos/MDeLuise/plant-it/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') |
| 56 | +wget -q https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/server.jar |
| 57 | +mkdir -p /opt/plant-it/{backend,frontend} |
| 58 | +mkdir -p /opt/plant-it-data |
| 59 | +mv -f server.jar /opt/plant-it/backend/server.jar |
| 60 | + |
| 61 | +cat <<EOF >/opt/plant-it/backend/server.env |
| 62 | +MYSQL_HOST=localhost |
| 63 | +MYSQL_PORT=3306 |
| 64 | +MYSQL_USERNAME=$DB_USER |
| 65 | +MYSQL_PSW=$DB_PASS |
| 66 | +MYSQL_DATABASE=$DB_NAME |
| 67 | +MYSQL_ROOT_PASSWORD=$DB_PASS |
| 68 | +
|
| 69 | +JWT_SECRET=$JWT_SECRET |
| 70 | +JWT_EXP=1 |
| 71 | +
|
| 72 | +USERS_LIMIT=-1 |
| 73 | +UPLOAD_DIR=/opt/plant-it-data |
| 74 | +API_PORT=8080 |
| 75 | +FLORACODEX_KEY= |
| 76 | +LOG_LEVEL=DEBUG |
| 77 | +ALLOWED_ORIGINS=* |
| 78 | +
|
| 79 | +CACHE_TYPE=redis |
| 80 | +CACHE_TTL=86400 |
| 81 | +CACHE_HOST=localhost |
| 82 | +CACHE_PORT=6379 |
| 83 | +EOF |
| 84 | + |
| 85 | +cd /opt/plant-it/frontend |
| 86 | +wget -q https://github.com/MDeLuise/plant-it/releases/download/${RELEASE}/client.tar.gz |
| 87 | +tar -xzf client.tar.gz |
| 88 | +echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" |
| 89 | +msg_ok "Setup Plant-it" |
| 90 | + |
| 91 | +msg_info "Creating Service" |
| 92 | +cat <<EOF >/etc/systemd/system/plant-it.service |
| 93 | +[Unit] |
| 94 | +Description=Plant-it Backend Service |
| 95 | +After=syslog.target network.target |
| 96 | +
|
| 97 | +[Service] |
| 98 | +Type=simple |
| 99 | +WorkingDirectory=/opt/plant-it/backend |
| 100 | +EnvironmentFile=/opt/plant-it/backend/server.env |
| 101 | +ExecStart=/usr/bin/java -jar -Xmx2g server.jar |
| 102 | +TimeoutStopSec=20 |
| 103 | +KillMode=process |
| 104 | +Restart=on-failure |
| 105 | +
|
| 106 | +[Install] |
| 107 | +WantedBy=multi-user.target |
| 108 | +EOF |
| 109 | +systemctl enable --now -q plant-it |
| 110 | + |
| 111 | +cat <<EOF >/etc/nginx/nginx.conf |
| 112 | +events { |
| 113 | + worker_connections 1024; |
| 114 | +} |
| 115 | +
|
| 116 | +http { |
| 117 | + server { |
| 118 | + listen 3000; |
| 119 | + server_name localhost; |
| 120 | +
|
| 121 | + root /opt/plant-it/frontend; |
| 122 | + index index.html; |
| 123 | +
|
| 124 | + location / { |
| 125 | + try_files \$uri \$uri/ /index.html; |
| 126 | + } |
| 127 | +
|
| 128 | + error_page 404 /404.html; |
| 129 | + location = /404.html { |
| 130 | + internal; |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | +EOF |
| 135 | +systemctl restart nginx |
| 136 | +msg_ok "Created Service" |
| 137 | + |
| 138 | +motd_ssh |
| 139 | +customize |
| 140 | + |
| 141 | +msg_info "Cleaning up" |
| 142 | +rm -rf /opt/plant-it/frontend/client.tar.gz |
| 143 | +$STD apt-get -y autoremove |
| 144 | +$STD apt-get -y autoclean |
| 145 | +msg_ok "Cleaned" |
0 commit comments