Repository navigation
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·110 lines (94 loc) · 2.53 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·110 lines (94 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
usage() {
echo "Usage: $0 [--dry-run] -d DEST_REPO"
echo " --dry-run Show what would be synced without making changes"
echo " -d, --dest Destination repository path"
echo
echo "Example:"
echo " $0 --dry-run -d /Users/$USER/workspace/amazon-dynamodb-immersion-day"
exit 1
}
# Get the directory where the script is located
SOURCE_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Parse command line arguments
DRY_RUN=false
DEST_REPO=""
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=true
shift
;;
-d|--dest)
DEST_REPO="$2"
shift 2
;;
*)
usage
;;
esac
done
# Validate required parameters
if [ -z "$DEST_REPO" ]; then
usage
fi
# Define source and destination directory pairs
src_dirs=(
"content"
"static"
)
dest_dirs=(
"content"
"static"
)
# Define source and destination file pairs
src_files=(
"design-patterns/cloudformation/vscode.yaml"
)
dest_files=(
"static/ddb.yaml"
)
# Function to perform sync
perform_sync() {
local rsync_options="-avz"
if [ "$DRY_RUN" = true ]; then
rsync_options="$rsync_options --dry-run"
echo "Performing dry run..."
else
echo "Performing actual sync..."
fi
echo "Source repository: $SOURCE_REPO"
echo "Destination repository: $DEST_REPO"
# Sync directories
for i in "${!src_dirs[@]}"; do
echo "Syncing directory: ${src_dirs[$i]}/ -> ${dest_dirs[$i]}/"
mkdir -p "$DEST_REPO/${dest_dirs[$i]}"
rsync $rsync_options "$SOURCE_REPO/${src_dirs[$i]}/" "$DEST_REPO/${dest_dirs[$i]}/"
done
# Sync individual files
for i in "${!src_files[@]}"; do
echo "Syncing file: ${src_files[$i]} -> ${dest_files[$i]}"
dest_dir=$(dirname "$DEST_REPO/${dest_files[$i]}")
mkdir -p "$dest_dir"
rsync $rsync_options "$SOURCE_REPO/${src_files[$i]}" "$DEST_REPO/${dest_files[$i]}"
done
echo "Great! Now follow instructions in the amazon-dynamodb-immersion-day README.md document to complete the sync."
}
# Verify destination repository exists
if [ ! -d "$DEST_REPO" ]; then
echo "Error: Destination repository does not exist: $DEST_REPO"
exit 1
fi
# Execute sync
if [ "$DRY_RUN" = true ]; then
perform_sync
else
read -p "This will perform an actual sync. Are you sure? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
perform_sync
else
echo "Sync cancelled."
exit 1
fi
fi