From a7f089e15990cf4d4c91fa6b1b11e923b571a6b9 Mon Sep 17 00:00:00 2001 From: Leons Aleksandrovs <58330666+Skrazzo@users.noreply.github.com> Date: Fri, 14 Nov 2025 22:57:27 +0200 Subject: [PATCH] Refactor script building / add to gitignore / 2 new scripts --- scripts/local-remote.sh | 13 +++++ scripts/remote-local.sh | 12 ++++ scripts/sftp-watch.sh | 5 ++ .../upload-core-build.sh | 4 +- .../watch-core-build.sh | 2 +- sync-project.sh | 56 ++++++++----------- 6 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 scripts/local-remote.sh create mode 100644 scripts/remote-local.sh create mode 100644 scripts/sftp-watch.sh rename upload-core-build.sh => scripts/upload-core-build.sh (86%) rename watch-core-build.sh => scripts/watch-core-build.sh (96%) diff --git a/scripts/local-remote.sh b/scripts/local-remote.sh new file mode 100644 index 0000000..600043f --- /dev/null +++ b/scripts/local-remote.sh @@ -0,0 +1,13 @@ +sshpass -p "${SERVER_PASSWORD}" \ + rsync -avzu --delete \ + --exclude .git \ + --exclude .vscode \ + --exclude .DS_Store \ + --exclude node_modules \ + --exclude vendor \ + --exclude storage \ + --exclude uploads \ + --exclude temp \ + --exclude cache \ + --exclude sitepress-multilingual-cms \ + -e ssh . "${SERVER_USER}@${SERVER_HOST}:${SERVER_PATH}" diff --git a/scripts/remote-local.sh b/scripts/remote-local.sh new file mode 100644 index 0000000..5767820 --- /dev/null +++ b/scripts/remote-local.sh @@ -0,0 +1,12 @@ +sshpass -p "${SERVER_PASSWORD}" \ + rsync -avzu \ + --exclude .vscode \ + --exclude .DS_Store \ + --exclude node_modules \ + --exclude vendor \ + --exclude storage \ + --exclude uploads \ + --exclude temp \ + --exclude cache \ + --exclude sitepress-multilingual-cms \ + -e ssh "${SERVER_USER}@${SERVER_HOST}:${SERVER_PATH}" . # --exclude .git \ diff --git a/scripts/sftp-watch.sh b/scripts/sftp-watch.sh new file mode 100644 index 0000000..126a8fa --- /dev/null +++ b/scripts/sftp-watch.sh @@ -0,0 +1,5 @@ + +echo "Syncing remote->local..." +sh remote-local.sh + +watchexec --debounce 500ms -w . "sh local-remote.sh" diff --git a/upload-core-build.sh b/scripts/upload-core-build.sh similarity index 86% rename from upload-core-build.sh rename to scripts/upload-core-build.sh index 70bbafd..27656e9 100644 --- a/upload-core-build.sh +++ b/scripts/upload-core-build.sh @@ -18,11 +18,11 @@ echo "Syncing public folder..." sshpass -p "$SERVER_PASSWORD" rsync -avz --progress \ --exclude 'storage' \ --exclude '.htaccess' \ - "$LOCAL_PUBLIC/" "$SERVER_USER@$SERVER_HOST:$SERVER_PATH/" + "$LOCAL_PUBLIC/" "$SERVER_USER@$SERVER_HOST:$SERVER_PATHpublic/" # Upload mix-manifest.json specifically (if not already synced) echo "Uploading mix-manifest.json..." sshpass -p "$SERVER_PASSWORD" scp "$LOCAL_MANIFEST" \ "$SERVER_USER@$SERVER_HOST:$SERVER_PATH/mix-manifest.json" -echo "Deployment complete!" \ No newline at end of file +echo "Deployment complete!" diff --git a/watch-core-build.sh b/scripts/watch-core-build.sh similarity index 96% rename from watch-core-build.sh rename to scripts/watch-core-build.sh index 433674f..2651ab0 100644 --- a/watch-core-build.sh +++ b/scripts/watch-core-build.sh @@ -40,7 +40,7 @@ upload_changes() { sshpass -p "$SERVER_PASSWORD" rsync -avz --progress \ --exclude 'storage' \ --exclude '.htaccess' \ - "$LOCAL_PUBLIC/" "$SERVER_USER@$SERVER_HOST:$SERVER_PATH/" + "$LOCAL_PUBLIC/" "$SERVER_USER@$SERVER_HOST:$SERVER_PATHpublic/" # Upload mix-manifest.json specifically echo "Uploading mix-manifest.json..." diff --git a/sync-project.sh b/sync-project.sh index 13e760b..fc31944 100755 --- a/sync-project.sh +++ b/sync-project.sh @@ -120,46 +120,38 @@ echo "{ echo -e "${GREEN}.vscode/sftp.json created successfully${NC}" -# Add upload core build script -# Add variables to upload core script -echo " -#!/bin/bash -set -e +# Go through scripts, add variables and add them to project folder +scripts=("upload-core-build.sh" "watch-core-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh") -# Configuration -SERVER_USER=\"${USERNAME}\" -SERVER_HOST=\"${HOST}\" -SERVER_PASSWORD=\"${SSH_PASSWORD}\" -SERVER_PATH=\"${SERVER_PROJECT_PATH}/public\" # Public folders location on server -" > upload-core-build.sh +for script in "${scripts[@]}"; do + # Add variables to script + echo " + #!/bin/bash + set -e -# Append the rest of the upload core build script -cat "${SCRIPT_DIR}/upload-core-build.sh" >> upload-core-build.sh + # Configuration + SERVER_USER=\"${USERNAME}\" + SERVER_HOST=\"${HOST}\" + SERVER_PASSWORD=\"${SSH_PASSWORD}\" + SERVER_PATH=\"${SERVER_PROJECT_PATH}/\" + " > "${script}" -echo -e "${GREEN}upload-core-build.sh created successfully${NC}" + # Append the rest of the upload core build script + cat "${SCRIPT_DIR}/scripts/${script}" >> "${script}" + echo "${script} created successfully" -# Add watch core build script -# Add variables to upload core script -echo " -#!/bin/bash -set -e - -# Configuration -SERVER_USER=\"${USERNAME}\" -SERVER_HOST=\"${HOST}\" -SERVER_PASSWORD=\"${SSH_PASSWORD}\" -SERVER_PATH=\"${SERVER_PROJECT_PATH}/public\" # Public folders location on server -" > watch-core-build.sh - -# Append the rest of the watch core build script -cat "${SCRIPT_DIR}/watch-core-build.sh" >> watch-core-build.sh - -echo -e "${GREEN}watch-core-build.sh created successfully${NC}" + # Add script to .gitignore + echo "${script}" >> .gitignore + echo -e "${BLUE}Added ${script} to .gitignore${NC}" +done # Upload lazygit to server echo "Uploading lazygit to server..." cp "${SCRIPT_DIR}/lazygit" . sshpass -p "${SSH_PASSWORD}" scp "${SCRIPT_DIR}/lazygit" ${SERVER_HOST}:${SERVER_PROJECT_PATH} +echo -e "${GREEN}lazygit uploaded successfully${NC}" -echo -e "${GREEN}lazygit uploaded successfully${NC}" \ No newline at end of file +# Add lazygit to .gitignore +echo "lazygit" >> .gitignore +echo -e "${BLUE}Added lazygit to .gitignore${NC}"