-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes-launcher.sh
executable file
·313 lines (279 loc) · 4.9 KB
/
es-launcher.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
Path=$(dirname $(readlink -f $0))"/"
Config=$Path"es-launcher.config"
Resources=$Path"ES-launcher/"
Repos=$Resources"repositories/"
Instances=$Resources"instances/"
declare -a Repository
declare -a Plugin
declare -a Savefile
declare -a Version
declare -a OS
declare -a Result
lower(){
case "$1" in
[A-Z])
n=$(printf "%d" "'$1")
n=$((n+32))
printf \\$(printf "%o" "$n")
;;
*)
printf "%s" "$1"
;;
esac
}
HeaderText () {
local bar=""
local i=0
local size=${#1}
while (( $i < $size ))
do
bar+="-"
((i++))
done
echo $bar
echo $*
echo $bar
}
StreamText () {
local i=0
while (( $i <= ${#1} ))
do
printf "$(expr substr "$1" $i 1)"
if [ $2 ]
then
sleep $2
else
sleep .1
fi
((i++))
done
printf "\n"
}
Search () {
local -n Array=$1
local Reply=$2
local Number=$3
local Term=$4
local begin=$5
(( begin-- ))
local i=0
local e=$begin
local n=1
unset $Result
echo "test"
echo "${Array[1]}"
while (( i < ${#Array[@]} ))
do
read -a Break <<< ${Array[i]}
case $Reply in
bool)
echo "${Break[e]}"
if [[ "${Break[e]}" == *"$Term"* ]]
then
echo "$Term"
return 0
fi
;;
*)
if [[ "${Break[e]}" == *"$Term"* ]]
then
Result[${#Result[@]}]=${Break[$Reply]}
echo $Result
fi
if (( $n >= $Number || $n == ${#Array[@]} ))
then
return 0
fi
((n++))
;;
esac
((i++))
done
return 1
}
Menu () {
MenuInput=0
printf "1:\tLaunch Version\n"
printf "2:\tCompile Version\n"
printf "3:\tImport Repository\n"
printf "4:\tExit\n"
echo
while [ 1 ]
do
case $MenuInput in
1) # Launch Version
if [ ! ${Version[0]} ]
then
echo "There are no versions avaliable to run."
echo "Please select compile from the list of options."
echo
Menu
fi
Launch
break
;;
2) # Compile Version
if ( ! Search "Repository" "bool" "void" "source" 4 )
then
echo "There are no repositories avaliable to compile."
echo "Please import a repository containing source code."
echo
Menu
fi
Compile
break
;;
3) # Import Repository
Import
break
;;
4) # Exit
break
;;
*)
echo "Please enter the number next to your choice."
read MenuInput
echo
;;
esac
done
}
Launch () {
:
}
Compile () {
:
}
Import () {
:
}
touch $Config
mkdir -p $Resources
mkdir -p $Repos
mkdir -p $Instances
echo "Loading configuration file."
while read -a line
do
case "${line[0]}" in
repository)
Repository[${#Repository[@]}]=${line[@]:1}
;;
plugin)
Plugin[${#Plugin[@]}]=${line[@]:1}
;;
savefile)
Savefile[${#Savefile[@]}]=${line[@]:1}
;;
version)
Version[${#Version[@]}]=${line[@]:1}
;;
OS)
OS[${#OS[@]}]=${line[@]:1}
;;
esac
done < "$Config"
echo "done"
# first time setup
if [[ ${#OS[@]} == 0 ]]
then
while [ 1 ]
do
case $OSinput in
Linux)
break
;;
Windows)
echo "Please enter the full path to your Code::Blocks executable starting with the drive."
read OScompiler
OS[1]=/mnt/
i=0
if [ "$(expr substr "$str" 2 1)" = ":" ]; then
lower $char
OS[1]+=$char/
fi
while (( i <= ${#OScompiler} ))
do
char=$(expr substr "$str" $i 1)
((i++))
done
break
;;
OSX)
echo "The author does not currently know how to compile for OSX. If you have done so please feel free to make a PR at http://github.com/Nechochwen-D/ES-launcher"
exit 0
;;
*)
echo "please enter OS (Linux, Windows, OSX)"
read OSinput
echo
;;
esac
done
OS[0]=$OSinput
fi
if ( Search "OS" 2 1 "Windows" 1)
then
str=$(printf $Reply)
fi
if ( ! Search "Repository" "bool" "void" "endless-sky/endless-sky" 1 )
then
indexL=${#Repository[@]}
Repository[$indexL]="https://github.com/endless-sky/endless-sky.git auto"
cd $Repos
git clone https://github.com/endless-sky/endless-sky.git
Repository[$indexL]+=" $(ls -td $Repos*/ | head -1) source"
fi
# begin interface
clear
HeaderText "Welcome to the unofficial launcher for Endless Sky."
echo "Script created by Nechochwen."
echo
echo "What do you want to do?"
echo
Menu
echo ${#OS[@]}
# Write to .config file.
echo "# Repositories" > $Config
echo >> $Config
i=0
while [[ $i < ${#Repository[@]} ]]
do
echo "repository ${Repository[$i]}" >> $Config
((i++))
done
echo >> $Config
echo "# Plugins" >> $Config
echo >> $Config
i=0
while [[ $i < ${#Plugin[@]} ]]
do
echo "plugin ${Plugin[$i]}" >> $Config
((i++))
done
echo >> $Config
echo "# Saves" >> $Config
echo >> $Config
i=0
while [[ $i < ${#Savefile[@]} ]]
do
echo "savefile ${Savefile[$i]}" >> $Config
((i++))
done
echo >> $Config
echo "# Versions" >> $Config
echo >> $Config
i=0
while [[ $i < ${#Version[@]} ]]
do
echo "version ${Version[$i]}" >> $Config
((i++))
done
echo >> $Config
echo >> $Config
i=0
while [[ $i < ${#OS[@]} ]]
do
echo "OS ${OS[$i]}" >> $Config
((i++))
done