add --sftp-only flag support
This commit is contained in:
@@ -2,18 +2,6 @@
|
|||||||
|
|
||||||
# This script is used to sync a project from
|
# This script is used to sync a project from
|
||||||
# a remote server to a local machine.
|
# a remote server to a local machine.
|
||||||
#
|
|
||||||
# Considerations:
|
|
||||||
# 1. The server must have an SSH key set up for password-less login.
|
|
||||||
# 2. The server must have the project files in a specific folder. (~/public_leo, etc..)
|
|
||||||
#
|
|
||||||
# How it works:
|
|
||||||
# 1. created an archive on the server
|
|
||||||
# 2. copy the archive to the local machine
|
|
||||||
# 3. extract the archive locally
|
|
||||||
# 4. delete the local archive
|
|
||||||
# 5. delete the server archive
|
|
||||||
# 6. create .vscode/sftp.json file
|
|
||||||
|
|
||||||
# Colors for output
|
# Colors for output
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
@@ -25,7 +13,15 @@ NC='\033[0m' # No Color
|
|||||||
# Get current script real directory (follow symlinks)
|
# Get current script real directory (follow symlinks)
|
||||||
SCRIPT_PATH="$(realpath "$0")"
|
SCRIPT_PATH="$(realpath "$0")"
|
||||||
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
|
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
|
||||||
ARCHIVE_NAME="leo.tar.gz"
|
ARCHIVE_NAME="sync.tar.gz"
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
SFTP_ONLY=false
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [ "$arg" = "--sftp-only" ]; then
|
||||||
|
SFTP_ONLY=true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Function to add entry to .gitignore if not already present
|
# Function to add entry to .gitignore if not already present
|
||||||
add_to_gitignore() {
|
add_to_gitignore() {
|
||||||
@@ -155,7 +151,11 @@ echo "{
|
|||||||
echo -e "${GREEN}.vscode/sftp.json created successfully${NC}"
|
echo -e "${GREEN}.vscode/sftp.json created successfully${NC}"
|
||||||
|
|
||||||
# Go through scripts, add variables and add them to project folder
|
# Go through scripts, add variables and add them to project folder
|
||||||
scripts=("watch-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh")
|
if [ "$SFTP_ONLY" = true ]; then
|
||||||
|
scripts=("local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh")
|
||||||
|
else
|
||||||
|
scripts=("watch-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh")
|
||||||
|
fi
|
||||||
|
|
||||||
for script in "${scripts[@]}"; do
|
for script in "${scripts[@]}"; do
|
||||||
# Add variables to script
|
# Add variables to script
|
||||||
@@ -174,16 +174,20 @@ for script in "${scripts[@]}"; do
|
|||||||
cat "${SCRIPT_DIR}/scripts/${script}" >> "${script}"
|
cat "${SCRIPT_DIR}/scripts/${script}" >> "${script}"
|
||||||
echo "${script} created successfully"
|
echo "${script} created successfully"
|
||||||
|
|
||||||
# Add script to .gitignore
|
# Skip .gitignore updates when --sftp-only flag is present
|
||||||
add_to_gitignore "${script}"
|
if [ "$SFTP_ONLY" = false ]; then
|
||||||
|
add_to_gitignore "${script}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Upload lazygit to server
|
# Upload lazygit to server (skip when --sftp-only flag is present)
|
||||||
echo "Uploading lazygit to server..."
|
if [ "$SFTP_ONLY" = false ]; then
|
||||||
|
echo "Uploading lazygit to server..."
|
||||||
|
|
||||||
cp "${SCRIPT_DIR}/lazygit" .
|
cp "${SCRIPT_DIR}/lazygit" .
|
||||||
sshpass -p "${SSH_PASSWORD}" scp "${SCRIPT_DIR}/lazygit" ${SERVER_HOST}:${SERVER_PROJECT_PATH}
|
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}"
|
||||||
|
|
||||||
# Add lazygit to .gitignore
|
# Add lazygit to .gitignore
|
||||||
add_to_gitignore "lazygit"
|
add_to_gitignore "lazygit"
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user