-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateFromZip.sh
executable file
·121 lines (89 loc) · 2.09 KB
/
updateFromZip.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
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
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
VERBOSE=false
CURRENT_BRANCH=$(git branch --show-current)
function show_help {
echo Usage $0 ZIP_FILE [BRANCH_NAME]
echo " ZIP_FILE : path to exported gameModel"
echo " Default BRANCH_NAME is $(git branch --show-current)"
}
function printError() {
echo;
echo "Abort";
if [ ! -z "$1" ]; then
echo $1;
fi
}
## Parse options
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
while getopts "h?v" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
v) VERBOSE=true
;;
esac
done
## Read arguments
shift $(($OPTIND - 1))
ZIP_FILE=$1
ARG_BRANCH=$2
BRANCH=${ARG_BRANCH:-${CURRENT_BRANCH}}
$VERBOSE && echo "Update ${BRANCH} from ${ZIP_FILE}"
# make sure the given zip file exists
if [ -z "${ZIP_FILE}" ]; then
show_help;
exit 1;
fi
# make sure the given zip file exists
if [ ! -f "${ZIP_FILE}" ]; then
printError "$ZIP_FILE does not exist";
exit 1;
fi
ZIP_INFO=$(zipinfo -1 ${ZIP_FILE} 2> /dev/null | grep -e "^/\?gameModel/")
if [ -z "${ZIP_INFO}" ]; then
printError "${ZIP_FILE} is not a valid gameModel export";
exit 1;
fi
GIT_STATUS_SHORT=$(git status --short gameModel)
if [ ! -z "${GIT_STATUS_SHORT}" ]; then
git status
printError "Pending changes in repository !";
exit 1;
fi
if [ ! "${BRANCH}" == "${CURRENT_BRANCH}" ]; then
if [ ${VERBOSE} ]; then
git switch $BRANCH;
else
git switch -q $BRANCH;
fi
if [ $? -ne 0 ]; then
printError "Branch ${BRANCH} does not exist";
exit 1;
fi
fi
$VERBOSE && echo Process
TMP_DIR=$(mktemp -d ./gameModel.XXXXXX)
mv ./gameModel $TMP_DIR
unzip -qq $ZIP_FILE "gameModel/**"
if [ $? -ne 0 ]; then
mv $TMP_DIR/gameModel .
rmdir $TMP_DIR;
printError "Unzip failed: restore previous gameModel";
exit 1;
fi
rm -R $TMP_DIR;
echo "Prettier formatting"
yarn format
echo "Compiling TypeScript"
yarn build
if [ $? -gt 0 ]; then
echo
echo "Compilation error(s), please fix";
echo
fi
echo "Done"
echo
echo "Please review changes"