diff --git a/ct/booklore.sh b/ct/booklore.sh index 3e9988257..003230c7b 100644 --- a/ct/booklore.sh +++ b/ct/booklore.sh @@ -11,7 +11,7 @@ var_cpu="${var_cpu:-3}" var_ram="${var_ram:-3072}" var_disk="${var_disk:-7}" var_os="${var_os:-debian}" -var_version="${var_version:-12}" +var_version="${var_version:-13}" var_unprivileged="${var_unprivileged:-1}" header_info "$APP" @@ -28,15 +28,29 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi - setup_mariadb + if check_for_gh_release "booklore" "booklore-app/BookLore"; then + JAVA_VERSION="21" setup_java + NODE_VERSION="22" setup_nodejs + setup_mariadb + setup_yq + msg_info "Stopping Service" systemctl stop booklore - msg_info "Stopped Service" + msg_ok "Stopped Service" - msg_info "backup old install" + if grep -qE "^BOOKLORE_(DATA_PATH|BOOKDROP_PATH|BOOKS_PATH|PORT)=" /opt/booklore_storage/.env 2>/dev/null; then + msg_info "Migrating old environment variables" + sed -i 's/^BOOKLORE_DATA_PATH=/APP_PATH_CONFIG=/g' /opt/booklore_storage/.env + sed -i 's/^BOOKLORE_BOOKDROP_PATH=/APP_BOOKDROP_FOLDER=/g' /opt/booklore_storage/.env + sed -i '/^BOOKLORE_BOOKS_PATH=/d' /opt/booklore_storage/.env + sed -i '/^BOOKLORE_PORT=/d' /opt/booklore_storage/.env + msg_ok "Migrated old environment variables" + fi + + msg_info "Backing up old installation" mv /opt/booklore /opt/booklore_bak - msg_ok "backup done" + msg_ok "Backed up old installation" fetch_and_deploy_gh_release "booklore" "booklore-app/BookLore" "tarball" @@ -46,12 +60,9 @@ function update_script() { $STD npm run build --configuration=production msg_ok "Built Frontend" - JAVA_VERSION="21" setup_java - setup_yq - msg_info "Building Backend" cd /opt/booklore/booklore-api - APP_VERSION=$(curl -fsSL https://api.github.com/repos/booklore-app/BookLore/releases/latest | yq '.tag_name' | sed 's/^v//') + APP_VERSION=$(get_latest_github_release "booklore-app/BookLore") yq eval ".app.version = \"${APP_VERSION}\"" -i src/main/resources/application.yaml $STD ./gradlew clean build --no-daemon mkdir -p /opt/booklore/dist diff --git a/frontend/public/json/booklore.json b/frontend/public/json/booklore.json index 952710f88..b65c5e0e7 100644 --- a/frontend/public/json/booklore.json +++ b/frontend/public/json/booklore.json @@ -23,7 +23,7 @@ "ram": 3072, "hdd": 7, "os": "debian", - "version": "12" + "version": "13" } } ], diff --git a/install/booklore-install.sh b/install/booklore-install.sh index 9dd0f6aaf..bb800c0a5 100644 --- a/install/booklore-install.sh +++ b/install/booklore-install.sh @@ -14,30 +14,15 @@ network_check update_os msg_info "Installing Dependencies" -$STD apt-get install -y nginx +$STD apt install -y nginx msg_ok "Installed Dependencies" -fetch_and_deploy_gh_release "booklore" "booklore-app/BookLore" "tarball" JAVA_VERSION="21" setup_java NODE_VERSION="22" setup_nodejs setup_mariadb setup_yq - -msg_info "Setting up database" -DB_NAME=booklore_db -DB_USER=booklore_user -DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) -$STD mariadb -u root -e "CREATE DATABASE $DB_NAME;" -$STD mariadb -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';" -$STD mariadb -u root -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';" -$STD mariadb -u root -e "GRANT SELECT ON \`mysql\`.\`time_zone_name\` TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" -{ - echo "BookLore Database Credentials" - echo "Database: $DB_NAME" - echo "Username: $DB_USER" - echo "Password: $DB_PASS" -} >>~/booklore.creds -msg_ok "Set up database" +MARIADB_DB_NAME="booklore_db" MARIADB_DB_USER="booklore_user" MARIADB_DB_EXTRA_GRANTS="GRANT SELECT ON \`mysql\`.\`time_zone_name\`" setup_mariadb_db +fetch_and_deploy_gh_release "booklore" "booklore-app/BookLore" "tarball" msg_info "Building Frontend" cd /opt/booklore/booklore-ui @@ -46,22 +31,22 @@ $STD npm run build --configuration=production msg_ok "Built Frontend" msg_info "Creating Environment" -mkdir -p /opt/booklore_storage{/data,/books,/bookdrop} +mkdir -p /opt/booklore_storage/{data,books,bookdrop} cat </opt/booklore_storage/.env -DATABASE_URL=jdbc:mariadb://localhost:3306/$DB_NAME -DATABASE_USERNAME=$DB_USER -DATABASE_PASSWORD=$DB_PASS -BOOKLORE_PORT=6060 +# Database Configuration +DATABASE_URL=jdbc:mariadb://localhost:3306/${MARIADB_DB_NAME} +DATABASE_USERNAME=${MARIADB_DB_USER} +DATABASE_PASSWORD=${MARIADB_DB_PASS} -BOOKLORE_DATA_PATH=/opt/booklore_storage/data -BOOKLORE_BOOKS_PATH=/opt/booklore_storage/books -BOOKLORE_BOOKDROP_PATH=/opt/booklore_storage/bookdrop +# App Configuration (Spring Boot mapping from app.* properties) +APP_PATH_CONFIG=/opt/booklore_storage/data +APP_BOOKDROP_FOLDER=/opt/booklore_storage/bookdrop EOF msg_ok "Created Environment" msg_info "Building Backend" cd /opt/booklore/booklore-api -APP_VERSION=$(curl -fsSL https://api.github.com/repos/booklore-app/BookLore/releases/latest | yq '.tag_name' | sed 's/^v//') +APP_VERSION=$(get_latest_github_release "booklore-app/BookLore") yq eval ".app.version = \"${APP_VERSION}\"" -i src/main/resources/application.yaml $STD ./gradlew clean build --no-daemon mkdir -p /opt/booklore/dist @@ -73,22 +58,24 @@ fi cp "$JAR_PATH" /opt/booklore/dist/app.jar msg_ok "Built Backend" -msg_info "Configure Nginx" +msg_info "Configuring Nginx" rm -rf /usr/share/nginx/html ln -s /opt/booklore/booklore-ui/dist/booklore/browser /usr/share/nginx/html +rm -f /etc/nginx/sites-enabled/default cp /opt/booklore/nginx.conf /etc/nginx/nginx.conf sed -i 's/listen \${BOOKLORE_PORT};/listen 6060;/' /etc/nginx/nginx.conf sed -i 's/listen \[::\]:${BOOKLORE_PORT};/listen [::]:6060;/' /etc/nginx/nginx.conf systemctl restart nginx msg_ok "Configured Nginx" -msg_info "Creating Systemd Service" +msg_info "Creating Service" cat </etc/systemd/system/booklore.service [Unit] Description=BookLore Java Service -After=network.target +After=network.target mariadb.service [Service] +Type=simple User=root WorkingDirectory=/opt/booklore/dist ExecStart=/usr/bin/java -jar /opt/booklore/dist/app.jar @@ -102,7 +89,7 @@ RestartSec=5 WantedBy=multi-user.target EOF systemctl enable -q --now booklore -msg_ok "Created BookLore Service" +msg_ok "Created Service" motd_ssh customize