-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·148 lines (134 loc) · 3 KB
/
start.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# https://github.com/ZillyWoods/ZillyWoods-scripts/blob/master/start.sh
# helper script to start zillywoods client
is_update=0
is_found=0
if [[ "$1" == "--update" ]] || [[ "$1" == "update" ]]
then
is_update=1
shift
fi
clientname="${1:-ZillyWoods}"
clientlower="${clientname,,}"
clientbinary="${2:-$clientlower}"
gitpath="$HOME/Desktop/git"
reponame="$clientname"
run_client="gdb -ex='set confirm off' "
run_client+="-ex='set pagination off' "
run_client+="-ex=run -ex=bt --args ./$clientbinary"
# actually binarys next to data dirs
declare -A aDataPaths
aDataPaths+=(["cmake"]="$clientbinary")
aDataPaths+=(["bam64_dbg"]="x86_64/debug/$clientbinary")
aDataPaths+=(["bam64_rls"]="x86_64/release/$clientbinary")
aDataPaths+=(["bam32_dbg"]="x86_32/debug/$clientbinary")
aDataPaths+=(["bam32_rls"]="x86_32/release/$clientbinary")
function get_path() {
file=$1
echo "${file%/*}"
}
function git_save_pull() {
if [ "$(git status | tail -n1)" != "nothing to commit, working tree clean" ]
then
echo "WARNING: git pull failed! Is your working tree clean?"
echo " git status"
return
fi
git pull
}
function get_bam() {
bam="echo 'Bam not found';exit 1;"
if [ -x "$(command -v bam)" ]
then
bam="bam"
elif [ -x "$(command -v bam5)" ]
then
bam="bam5"
elif [ -x "$(command -v bam4)" ]
then
bam="bam4"
elif [ -x "$(command -v ../bam)" ]
then
bam="../bam"
elif [ -x "$(command -v ../bam/bam)" ]
then
bam="../bam/bam"
fi
echo "$bam"
}
function get_build_cmd() {
local build
local bam
if [ "$is_update" == "0" ]
then
return
fi
bam="$(get_bam)"
build=""
if [ "$is_found" == "0" ]
then
return
fi
if [ -f ../CMakeLists.txt ]
then
build="cd .. || exit 1;"
build+="mkdir -p build && cd build;"
build+="cmake .. -DCMAKE_BUILD_TYPE=Debug;"
build+="make -j$(nproc)"
else
# bam does two more up
if [ -f ../../bam.lua ]
then
build="cd ../../ || exit 1;"
build+="$bam"
fi
fi
echo "$build"
}
function launch_client() {
local build
if [ -d ../.git ] && [ "$is_update" == "1" ]
then
git_save_pull
fi
build="$(get_build_cmd)"
echo "-------"
echo ""
echo " cd $(pwd)"
echo " $build"
echo " $run_client"
echo ""
echo "-------"
eval "$build"
eval "$run_client"
exit "$?"
}
function check_data() {
file=$1
if [ ! -f "$file" ]
then
echo "file does not exist '$file'"
return
fi
echo "file = $file"
path="$(get_path "$file")"
if [ ! -d "$path" ]
then
echo "Invalid path='$path'. Script is probably broken"
exit 1
fi
cd "$path" || exit 1
echo "cd into path=$path"
cd "$path" || exit 1
is_found=1
launch_client
}
for key in ${!aDataPaths[@]}; do
file="$gitpath/$reponame/build/${aDataPaths[${key}]}"
echo "${key} - $file"
check_data "$file"
done
# last hope use ~.teeworlds/
echo "fallback to home directory"
cd || exit 1
launch_client