forked from RetroPie/RetroPie-Setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retropie_setup.sh
executable file
·218 lines (190 loc) · 6.53 KB
/
retropie_setup.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
#!/bin/bash
# RetroPie-Setup - Shell script for initializing Raspberry Pi
# with RetroArch, various cores, and EmulationStation (a graphical
# front end).
#
# (c) Copyright 2012-2013 Florian Müller ([email protected])
#
# RetroPie-Setup homepage: https://github.com/petrockblog/RetroPie-Setup
#
# Permission to use, copy, modify and distribute RetroPie-Setup in both binary and
# source form, for non-commercial purposes, is hereby granted without fee,
# providing that this license information and copyright notice appear with
# all copies and any derived work.
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event shall the authors be held liable for any damages
# arising from the use of this software.
#
# RetroPie-Setup is freeware for PERSONAL USE only. Commercial users should
# seek permission of the copyright holders first. Commercial use includes
# charging money for RetroPie-Setup or software derived from RetroPie-Setup.
#
# The copyright holders request that bug fixes and improvements to the code
# should be forwarded to them so everyone can benefit from the modifications
# in future versions.
#
# Many, many thanks go to all people that provide the individual packages!!!
#
# Raspberry Pi is a trademark of the Raspberry Pi Foundation.
#
__ERRMSGS=""
__INFMSGS=""
__doReboot=0
# 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
}
script_invoke_path="$0"
script_name=`basename "$0"`
getScriptAbsoluteDir "$script_invoke_path"
script_absolute_dir=$RESULT
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 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 $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
}
# load script modules
import "scriptmodules/helpers"
import "scriptmodules/raspbianconfig"
import "scriptmodules/emulators"
import "scriptmodules/libretrocores"
import "scriptmodules/supplementary"
import "scriptmodules/setup"
import "scriptmodules/retropiesetup"
# END HELPER FUNCTIONS ###
######################################
# here starts the main loop ##########
######################################
scriptdir=`dirname $0`
scriptdir=`cd $scriptdir && pwd`
rps_checkNeededPackages
if [[ "$1" == "--help" ]]; then
showHelp
exit 0
fi
if [ $(id -u) -ne 0 ]; then
printf "Script must be run as root. Try 'sudo ./retropie_setup' or ./retropie_setup --help for further information\n"
exit 1
fi
# if called with sudo ./retropie_setup.sh, the installation directory is /home/CURRENTUSER/RetroPie for the current user
# if called with sudo ./retropie_setup.sh USERNAME, the installation directory is /home/USERNAME/RetroPie for user USERNAME
# if called with sudo ./retropie_setup.sh USERNAME ABSPATH, the installation directory is ABSPATH for user USERNAME
if [[ $# -lt 1 ]]; then
user=$SUDO_USER
if [ -z "$user" ]
then
user=$(whoami)
fi
rootdir=/home/$user/RetroPie
elif [[ $# -lt 2 ]]; then
user=$1
rootdir=/home/$user/RetroPie
elif [[ $# -lt 3 ]]; then
user=$1
rootdir=$2
fi
if [[ $user == "root" ]]; then
echo "Please start the RetroPie Setup Script not as user 'root', but, e.g., as user 'pi'."
exit
fi
esscrapimgw=275 # width in pixel for EmulationStation games scraper
home=$(eval echo ~$user)
if [[ ! -d $rootdir ]]; then
mkdir -p "$rootdir"
if [[ ! -d $rootdir ]]; then
echo "Couldn't make directory $rootdir"
exit 1
fi
fi
rps_availFreeDiskSpace 800000
while true; do
cmd=(dialog --backtitle "PetRockBlock.com - RetroPie Setup. Installation folder: $rootdir for user $user" --menu "Choose installation either based on binaries or on sources." 22 76 16)
options=(1 "Binaries-based INSTALLATION (faster, but possibly not up-to-date)"
2 "Source-based INSTALLATION (slower, but up-to-date versions)"
3 "SETUP (only if you already have run one of the installations above)"
4 "UPDATE RetroPie Setup script"
5 "UPDATE RetroPie Binaries"
6 "UNINSTALL RetroPie installation"
7 "Perform REBOOT" )
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
if [ "$choices" != "" ]; then
case $choices in
1) rps_main_binaries ;;
2) rps_main_options ;;
3) rps_main_setup ;;
4) rps_main_updatescript ;;
5) rps_downloadBinaries ;;
6) rc_removeAPTPackages ;;
7) rps_main_reboot ;;
esac
else
break
fi
done
if [[ $__doReboot -eq 1 ]]; then
dialog --title "The firmware has been updated and a reboot is needed." --clear \
--yesno "Would you like to reboot now?\
" 22 76
case $? in
0)
rps_main_reboot
;;
*)
;;
esac
fi
clear