forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_module.sh
More file actions
executable file
·48 lines (41 loc) · 1.14 KB
/
sync_module.sh
File metadata and controls
executable file
·48 lines (41 loc) · 1.14 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
#!/bin/bash
# 1. Backs up tracked files by git
# 2. Copies everything from Source folder
# 3. Restores backed files
if [[ $# -eq 0 ]] ; then
printf "\e[31mUsage: sync_module.sh <path to module folder>\e[39m\n"
exit 0
fi
if [ ! -d "${1}" ]; then
printf "\e[31mError! Folder '${1}' does not exist.\e[39m\n"
exit 0
fi
printf "\e[1;33mSynchronizing module ${1##*/}.\e[0;39m\n"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$1"
TMP="./___tmp"
rm -rf $TMP
mkdir $TMP
ROOTFOLDER="Assets/TouchScript"
IFS=$'\n'
for f in $(git ls-tree -r --name-only HEAD | grep "^$ROOTFOLDER/") ; do
echo "$f"
FOLDER=$(dirname "$f")/
FILENAME=$(basename "$f")
TMPFOLDER="$TMP/${FOLDER##$ROOTFOLDER/}"
mkdir -p "$TMPFOLDER"
if (! cp "./$f" "$TMPFOLDER$FILENAME") ; then
printf "\e[31mError copying $f to $TMPFOLDER$FILENAME!\e[39m\n"
exit 0;
fi
done
rm -rf ./$ROOTFOLDER
if (! cp -rf "$DIR/../../Source/Assets/TouchScript" "./Assets/") ; then
printf "\e[31mError copying TouchScript to ${1}!\e[39m\n"
exit 0;
fi
if (! cp -r "$TMP/." "./$ROOTFOLDER/") ; then
printf "\e[31mError copying temporary files to ${1}!\e[39m\n"
exit 0;
fi
rm -rf $TMP