This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateZip.sh
executable file
·87 lines (65 loc) · 1.54 KB
/
createZip.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
#!/bin/bash
VERBOSE=false
CURRENT_BRANCH=$(git branch --show-current)
DATE=$(date +%Y-%m-%d_%Hh%M)
function show_help {
echo Usage ./$0 [BRANCH_NAME]
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))
ARG_BRANCH=$1
BRANCH=${ARG_BRANCH:-${CURRENT_BRANCH}}
ZIP_FILE=gameModel_${BRANCH}_${DATE}.zip
$VERBOSE && echo "Create ZIP from branch '${BRANCH}'"
# make sure the given zip file does not exist
if [ -f "${ZIP_FILE}" ]; then
printError "$ZIP_FILE already exists";
exit 1;
fi
GIT_STATUS_SHORT=$(git status --short gameModel)
if [ ! -z "${GIT_STATUS_SHORT}" ]; then
git status
printError "Pending changes in repository ! Please commit or revert all changes";
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
zip -qq -r $ZIP_FILE gameModel
if [ $? -ne 0 ]; then
printError "Failed to create ZIP file";
exit 1;
fi
echo "Done"
echo
echo "Zip file is ${ZIP_FILE}"