Add uploads folder to tar exclusion

This commit is contained in:
2026-01-22 15:32:27 +02:00
parent 7682a1f212
commit ce339d383c

View File

@@ -23,32 +23,32 @@ SFTP_ONLY=false
FILES_ONLY=false FILES_ONLY=false
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
-h|--help) -h | --help)
cat "$SCRIPT_DIR/MANUAL" cat "$SCRIPT_DIR/MANUAL"
exit 0 exit 0
;; ;;
--sftp-only) --sftp-only)
SFTP_ONLY=true SFTP_ONLY=true
echo -e "${YELLOW}SFTP only mode enabled${NC}" echo -e "${YELLOW}SFTP only mode enabled${NC}"
;; ;;
--files-only) --files-only)
FILES_ONLY=true FILES_ONLY=true
echo -e "${YELLOW}Files only mode enabled${NC}" echo -e "${YELLOW}Files only mode enabled${NC}"
;; ;;
esac esac
done 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() {
local entry="$1" local entry="$1"
cat .gitignore | grep "$entry" > /dev/null 2>&1 cat .gitignore | grep "$entry" >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$entry" >> .gitignore echo "$entry" >>.gitignore
echo -e "${BLUE}Added $entry to .gitignore${NC}" echo -e "${BLUE}Added $entry to .gitignore${NC}"
else else
echo -e "${YELLOW}$entry already is inside of .gitignore file${NC}" echo -e "${YELLOW}$entry already is inside of .gitignore file${NC}"
fi fi
} }
echo -e "${BLUE}=== Project Sync Configuration ===${NC}" echo -e "${BLUE}=== Project Sync Configuration ===${NC}"
@@ -56,67 +56,67 @@ echo ""
# Check if config is predefined (for testing usually) # Check if config is predefined (for testing usually)
if [ -f ".sync-credentials" ]; then if [ -f ".sync-credentials" ]; then
source ".sync-credentials" source ".sync-credentials"
else else
# Prompt for configuration (password before path for SSH resolution) # Prompt for configuration (password before path for SSH resolution)
read -p "Server user@host (e.g., leo@server.com): " SERVER_HOST read -p "Server user@host (e.g., leo@server.com): " SERVER_HOST
read -sp "SSH Password: " SSH_PASSWORD read -sp "SSH Password: " SSH_PASSWORD
echo "" echo ""
read -p "Server project path (default: ~/public_leo): " SERVER_PROJECT_PATH read -p "Server project path (default: ~/public_leo): " SERVER_PROJECT_PATH
read -p "Local folder path (e.g., Delta Pharmacy): " LOCAL_FOLDER read -p "Local folder path (e.g., Delta Pharmacy): " LOCAL_FOLDER
echo "" echo ""
fi fi
# Default path to ~/public_leo if empty # Default path to ~/public_leo if empty
if [ -z "$SERVER_PROJECT_PATH" ]; then if [ -z "$SERVER_PROJECT_PATH" ]; then
SERVER_PROJECT_PATH="~/public_leo" SERVER_PROJECT_PATH="~/public_leo"
fi fi
# Resolve ~ to full path via SSH # Resolve ~ to full path via SSH
if [[ "$SERVER_PROJECT_PATH" == ~* ]]; then if [[ "$SERVER_PROJECT_PATH" == ~* ]]; then
echo "Resolving path..." echo "Resolving path..."
SERVER_PROJECT_PATH=$(sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} "cd ${SERVER_PROJECT_PATH} && pwd") SERVER_PROJECT_PATH=$(sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} "cd ${SERVER_PROJECT_PATH} && pwd")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "${RED}Failed to resolve path${NC}" echo -e "${RED}Failed to resolve path${NC}"
exit 1 exit 1
fi fi
echo -e "${GREEN}Resolved to: ${SERVER_PROJECT_PATH}${NC}" echo -e "${GREEN}Resolved to: ${SERVER_PROJECT_PATH}${NC}"
fi fi
# Validate required variables (all except password) # Validate required variables (all except password)
if [ -z "$SERVER_HOST" ]; then if [ -z "$SERVER_HOST" ]; then
echo -e "${RED}Error: SERVER_HOST is not set${NC}" echo -e "${RED}Error: SERVER_HOST is not set${NC}"
exit 1 exit 1
fi fi
if [ -z "$SERVER_PROJECT_PATH" ]; then if [ -z "$SERVER_PROJECT_PATH" ]; then
echo -e "${RED}Error: SERVER_PROJECT_PATH is not set${NC}" echo -e "${RED}Error: SERVER_PROJECT_PATH is not set${NC}"
exit 1 exit 1
fi fi
if [ -z "$LOCAL_FOLDER" ]; then if [ -z "$LOCAL_FOLDER" ]; then
echo -e "${RED}Error: LOCAL_FOLDER is not set${NC}" echo -e "${RED}Error: LOCAL_FOLDER is not set${NC}"
exit 1 exit 1
fi fi
# Sync terminal info on full sync (no flags) # Sync terminal info on full sync (no flags)
if [ "$SFTP_ONLY" = false ] && [ "$FILES_ONLY" = false ]; then if [ "$SFTP_ONLY" = false ] && [ "$FILES_ONLY" = false ]; then
# Detect terminal type # Detect terminal type
if [[ "$TERM" == *"ghostty"* ]]; then if [[ "$TERM" == *"ghostty"* ]]; then
TERM_TYPE="xterm-ghostty" TERM_TYPE="xterm-ghostty"
elif [[ "$TERM" == *"kitty"* ]]; then elif [[ "$TERM" == *"kitty"* ]]; then
TERM_TYPE="xterm-kitty" TERM_TYPE="xterm-kitty"
else else
TERM_TYPE="" TERM_TYPE=""
fi fi
if [ -n "$TERM_TYPE" ]; then if [ -n "$TERM_TYPE" ]; then
echo "Syncing terminal info ($TERM_TYPE)..." echo "Syncing terminal info ($TERM_TYPE)..."
infocmp -x "$TERM_TYPE" | sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} -- tic -x - infocmp -x "$TERM_TYPE" | sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} -- tic -x -
echo -e "${GREEN}Terminal info synced${NC}" echo -e "${GREEN}Terminal info synced${NC}"
else else
echo -e "${YELLOW}Warning: Unknown terminal ($TERM), skipping terminfo sync${NC}" echo -e "${YELLOW}Warning: Unknown terminal ($TERM), skipping terminfo sync${NC}"
fi fi
fi fi
# Start sync process # Start sync process
@@ -125,14 +125,14 @@ echo "Starting project sync..."
# Step 1: SSH into server and create tar archive # Step 1: SSH into server and create tar archive
echo "Creating archive on server..." echo "Creating archive on server..."
if [ "$FILES_ONLY" = true ]; then if [ "$FILES_ONLY" = true ]; then
sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} "cd ${SERVER_PROJECT_PATH} && tar -czf ../${ARCHIVE_NAME} --exclude='node_modules' --exclude='vendor' ." sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} "cd ${SERVER_PROJECT_PATH} && tar -czf ../${ARCHIVE_NAME} --exclude='node_modules' --exclude='vendor' --exclude='uploads' ."
else else
sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} "cd ${SERVER_PROJECT_PATH} && tar -czf ../${ARCHIVE_NAME} ." sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} "cd ${SERVER_PROJECT_PATH} && tar -czf ../${ARCHIVE_NAME} --exclude='uploads' ."
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "${RED}Failed to create archive on server${NC}" echo -e "${RED}Failed to create archive on server${NC}"
exit 1 exit 1
fi fi
echo -e "${GREEN}Archive created successfully${NC}" echo -e "${GREEN}Archive created successfully${NC}"
@@ -145,8 +145,8 @@ echo "Copying archive to local machine..."
sshpass -p "${SSH_PASSWORD}" rsync -az --info=progress2 -e "ssh $SSH_OPTS" ${SERVER_HOST}:~/${ARCHIVE_NAME} "${LOCAL_FOLDER}/" sshpass -p "${SSH_PASSWORD}" rsync -az --info=progress2 -e "ssh $SSH_OPTS" ${SERVER_HOST}:~/${ARCHIVE_NAME} "${LOCAL_FOLDER}/"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "${RED}Failed to copy archive${NC}" echo -e "${RED}Failed to copy archive${NC}"
exit 1 exit 1
fi fi
echo -e "${GREEN}Archive copied successfully${NC}" echo -e "${GREEN}Archive copied successfully${NC}"
@@ -157,8 +157,8 @@ cd "${LOCAL_FOLDER}"
tar -xzf ${ARCHIVE_NAME} tar -xzf ${ARCHIVE_NAME}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "${RED}Failed to extract archive${NC}" echo -e "${RED}Failed to extract archive${NC}"
exit 1 exit 1
fi fi
echo -e "${GREEN}Archive extracted successfully${NC}" echo -e "${GREEN}Archive extracted successfully${NC}"
@@ -175,7 +175,7 @@ echo -e "${GREEN}File sync complete!${NC}"
# Skip helper scripts and config generation in files-only mode # Skip helper scripts and config generation in files-only mode
if [ "$FILES_ONLY" = true ]; then if [ "$FILES_ONLY" = true ]; then
exit 0 exit 0
fi fi
# Create .vscode sftp.json file # Create .vscode sftp.json file
@@ -214,15 +214,15 @@ 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
if [ "$SFTP_ONLY" = true ]; then if [ "$SFTP_ONLY" = true ]; then
# Sftp only scripts # Sftp only scripts
scripts=("local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh") scripts=("local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh")
else else
# All scripts # All scripts
scripts=("watch-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh" "split-conflicts.sh") scripts=("watch-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh" "split-conflicts.sh")
fi fi
for script in "${scripts[@]}"; do for script in "${scripts[@]}"; do
# Add variables to script # Add variables to script
echo " echo "
#!/bin/bash #!/bin/bash
set -e set -e
@@ -232,25 +232,25 @@ for script in "${scripts[@]}"; do
SERVER_PASSWORD=\"${SSH_PASSWORD}\" SERVER_PASSWORD=\"${SSH_PASSWORD}\"
SERVER_PATH=\"${SERVER_PROJECT_PATH}/\" SERVER_PATH=\"${SERVER_PROJECT_PATH}/\"
REMOTE_PROGRESS=\".remote-in-progress\" REMOTE_PROGRESS=\".remote-in-progress\"
" > "${script}" " >"${script}"
# Append the rest of the upload core build script # Append the rest of the upload core build script
cat "${SCRIPT_DIR}/scripts/${script}" >> "${script}" cat "${SCRIPT_DIR}/scripts/${script}" >>"${script}"
echo "${script} created successfully" echo "${script} created successfully"
# Skip .gitignore updates when --sftp-only flag is present # Skip .gitignore updates when --sftp-only flag is present
if [ "$SFTP_ONLY" = false ]; then if [ "$SFTP_ONLY" = false ]; then
add_to_gitignore "${script}" add_to_gitignore "${script}"
fi fi
done done
# Upload lazygit to server (skip when --sftp-only flag is present) # Upload lazygit to server (skip when --sftp-only flag is present)
if [ "$SFTP_ONLY" = false ]; then if [ "$SFTP_ONLY" = false ]; then
echo "Uploading lazygit to server..." echo "Uploading lazygit to server..."
sshpass -p "${SSH_PASSWORD}" scp $SSH_OPTS "${SCRIPT_DIR}/lazygit" ${SERVER_HOST}:${SERVER_PROJECT_PATH} sshpass -p "${SSH_PASSWORD}" scp $SSH_OPTS "${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 fi