-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathreplicate.sh
executable file
·56 lines (50 loc) · 1.26 KB
/
replicate.sh
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
#!/usr/bin/env bash
# define source folder
# take src as input arg
src=$1
# src=src/app/common
# define files array
# take multiple files as input arg
# if * is passed, copy all files
if [[ $2 == "*" ]]; then
files=($(ls $src))
else
files=($2)
fi
# files=(auth.service.ts auth.service.spec.ts)
# define folders array
# take multiple folders as input arg
stages=("8" "10" "11" "12")
# if the third arg is not empty use it as the stages array
if [[ -n $3 ]]; then
stages=($3)
fi
stageFolders=()
# prepend each stages input with stage
for number in "${stages[@]}"; do
stageFolders+=("projects/stage$number")
done
# set param named force if --force or -f is passed
force=false
if [[ $4 == "--force" || $4 == "-f" ]]; then
force=true
fi
for file in "${files[@]}"; do
for folder in "${stageFolders[@]}"; do
echo -n "Copying $src/$file to $folder"
if [[ -d "$folder" ]]; then
# copy only if target file exists or force is true
if [[ $force == true ]]; then
cp -r $src/$file $folder/$src/
echo "... created"
elif [[ -f "$folder/$src/$file" ]]; then
cp -r $src/$file $folder/$src/
echo "... updated"
else
echo "... file does not exist"
fi
else
echo "... folder does not exist"
fi
done
done