-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.bash
More file actions
executable file
·479 lines (387 loc) · 10.5 KB
/
install.bash
File metadata and controls
executable file
·479 lines (387 loc) · 10.5 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/bin/bash
### CPU ###
# CPU in use for the compilation
# You can change and take an other number (this command maximise)
declare -ix nb_cpu=`cat /proc/cpuinfo | head -13 | tail -1 | cut -d: -f2-2 | cut -d" " -f2-`
### GIT ###
declare -x KOS_REPO="git.code.sf.net/p/cadcdev/kallistios"
declare -x KOS_PORTS_REPO="git.code.sf.net/p/cadcdev/kos-ports"
declare -ix GIT_DOWNLOAD_MODE=0
### FOLDER ###
declare -x MAIN_FOLDER=`pwd`
# TO MODIFY IF YOU WANT BEGIN
# 0 = no sudo power needed
# 1 = sudo power needed
# NOT USED YET
declare -ix REGULAR_FOLDER=0
declare -xr DC_CHAIN_INSTALL_FOLDER_NAME="dreamcast_chain"
declare -xr DC_CHAIN_INSTALL_PATH="$MAIN_FOLDER/$DC_CHAIN_INSTALL_FOLDER_NAME/"
# NOT USED YET
declare -xr NAME_NEW_BASHRC="new_bashrc"
declare -xr KOS_FOLDER_NAME="kos"
declare -xr KOS_PORTS_FOLDER_NAME="kos-ports"
declare -xr ENVIRON_SCRIPT_NAME="environ.sh"
# TO MODIFY IF YOU WANT END
declare -xr NEW_BASHRC="$MAIN_FOLDER/$NAME_NEW_BASHRC"
declare -xr KOS_PORTS_GIT_MODULES_FILE=".gitmodules"
declare -xr KOS_DC_CHAIN_FOLDER_NAME="$MAIN_FOLDER/$KOS_FOLDER_NAME/utils/dc-chain"
declare -xr DC_CHAIN_DEFAULT_PATH="/opt/toolchains/dc/"
declare -xr ENVIRON_SAMPLE_SCRIPT_NAME="environ.sh.sample"
### OS ###
declare -x OS=""
declare -arx OS_AVAILABLE=("ARCH")
declare -arx PACKAGE_MANAGER_SEARCH_AVAILABLE=("pacman -Q --search ARG")
declare -arx PACKAGE_MANAGER_INSTALL_AVAILABLE=("pacman -S ARG")
declare -arx PACKAGE_FOR_ARCH=("gcc" "git" "gawk" "patch" "bzip2" "tar" "make" "sed" "flex" "bison" "texinfo" "wget" "gettext" "elfutils" "libmpc" "mpfr" "gmp")
### SCRIPT VALUE ###
# 255 = OS
# 254 = INTERNET
# 253 = FUNCTION BAD USE
# 252 = SED PB
declare -arix EXIT_SCRIPT_VALUES=(255 254 253 252)
### SCRIPT ERROR ###
# Exit the script for some return
# USE : exit_the_script
# RETURN :
# NONE
function exit_the_script
{
declare -ix return_value=$?
for((cpt_exit_script_values=0 ; cpt_exit_script_values < ${#EXIT_SCRIPT_VALUES[*]} ; ++cpt_exit_script_values))
do
if [ $return_value -eq ${EXIT_SCRIPT_VALUES[$cpt_exit_script_values]} ]; then
exit $return_value
fi
done
}
### TOOLS ###
# Give a path with an escape character before /
# USE : add_escape_character_for_path path
# Return value :
# string with characters "/" are escape = OK
# ERROR MUST HAVE AN ARGUMENT = ERROR / the fonction must have an argument
function add_escape_character_for_path
{
string_path_escape="";
string_path=$1;
# echo ${#string_path}
# Check if there are only 1 argument
if [ $# -eq 1 ]; then
# For all character if the current character is / then
# he is escape thanks to \/ else the character are not modified
for((cpt_string_path=0 ; cpt_string_path < ${#string_path} ; ++cpt_string_path))
do
if [ ${string_path:$cpt_string_path:1} = "/" ]; then
string_path_escape=$string_path_escape"\/";
else
string_path_escape=$string_path_escape${string_path:$cpt_string_path:1};
fi
done
echo $string_path_escape;
else
echo "ERROR MUST HAVE AN ARGUMENT";
fi
}
### CHECK ###
# Check the OS
# USE : check_os
# RETURN :
# 0 = OK / Find in OS_AVAILABLE
# -1 = NOK / Not supported
function check_os
{
for((cpt_os_available=0 ; cpt_os_available < ${#OS_AVAILABLE[*]} ; ++cpt_os_available))
do
uname -a | grep ${OS_AVAILABLE[$cpt_os_available]} &> /dev/null
if [ $? -eq 0 ]; then
OS=${OS_AVAILABLE[$cpt_os_available]}
return 0
fi
done
return -1
}
# Check the librarys installed and install all missing librarys
# USE : check_library_package
# RETURN :
# 0 = OK / Success to install all missing package
# -1 = NOK / Not supported
# -2 = ROOT PB
function check_library_package
{
declare -x package_manager_search=""
declare -x package_manager_install=""
declare -x missing_package=""
# Check the OS var
case $OS in
ARCH)
# Find the position of ARG in PACKAGE_MANAGER_SEARCH_AVAILABLE
limit=`expr index "${PACKAGE_MANAGER_SEARCH_AVAILABLE[0]}" ARG`
# Substr PACKAGE_MANAGER_SEARCH_AVAILABLE 0 -> limit ( before ARG )
package_manager_search=${PACKAGE_MANAGER_SEARCH_AVAILABLE:0:$(($limit-1))}
# Find the position of ARG in PACKAGE_MANAGER_INSTALL_AVAILABLE
limit=`expr index "${PACKAGE_MANAGER_INSTALL_AVAILABLE[0]}" ARG`
# Substr PACKAGE_MANAGER_INSTALL_AVAILABLE 0 -> limit ( before ARG )
package_manager_install=${PACKAGE_MANAGER_INSTALL_AVAILABLE:0:$(($limit-1))}
;;
*)
# Not init
return -1
;;
esac
# Check all packages
for((cpt_package_for_arch=0 ; cpt_package_for_arch < ${#PACKAGE_FOR_ARCH[*]} ; ++cpt_package_for_arch))
do
# Do the search
$package_manager_search "^${PACKAGE_FOR_ARCH[$cpt_package_for_arch]}$" &> /dev/null
# Check if there are an error => no lines => not installed
if [ $? -ne 0 ]; then
missing_package="$missing_package ${PACKAGE_FOR_ARCH[$cpt_package_for_arch]}"
fi
done
# Check the missing_package var
if [ "$missing_package" != "" ]; then
# Do the sudo command
echo "sudo $package_manager_install $missing_package"
sudo $package_manager_install $missing_package
# TODO = if the user is not sudo do something
if [ $? -eq 0 ]; then
echo "No root password"
return -2
fi
fi
return 0
}
### DOWNLOAD REPO ###
# Downlaod the repo
# USE : download_repo repo_address_without_http|https
# RETURN :
# 0 = OK
# -3 = BAD USE
# -5 = GIT PB
function download_repo
{
# Bad use
if [ $# -ne 2 ]; then
return -3
fi
case $GIT_DOWNLOAD_MODE in
0)
git clone git://$1 $2
if [ $? -ne 0 ]; then
GIT_DOWNLOAD_MODE=1
git clone http://$1 $2
if [ $? -ne 0 ]; then
return -5
fi
fi
;;
1)
git clone http://$1 $2
if [ $? -ne 0 ]; then
return -5
fi
;;
*)
return -5
;;
esac
return 0
}
# Replace all git to http in $1
# USE : replace_submodules_git_to_http gitmodules_file
# RETURN :
# 0 = OK
# -3 = BAD USE
# -4 = SED PB
function replace_submodules_git_to_http
{
# Function protection
if [ $# -ne 1 ]; then
return -3
fi
# Replace
sed "s/git:\/\//http:\/\//g" --in-place $1
# Error
if [ $? -ne 0 ]; then
return -4
fi
return 0
}
# Downlaod submodule
# USE : download_submodules gitmodules_file
# RETURN :
# 0 = OK
# -3 = BAD USE
# -5 = GIT PB
function download_submodules
{
if [ $# -ne 1 ]; then
return -3
fi
case $GIT_DOWNLOAD_MODE in
0)
# Submodule init cmd
git submodule update --init
# Pb try with http
if [ $? -ne 0 ]; then
GIT_DOWNLOAD_MODE=1
# Replace
replace_submodules_git_to_http $1
exit_the_script
# Submodule init cmd
git submodule update --init
# Error
if [ $? -ne 0 ]; then
return -5
fi
fi
;;
1)
# Replace
replace_submodules_git_to_http $1
# Error
exit_the_script
# Submodule init cmd
git submodule update --init
# Error
if [ $? -ne 0 ]; then
return -5
fi
;;
*)
return -5
;;
esac
return 0
}
### DREAMCAST CHAIN ###
# Download all Dreamcast chain
# TODO : See to modify the download script
# USE : download_dc_chain
# RETURN :
# 0
function download_dc_chain
{
cd $KOS_DC_CHAIN_FOLDER_NAME
# chmod u+x download.sh
# if [ $GIT_DOWNLOAD_MODE -eq 1 ]; then
# sed "s/ftp:\/\//http:\/\//g" --in-place download.sh
# fi
# ./download.sh --no-deps
wget -c sourceforge.net/projects/devkitpro/files/sources/newlib/newlib-2.0.0.tar.gz
wget -c ftp.gnu.org/gnu/binutils/binutils-2.23.2.tar.bz2
wget -c ftp.gnu.org/gnu/gcc/gcc-4.7.3/gcc-4.7.3.tar.bz2
return 0
}
# Unpack all Dreamcast chain
# TODO : See to not use the unpack script
# USE : unpack_dc_chain
# RETURN :
# 0 = OK
function unpack_dc_chain
{
cd $KOS_DC_CHAIN_FOLDER_NAME
chmod u+x unpack.sh
./unpack.sh --no-deps
# tar jxf binutils-2.23.2.tar.bz2
# tar jxf gcc-4.7.3.tar.bz2
# tar zxf newlib-2.2.0.tar.gz
return 0
}
# Make all Dreamcast chain
# USE : make_dc_chain
# RETURN :
# 0 = OK
function make_dc_chain
{
cd $KOS_DC_CHAIN_FOLDER_NAME
if [ $REGULAR_FOLDER -eq 0 ]; then
mkdir -p $DC_CHAIN_INSTALL_PATH
elif [ $REGULAR_FOLDER -eq 1 ];then
echo "sudo mkdir -p $DC_CHAIN_INSTALL_PATH"
sudo mkdir -p $DC_CHAIN_INSTALL_PATH
fi
# Escape all paths
declare -x dc_default_path_escape=$(add_escape_character_for_path $DC_CHAIN_DEFAULT_PATH)
declare -x dc_install_path_escape_make=$(add_escape_character_for_path $DC_CHAIN_INSTALL_PATH)
# Replace the install path
sed "s/$dc_default_path_escape/$dc_install_path_escape_make/g" --in-place Makefile
# Optimise makejobs for each pc
sed "s/makejobs=-4/makejobs=-j$nb_cpu/g" --in-place Makefile
make
return 0
}
### KOS AND KOS PORT ###
# Make the KOS
# USE : make_kos
# RETURN :
# NONE
function make_kos
{
cd $MAIN_FOLDER/$KOS_FOLDER_NAME
# Escape all paths
declare -x kos_path_default_escape=$(add_escape_character_for_path "$DC_CHAIN_DEFAULT_PATH"kos)
declare -x kos_path_escape=$(add_escape_character_for_path "$MAIN_FOLDER/$KOS_FOLDER_NAME")
declare -x dc_install_path_escape=$(add_escape_character_for_path $DC_CHAIN_INSTALL_PATH)
declare -x tmp=""
cp doc/$ENVIRON_SAMPLE_SCRIPT_NAME $ENVIRON_SCRIPT_NAME
# Modify the environment script
sed "s/export KOS_BASE=\"$kos_path_default_escape\"/export KOS_BASE=\"$kos_path_escape\"/g" --in-place $ENVIRON_SCRIPT_NAME
tmp="${dc_install_path_escape}sh-elf"
sed "s/export KOS_CC_BASE=\"\/opt\/toolchains\/dc\/sh-elf\"/export KOS_CC_BASE=\"$tmp\"/g" --in-place $ENVIRON_SCRIPT_NAME
tmp="${dc_install_path_escape}arm-eabi"
sed "s/export DC_ARM_BASE=\"\/opt\/toolchains\/dc\/arm-eabi\"/export DC_ARM_BASE=\"$tmp\"/g" --in-place $ENVIRON_SCRIPT_NAME
tmp="${kos_path_escape}\/bin"
sed "s/export PATH=\"\${PATH}:\${KOS_CC_BASE}\/bin:\/opt\/toolchains\/dc\/bin\"/export PATH=\"\${PATH}:\${KOS_CC_BASE}\/bin:$tmp\"/g" --in-place $ENVIRON_SCRIPT_NAME
# Change right and execute script
chmod u+x $ENVIRON_SCRIPT_NAME
source $ENVIRON_SCRIPT_NAME
# Compilation
make -j$nb_cpu
# TODO : if its a root path
}
# Make the KOS Port
# USE : make_kos_port
# RETURN :
# NONE
function make_kos_port
{
cd $MAIN_FOLDER/$KOS_PORTS_FOLDER_NAME
# Compilation
make #-j$nb_cpu
}
### MAIN ###
# Main function
# USE : main_function
# RETURN :
# NONE
function main_function
{
check_os
exit_the_script
echo $OS
check_library_package
exit_the_script
echo "All missing librarys installed"
download_repo $KOS_REPO $KOS_FOLDER_NAME
exit_the_script
echo "KOS repo download"
download_repo $KOS_PORTS_REPO $KOS_PORTS_FOLDER_NAME
exit_the_script
echo "KOS Port repo download"
cd $KOS_PORTS_FOLDER_NAME
download_submodules $KOS_PORTS_GIT_MODULES_FILE
exit_the_script
echo "Submodule download"
download_dc_chain
unpack_dc_chain
make_dc_chain
exit_the_script
echo "Make Dreamcast chain"
make_kos
echo "Make Kos"
make_kos_port
echo "Make Kos port"
}
main_function
exit 0