-
Notifications
You must be signed in to change notification settings - Fork 3
/
xbian-config
executable file
·294 lines (242 loc) · 6.66 KB
/
xbian-config
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
#!/bin/bash
#
#Copyright 2012 - 2013 CurlyMo & mk01 <development@xbian.org>
#
#This file is part of XBian - XBMC on the Raspberry Pi.
#
#XBian is free software: you can redistribute it and/or modify it under the
#terms of the GNU General Public License as published by the Free Software
#Foundation, either version 3 of the License, or (at your option) any later
#version.
#
#XBian is distributed in the hope that it will be useful, but WITHOUT ANY
#WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
#details.
#
#You should have received a copy of the GNU General Public License along
#with XBian. If not, see <http://www.gnu.org/licenses/>
#
# This will only allow xbian-config to be run as root
if [ ! $(id -u) -eq 0 ]; then
echo "This program must be run as root.";
exit 0;
fi
# Disable [ctrl]-c and [ctrl]-z actions
trap '' 2 20
#|------------------------------------|
#| Global variables |
#|------------------------------------|
# Title at the top of the dialog windows
BACKTITLE="XBian $(cat /etc/xbian_version)";
# Check if a reboot is needed
ASKFORREBOOT=0;
# Check if the package database needs to be updates
LOCALPKGDBUPDATED=0;
REMOTEPKGDBUPDATED=0;
APTUPDATELISTUPDATED=0;
# Standard delimiter
ORIGINALIFS=$IFS;
# Url for the main APT repository Package location
APTBASE="http://apt.xbian.org/"
# Location of the xbian-config script files
BASEPATH="/usr/local/include/xbian-config"
#Set GUI language
LANGUAGE="en"
#Check if xbian-config is run in GUI mode
GUIMODE=1;
#|------------------------------------|
#| Main program |
#|------------------------------------|
function showMainCloseDlg() {
DOREBOOT=0;
umount /boot
# Is a reboot needed for the changes to get effect
if [ $ASKFORREBOOT -eq 1 ]; then
wrapTxtFn "$(_ main.reboot_question)"
centerTxtFn "$WRAPPEDTXT"
valignTxtFn "$CENTEREDTXT"
showConfirmDlg "$ALIGNEDTXT";
# 0: Do reboot
# 1: Don't reboot
case "$?" in
0)
DOREBOOT=1;
;;
esac
fi
# Clear FS and MEM caches
clrFSCacheFn;
clrMemCacheFn;
if [ $DOREBOOT -eq 1 ]; then
reboot
fi;
exit 0
}
function showMainMenuDlg() {
mountpoint -q /boot || mount /boot
ITEMS="";
LEVEL="";
ADD=".";
CPATH=$(_ main.title);
# Do different things depending on which level we are
if [ $1 -gt 0 ]; then
# Show descendant
LEVEL="$2";
ADD=".";
fi
# Prepare path
if [ $# -gt 2 ]; then
CPATH=$3;
fi
# Trim CPATH
trimLnFn $CPATH
CPATH=$TRIMMEDLN;
# Draw showMainMenuDlg
IFS=$'\n';
# Get all sub-items that corresponding to the level we are currently
ITEMS=$(grep "^$LEVEL$ADD[0-9]*:" $BASEPATH/struct | cut -f 2 -d:);
# Clear caches need by previous function
clrMemCacheFn;
# Create main menu
# If a certain menu items has no subitems, than we've reach of final function we want to execute
if [ -z "$ITEMS" ]; then
# Grab the system name of the module we want to execute
SPECIFICLEVEL=${LEVEL:0:-1};
MODULE=$(grep ^$SPECIFICLEVEL: $BASEPATH/struct | cut -f2 -d:);
# Include the module we want to execute
source $BASEPATH/modules/$MODULE/main
# Change the dialog title to reflect the current module
TITLE="[${CPATH% > *} > $(_ $MODULE.name)]"
# Open the modules gui function
showGUIFn;
# When we're done, show the main menu again
IFS=$'\n';
showMainMenuDlg $(($1-1)) ${LEVEL:0:-2} ${CPATH% > *};
else
MENU="";
I=1;
for ITEM in ${ITEMS[@]}; do
MENU+="$I%$(_ ${ITEM}.name)!-!\"$(_ $ITEM.description)\"%";
I=$(($I+1));
done;
IFS="%";
# Set the title to the appropriate menu level we're in
TITLE="["$CPATH"]"
# Stop the loader
if [ $(ps -A | grep $LOADER | wc -l) -gt 0 ]; then
kill -9 $LOADER > /dev/null 2>&1 &
wait $! 2>/dev/null
fi
# Show the main menu
if [ $1 -eq 0 ]; then
showMenuDlg "" "$MENU" 7 11 $(($DEFAULTWIDTH+15)) $(_ dialog.select) $(_ dialog.exit);
else
showMenuDlg "" "$MENU" 7
fi
# What there a button pressed?
# 1: Button
# 0: Item
CODE=$?
if [ $CODE -eq 1 ]; then
# Which button was pressed?
# 0: Close
# 1: Select
if [ $1 -eq 0 ]; then
showMainCloseDlg;
else
IFS=$'\n';
showMainMenuDlg $(($1-1)) ${LEVEL:0:-2} ${CPATH% > *};
fi
elif [ $CODE -eq 0 ]; then
IFS=$'\n';
MODULE=$(grep "^$LEVEL$RETURN*:" $BASEPATH/struct | cut -f 2 -d:)
showMainMenuDlg $(($1+1)) $LEVEL$RETURN$ADD "$CPATH > $(_ $MODULE.name)";
fi;
fi;
}
if [ $# -eq 0 ]; then
#|------------------------------------|
#| GUI Mode |
#|------------------------------------|
LOADER=0;
while [ $(pgrep dialog | wc -l) -eq 0 ]; do
for a in \\ \| \/ -; do
if [ $(pgrep dialog | wc -l) -eq 0 ]; then
echo -n $a;
sleep 0.5;
echo -n -e \\r;
else
break;
fi
done;
done &
LOADER=$!
#|------------------------------------|
#| Include files |
#|------------------------------------|
# Common xbian-config functions
source $BASEPATH/functions/packages
# Pre-requirements
source $BASEPATH/prereqs
# Standard dialogs
source $BASEPATH/functions/dialogs
# Text markup
source $BASEPATH/functions/markup
# System functions
source $BASEPATH/functions/system
# Language functions
source $BASEPATH/functions/language
#|------------------------------------|
#| Global variables |
#|------------------------------------|
# Current dialog title
TITLE="[$_TITLE]"
#Run script inside screen, so it's doesn't fill the whole terminal history
#SCREEN=$(screen -r | grep "Attached" | wc -l);
#if [ $SCREEN -eq 0 ]; then
# `screen $0`
#else
showMainMenuDlg 0 "";
#fi
else
#|------------------------------------|
#| CLI Mode |
#|------------------------------------|
#|------------------------------------|
#| Include files |
#|------------------------------------|
# System functions
#source $BASEPATH/functions/system
#clrMemCacheFn;
GUIMODE=0;
# Check xbian-config was opened using arguments
MODULE=$1;
if [ $MODULE == "reboot" ]; then
if [ -f /tmp/xbian-config-reboot ]; then
cat /tmp/xbian-config-reboot;
else
echo 0;
fi;
elif [ -f $BASEPATH/modules/$MODULE/main ]; then
source $BASEPATH/modules/$MODULE/main
shift;
# If the module was called with arguments
if [ $# -gt 0 ]; then
# Check if it's a valid argument
case "${ARGUMENTS[@]}" in
*"$1"*)
# Quotation marks to preserve newlines
showCMDFn "$@"
;;
*)
echo "Available arguments for module '$MODULE' are:";
echo ${ARGUMENTS[@]};
;;
esac
else
echo "Available arguments for module '$MODULE' are:";
echo ${ARGUMENTS[@]};
fi
fi
fi