Last active
November 5, 2025 16:42
-
-
Save alifarazz/2e356b2588ca5ab6b889d27c4153c34b to your computer and use it in GitHub Desktop.
Basic script to sync a local project with a remote server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # SPDX-License-Identifier: AGPL-3.0-or-later | |
| ######### NOTE: HOW TO USE ######################################### | |
| # $ bash sync-with-remote.bash <path to .(git)ignore file> <local path to watch for> | |
| set -euEo pipefail | |
| # set -x # show every command being executed, used for debug | |
| ##### Constants | |
| ######### NOTE: YOU NEED TO CHANGE THESE ########################### | |
| remote_path_prefix="nesaean:/project/ali" # Prefix to use for remote rsync command arg | |
| watcher_match_regex=".*((\.(cu|cuh|cc|hh|sh|md|c|h|inc|py|bash))|(CMakeLists\.txt)|(CMakePresets\.json))$" # Only watch for file paths matching regex | |
| function cut_path_postfix() { | |
| local i=5 # !!!!!!!!CHANGE-ME: Change based on your path on remote, experiment with it.!!!!!!! | |
| ret=$(echo $* | cut -d/ -f-1,${i}-) | |
| echo "$ret" | |
| } | |
| ##### Process argv | |
| src_path="$(realpath $2)" | |
| gitignore_path="$(realpath $1)" | |
| ##### Watch src_path directory for events | |
| echo Watching started on "$src_path" | |
| inotifywait -qmre modify,create,move "${src_path}" --format '%w%f%0' \ | |
| --no-newline --includei "${watcher_match_regex}" |\ | |
| while IFS= read -r -d '' file | |
| do | |
| # Copy the file that was just changed | |
| echo "${file}" # FOR DEBUG | |
| remote_path_postfix="$(echo ${file} | cut_path_postfix)" | |
| dst_path="${remote_path_prefix}${remote_path_postfix}" | |
| echo $dst_path | |
| rsync -urvPz --exclude-from="${gitignore_path}" "${file}" "${dst_path}" # FIXME: This doesn't mkdir on remote | |
| echo "----------------------------------------" | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment