-
Notifications
You must be signed in to change notification settings - Fork 6
/
angryhex.sh
executable file
·110 lines (96 loc) · 2.56 KB
/
angryhex.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
#!/bin/bash
#-------------------------------------------------------------------------------
SCR_ANGRYHEX=dev.angryhex.sh
ZIP_ANGRYHEX=angryhex.zip
DIR_ANGRYHEX=angryhex
URL_ANGRYHEX=https://github.com/DeMaCS-UNICAL/Angry-HEX/releases/download/angryhex2018/angryhex.zip
F_DEVELOP=.angryhex_dev
#-------------------------------------------------------------------------------
B=`tput bold`
N=`tput sgr0 tput rmul`
U=`tput smul`
usage() {
echo
echo "${B}SYNOPSIS${N}"
echo " ${B}./$(basename $0)${N} command [argument]"
echo
echo "${B}COMMANDS${N}"
echo
echo " ${B}install${N} [${U}all${N},dlv,boost,dlvhex,box2d,agent]"
echo
echo " ${B}run${N}"
echo
echo " ${B}update${N}"
echo
exit $1
}
#-------------------------------------------------------------------------------
REQUIRE() {
PACKAGES=$@
echo -n "checking if packages $PACKAGES are installed..."
if [[ ${OSTYPE} == ubuntu ]]; then
NOTFOUND=""
for f in $PACKAGES; do
FOUND=$(dpkg-query --show --showformat='${Status}\n' $f |grep 'install ok installed')
if [ "" == "$FOUND" ]; then
NOTFOUND="$NOTFOUND $f"
fi
done
if [ "" -ne "$NOTFOUND" ]; then
CMD="sudo apt-get -y install $NOTFOUND"
echo "did not find $NOTFOUND therefore installing with $CMD"
$CMD
else
echo "ok."
fi
else
echo "skipped (unknown OS)."
fi
}
downloadAgent() {
rm -rf ${SCR_ANGRYHEX}
rm -rf ${ZIP_ANGRYHEX}
rm -rf ${DIR_ANGRYHEX}
ensurePackagesAreInstalled wget unzip
wget ${URL_ANGRYHEX} -O ${ZIP_ANGRYHEX}
unzip ${ZIP_ANGRYHEX}
chmod +x ${SCR_ANGRYHEX}
}
ensureAgent() {
if [ -e ${SCR_ANGRYHEX} ]; then
# dev.angryhex.sh exists --> git clone or already unzipped
# git clone?
if [ -e ".git" ] && [ ! -e ${F_DEVELOP} ]; then
echo "angryhex.sh should be used in development mode when called from a git clone; please call ${B}./dev.angryhex.sh set develop${N}"
exit 1
fi
else
# dev.angryhex.sh exists --> no git clone and not already unzipped
downloadAgent
fi
}
#-------------------------------------------------------------------------------
CMD=$1
ARG=$2
if [ -z $CMD ]; then
usage 1
elif [ -z $ARG ]; then
case $CMD in
"install") ARG=all ;;
esac
fi
case $CMD in
"install")
case $ARG in
"all" | "dlv" | "boost" | "dlvhex" | "box2d" | "agent")
ensureAgent
./${SCR_ANGRYHEX} $CMD $ARG
#ldconfig
;;
*) echo "Unknown argument $ARG" && usage 1
esac
;;
"update") downloadAgent && ./${SCR_ANGRYHEX} install all ;;
"run") ./${SCR_ANGRYHEX} run client ${@:2} ;;
*) echo "Invalid command: $CMD" && usage 1
esac