From e81976e219ae274c4cd8511e86d928b232de4ecf Mon Sep 17 00:00:00 2001 From: Bobby <30593201+luciferreeves@users.noreply.github.com> Date: Fri, 27 Feb 2026 14:06:51 +0530 Subject: Enhance deployment script: add NEKOWEB_SITE validation, improve root cleaning, and adjust file upload paths --- scripts/deploy.sh | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 58ac748..8269baf 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -26,10 +26,16 @@ if [ -z "${NEKOWEB_API_KEY:-}" ]; then error "NEKOWEB_API_KEY is not set in .env" fi +if [ -z "${NEKOWEB_SITE:-}" ]; then + error "NEKOWEB_SITE is not set in .env" +fi + if [ ! -d "$GARDEN_DIR" ]; then error "garden/ directory not found at $GARDEN_DIR" fi +SITE_FOLDER="/${NEKOWEB_SITE}.nekoweb.org" + api_post() { local endpoint="$1" shift @@ -39,6 +45,13 @@ api_post() { "$@" } +api_get() { + local endpoint="$1" + curl -s \ + -H "Authorization: $NEKOWEB_API_KEY" \ + "$API_BASE$endpoint" +} + check_response() { local response="$1" local description="$2" @@ -55,6 +68,13 @@ check_response() { fi } +delete_remote_path() { + local path="$1" + local response + response=$(api_post "/files/delete" -d "pathname=$path") + check_response "$response" "Deleted $path" +} + create_remote_folder() { local path="$1" local response @@ -79,9 +99,28 @@ upload_file() { } log "Starting deployment to nekoweb..." +log "Site: ${NEKOWEB_SITE}.nekoweb.org" log "Source: $GARDEN_DIR" echo "" +log "Cleaning root..." +root_items=$(api_get "/files/readfolder?pathname=/") +root_count=$(echo "$root_items" | jq 'length') + +if [ "$root_count" -gt 0 ]; then + for i in $(seq 0 $((root_count - 1))); do + name=$(echo "$root_items" | jq -r ".[$i].name") + delete_remote_path "/$name" + done +else + log "Root is already empty" +fi +echo "" + +log "Creating site folder: $SITE_FOLDER" +create_remote_folder "$SITE_FOLDER" +echo "" + declare -a dirs_to_create=() declare -a files_to_upload=() @@ -93,11 +132,11 @@ while IFS= read -r -d '' file; do fi if [ -d "$file" ]; then - dirs_to_create+=("/$rel_path") + dirs_to_create+=("$SITE_FOLDER/$rel_path") elif [ -f "$file" ]; then - remote_dir="/$(dirname "$rel_path")" - if [ "$remote_dir" = "/." ]; then - remote_dir="/" + remote_dir="$SITE_FOLDER/$(dirname "$rel_path")" + if [ "$remote_dir" = "$SITE_FOLDER/." ]; then + remote_dir="$SITE_FOLDER" fi files_to_upload+=("$file|$remote_dir") fi -- cgit v1.2.3