-
Notifications
You must be signed in to change notification settings - Fork 3
/
retrorig-es-setup
executable file
·454 lines (376 loc) · 11.5 KB
/
retrorig-es-setup
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
#!/bin/bash
############################################################################
# RetroRig-ES Main Setup Script
# This is a small script to copy over configuration files for emulators
# append a "-x" on the end above for debugging if need be
# Version 0.3.0
#
# Note: Syscalls are now abstracted!
# Please see syscalls-<pkg_mgr>.shinc for more.
#
# Please report any errors via a pull request
# You can also reach me on twitter: @N3RD42
#
############################################################################
clear
#set up errmsgs and postmsgs
__ERRMSGS=""
__postMSGs=""
######################################
# Start Helper Functions
######################################
#set -o nounset
function getScriptAbsoluteDir() {
# @description used to get the script path
# @param $1 the script $0 parameter
local script_invoke_path="$1"
local cwd=$(pwd)
# absolute path ? if so, the first character is a /
if test "x${script_invoke_path:0:1}" = 'x/'
then
RESULT=$(dirname "$script_invoke_path")
else
RESULT=$(dirname "$cwd/$script_invoke_path")
fi
}
function import() {
# @description importer routine to get external functionality.
# @description the first location searched is the script directory.
# @description if not found, search the module in the paths contained in $SHELL_LIBRARY_PATH environment variable
# @param $1 the .shinc file to import, without .shinc extension
module=$1
if [ -f $module.shinc ]; then
source $module.shinc
echo "Loaded module $(basename $module.shinc)"
return
fi
if test "x$module" == "x"
then
echo "$script_name : Unable to import unspecified module. Dying."
exit 1
fi
if test "x${script_absolute_dir:-notset}" == "xnotset"
then
echo "$script_name : Undefined script absolute dir. Did you remove getScriptAbsoluteDir? Dying."
exit 1
fi
if test "x$script_absolute_dir" == "x"
then
echo "$script_name : empty script path. Dying."
exit 1
fi
if test -e "$script_absolute_dir/$module.shinc"
then
# import from script directory
. "$script_absolute_dir/$module.shinc"
echo "Loaded module $script_absolute_dir/$module.shinc"
return
elif test "x${SHELL_LIBRARY_PATH:-notset}" != "xnotset"
then
# import from the shell script library path
# save the separator and use the ':' instead
local saved_IFS="$IFS"
IFS=':'
for path in $SHELL_LIBRARY_PATH
do
if test -e "$path/$module.shinc"
then
. "$path/$module.shinc"
return
fi
done
# restore the standard separator
IFS="$saved_IFS"
fi
echo "$script_name : Unable to find module $module"
exit 1
}
function loadConfig()
{
# @description Routine for loading configuration files that contain key-value pairs in the format KEY="VALUE"
# param $1 Path to the configuration file relate to this file.
local configfile=$1
if test -e "$script_absolute_dir/$configfile"
then
. "$script_absolute_dir/$configfile"
echo "Loaded configuration file $script_absolute_dir/$configfile"
return
else
echo "Unable to find configuration file $script_absolute_dir/$configfile"
exit 1
fi
}
########################################################################
#
# setDesktopEnvironment()
#
# Arguments: Desktop folder identifier used in
# Unity/Gnome/Cinnamonin/Deepin Desktop ~/.config/user-dirs.dirs.
#
# Description: The command to set a folder variable is already
# contained in ~/.config/user-dirs.dirs. For example:
#
# XDG_DOWNLOAD_DIR="$HOME/Downloads"
#
# This script filters the related line and
# sets the corresponding variable with lower
# case letters:
#
# xdg_download_dir=/home/username/Downloads
#
########################################################################
function setDesktopEnvironment()
{
arg_upper_case=$1
arg_lower_case=`echo $1|tr '[:upper:]' '[:lower:]'`
XDG_DIR="XDG_"$arg_upper_case"_DIR"
xdg_dir="xdg_"$arg_lower_case"_dir"
setDir=`cat $home/.config/user-dirs.dirs | grep $XDG_DIR| sed s/$XDG_DIR/$xdg_dir/|sed s/HOME/home/`
target=`echo $setDir| cut -f 2 -d "="| sed s,'$home',$home,`
checkValid=`echo $setDir|grep $xdg_dir=\"|grep home/`
if [ -n "$checkValid" ]; then
eval "$setDir"
else
echo "local desktop setting" $XDG_DIR "not found"
fi
}
script_invoke_path="$0"
script_name=$(basename "$0")
getScriptAbsoluteDir "$script_invoke_path"
script_absolute_dir=$RESULT
if [ "$script_invoke_path" == "/usr/bin/retrorig-es-setup" ]; then
#install method via system folder
scriptdir=/usr/share/RetroRig-ES
else
#install method from local git clone
scriptdir=`dirname "$script_absolute_dir"`
fi
# load script modules
echo "#####################################################"
echo "Loading script modules"
echo "#####################################################"
import "$scriptdir/scriptmodules/helpers"
import "$scriptdir/scriptmodules/configuration"
import "$scriptdir/scriptmodules/settings"
import "$scriptdir/scriptmodules/setup"
import "$scriptdir/scriptmodules/gamepads"
import "$scriptdir/scriptmodules/emulators"
import "$scriptdir/scriptmodules/emulators-source"
# DEBUG ONLY!
# Remove the below comment to double check all modules load
# sleep 10s
echo "#####################################################"
echo "Checking compatibility"
echo "#####################################################"
# Discover platform
rrs_discover_distro
# Source the correct distro/plaform for syscalls
rrs_source_syscalls
######################################
# Start main script
######################################
if [[ "$1" == "--help" ]]; then
rrs_showHelp
exit 0
fi
if [ "$(id -u)" -ne 0 ]; then
printf "Script must be run as root! Try:"
echo ""
echo ""
printf "'sudo retrorig-es-setup'"
echo ""
echo "OR (for a git cloned version of RetroRig in its base directory)"
printf "'sudo ./retrorig-es-setup.sh'"
echo ""
echo "OR "
printf "'retrorig-es-setup --help'"
echo ""
echo ""
printf "for further information\n"
exit 1
fi
# if called with sudo ./retrorig_setup.sh, the installation directory is /$HOME/CURRENTUSER/RetroRig for the current user
# if called with sudo ./retrorig_setup.sh USERNAME, the installation directory is /$HOME/USERNAME/RetroRig for user USERNAME
# if called with sudo ./retrorig_setup.sh USERNAME ABSPATH, the installation directory is ABSPATH for user USERNAME
# We need to set "$home" for two reasons:
# 1. $HOME is a system reserved var
# 2. This path is needs to copy the dotfile configuration to the "real" home folder.
if [[ $# -lt 1 ]]; then
user=$SUDO_USER
if [ -z "$user" ]
then
user=$(whoami)
fi
rootdir=/home/$user/RetroRig-ES
elif [[ $# -lt 2 ]]; then
user=$1
rootdir=/home/$user/RetroRig-ES
elif [[ $# -lt 3 ]]; then
user=$1
rootdir=$2
fi
if [[ $user == "root" ]]; then
echo "Please start the RetroRig-ES Setup Script not as user 'root', but, e.g., as user 'pi'."
exit
fi
home=$(eval echo ~$user)
#################################################################
#
# *** Setting up local desktop folder structure ***
#
# Example for German Desktop:
#
# setup $xdg_desktop_dir to "/home/username/Schreibtisch"
# setup $xdg_download_dir to "/home/username/Downloads"
# setup $xdg_templates_dir to "/home/username/Vorlagen"
# setup $xdg_publicshare_dir to "/home/username/Öffentlich"
# setup $xdg_documents_dir to "/home/username/Dokumente"
# setup $xdg_music_dir to "/home/username/Musik"
# setup $xdg_pictures_dir to "/home/username/Bilder"
# setup $xdg_videos_dir to "/home/username/Videos"
#
#################################################################
setDesktopEnvironment DESKTOP
setDesktopEnvironment DOWNLOAD
setDesktopEnvironment TEMPLATES
setDesktopEnvironment PUBLICSHARE
setDesktopEnvironment DOCUMENTS
setDesktopEnvironment MUSIC
setDesktopEnvironment PICTURES
setDesktopEnvironment VIDEOS
#################################################################
#################################################################
# Pre-configuration
#
# as show the banner. Pre-reqs are checked and ammened if
# possible.
#
#################################################################
# make sure that RetroRig root directory exists
if [[ ! -d $rootdir ]]; then
mkdir -p "$rootdir"
chown $user:$user "$rootdir"
chgrp "$user" "$rootdir"
if [[ ! -d $rootdir ]]; then
echo "Couldn't make directory $rootdir"
exit 1
fi
fi
# make sure that RetroRig-Setup log directory exists
if [[ ! -d $rootdir/logs ]]; then
mkdir -p "$rootdir/logs"
chown "$user" "$rootdir/logs"
chgrp "$user" "$rootdir/logs"
if [[ ! -d $rootdir/logs ]]; then
echo "Couldn't make directory $rootdir/logs"
exit 1
fi
fi
# check for pre-requisites, output to log folder
rrs_prereq
# Show lame logo
# subtitle 1
clear
COLUMNS=$(tput cols)
title1="Welcome To"
printf "%*s\n" $(((${#title1}+$COLUMNS)/2)) "$title1"
figlet -c "_.RetroRig ES._"
echo ""
# subtitle 2
COLUMNS=$(tput cols)
title2="www.libregeek.org"
printf "%*s\n" $(((${#title2}+$COLUMNS)/2)) "$title2"
sleep 2s
# set the directory '$home/.retrorig-es' as a variable for easy reading
es_home="$home/.retrorig-es/.emulationstation"
# set config_home for all the dotfiles that need copied down for emulators
# and other utilities
config_home="$home/.retrorig-es"
#set RetroRig configuration file
configFile=$config_home/retrorig-es.cfg
cd "$rootdir"
#################################################################
while true; do
cmd=(dialog --backtitle "LibreGeek.org RetroRig-ES
Installer" --menu "| Main Menu (v.0.3.0) | \
BIOS files are NOT provided!" 17 62 16)
options=(1 "Install RetroRig-ES"
2 "RetroRig-ES Settings"
3 "Pull latest files from git"
4 "Update emulator binaries"
5 "Update core software"
6 "Update system"
7 "Upgrade system (Use with caution)"
8 "Reboot PC"
9 "Uninstall RetroRig-ES"
10 "Exit")
#make menu choice
# Expanding arrays involves [@] and {}
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
if [ "$choices" != "" ]; then
case $choices in
1)
now=$(date +'%d%m%Y_%H%M%S')
h_autosave_configs
rrs_prepareFolders
rrs_software
rrs_retrorig_cfgs
rrs_es_setup
rrs_gamepad
h_emu_user_fixes
set_resolution
rrs_post_install
rrs_done
# Removed - new logging needs added if possible.
# clean and fixup log file
#tr -cd '\11\12\15\40-\176' < "$rootdir/logs/temp_log.txt" > "$rootdir/logs/install_$now.log.txt"
#chown -R "$user" "$rootdir/logs/install_$now.log.txt"
#chgrp -R "$user" "$rootdir/logs/install_$now.log.txt"
kernelUpdate=`cat $rootdir/logs/kernelUpdate`
rm -f "$rootdir/logs/kernelUpdate"
if [ "$kernelUpdate" == "true" ]; then
rrs_reboot
fi
;;
2)
set_menu
;;
3)
h_update_git
;;
4)
rrs_emulators
;;
5)
rrs_software
;;
6)
h_update_system
;;
7)
h_upgrade_system
;;
8)
rrs_reboot
;;
9)
cfg_uninstall
;;
10)
clear
exit
;;
255)
# Next two lines for debugging only
# dialog --infobox "Esc hit..." 3 14
# sleep 1s
;;
esac
else
# Next two lines for debugging only
# dialog --infobox "cancel hit" 3 14
# sleep 1s
break
fi
done
clear