dirsync initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
# Directory Sync Utility
|
||||
|
||||
This directory contains a tool for syncing a local directory to a remote host in real time.
|
||||
It watches for file changes and transfers them immediately via SCP, making it useful for
|
||||
live development on a remote server.
|
||||
|
||||
## Scripts
|
||||
|
||||
| Script | Description |
|
||||
|---|---|
|
||||
| `dir-sync.sh` | Improved version — recommended |
|
||||
| `scpsync.sh` | Original version |
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
./dir-sync.sh -s /path/to/local/dir/ -d /path/to/remote/dir/ -r sshhost
|
||||
```
|
||||
|
||||
The script starts watching the local directory immediately. Press **Ctrl+C** to stop —
|
||||
it will reset the remote repository (`git reset --hard`) and clear the remote cache before exiting.
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Description |
|
||||
|---|---|
|
||||
| `-s, --source <path>` | Local directory absolute path |
|
||||
| `-d, --dest <path>` | Remote directory absolute path |
|
||||
| `-r, --remote-host <h>` | Remote SSH host (as configured in `~/.ssh/config`) |
|
||||
| `-h, --help` | Print help |
|
||||
|
||||
If an option is omitted, the script falls back to the default values defined at the top of the script.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **File watching**: `fswatch` monitors the source directory for any change, excluding `.git/`
|
||||
2. **Batch end marker**: `fswatch --batch-marker` emits a `NoOp` signal at the end of each batch
|
||||
3. **File sync**: each changed file is transferred with `scp`, preserving the relative path under the destination directory
|
||||
4. **Cache clear**: on each `NoOp` (end of batch), `composer front-cache-clear` is run on the remote
|
||||
5. **Cleanup on exit**: Ctrl+C triggers `git reset --hard` and a final cache clear on the remote
|
||||
|
||||
## Default Configuration
|
||||
|
||||
Edit the three constants at the top of `dir-sync.sh` to set your own defaults:
|
||||
|
||||
```bash
|
||||
DEFAULT_LOCAL_PATH='/path/to/local/dir/'
|
||||
DEFAULT_REMOTE_PATH='/path/to/remote/dir/'
|
||||
DEFAULT_HOST='devac'
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
- [`fswatch`](https://github.com/emcrisostomo/fswatch) — file system watcher
|
||||
- `scp` and `ssh` — standard OpenSSH tools
|
||||
- A remote host configured in `~/.ssh/config` (password-less key auth recommended)
|
||||
- `composer` available on the remote host (for cache clearing)
|
||||
|
||||
### Installing fswatch
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
brew install fswatch
|
||||
|
||||
# Linux (Ubuntu/Debian)
|
||||
sudo apt install fswatch
|
||||
```
|
||||
|
||||
## About
|
||||
|
||||
**Author:** Julien Gautier ([jgautier.webdev@gmail.com](mailto:jgautier.webdev@gmail.com))
|
||||
|
||||
**Organization:** AdAstra
|
||||
|
||||
**Project:** adastra_scripts
|
||||
Reference in New Issue
Block a user