-
Notifications
You must be signed in to change notification settings - Fork 1
/
librarybox-config
executable file
·265 lines (222 loc) · 7.36 KB
/
librarybox-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
#!/bin/sh
#### Based upon raspi-config
## Part of raspi-config http://github.com/asb/raspi-config
##
## See LICENSE file for copyright and license details
## (c)2014 Matthias Strubel [email protected]
# GPL
DEBUG=1
INTERACTIVE=True
ASK_TO_REBOOT=0
. $(dirname $0)/lbx_functions.sh
calc_wt_size() {
# NOTE: it's tempting to redirect stderr to /dev/null, so supress error
# output from tput. However in this case, tput detects neither stdout or
# stderr is a tty and so only gives default 80, 24 values
WT_HEIGHT=20
WT_WIDTH=$(tput cols)
if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
WT_WIDTH=80
fi
if [ "$WT_WIDTH" -gt 178 ]; then
WT_WIDTH=120
fi
WT_MENU_HEIGHT=$(($WT_HEIGHT-8))
}
do_finish(){
if [ $ASK_TO_REBOOT -eq 1 ]; then
whiptail --yesno "Would you like to reboot now?" 20 60 2
if [ $? -eq 0 ]; then # yes
sync
reboot
fi
fi
exit
}
# Everything else needs to be run as root
if [ $(id -u) -ne 0 ] && [ ! $DEBUG ] ; then
printf "Script must be run as root. Try 'sudo raspi-config'\n"
exit 1
fi
run_about(){
echo "TODO"
exit
}
run_enable_wifi_hotspot(){
do_enable_wifi_hotspot
ASK_TO_REBOOT=1
whiptail --msgbox "LibraryBox Configuration changed, Enabled Wifi" 20 60 1
return 0
}
run_disable_wifi_hotspot(){
do_disable_wifi_hotspot
ASK_TO_REBOOT=1
whiptail --msgbox "LibraryBox Configuration changed, Disabled Wifi" 20 60 1
return 0
}
run_change_pass_root() {
whiptail --msgbox "You will now be asked to enter a new password for the root user" 20 60 1
passwd &&
whiptail --msgbox "Password changed successfully" 20 60 1
}
run_timesave(){
do_timesave_enable
whiptail --msgbox "Timesave function setup and initialized, Remeber setup date&time" 20 60 1
}
run_dateTime(){
in_time=$(whiptail --inputbox "Setup time, use format HH:mm:ss" 20 60 'HH:mm:ss' 3>&1 1>&2 2>&3 )
in_date=$(whiptail --inputbox "Setup date, use format YYYY-MM-dd" 20 60 'YYYY-MM-dd' 3>&1 1>&2 2>&3 )
echo "${in_date}${in_time}"
[[ $DEBUG ]] || date -s "${in_date} ${in_time}"
}
run_lbx_ftp_config(){
/opt/piratebox/bin/ftp_enable.sh
}
run_minidlna_toggle(){
MINIDLNA_STATUS=$(systemctl is-enabled minidlna)
if [ "$MINIDLNA_STATUS" = "disabled" ] ; then
do_enable_minidlna
if [ $? -eq 0 ] ; then
whiptail --msgbox "Minidlna enabled" 20 70 1
else
whiptail --msgbox "There was an error during enabling minidlna ..." 20 70 1
fi
else
do_disable_minidlna
if [ $? -eq 0 ] ; then
whiptail --msgbox "Minidlna disabled" 20 70 1
else
whiptail --msgbox "There was an error during disabling minidlna ..." 20 70 1
fi
fi
}
_test_netctl_status_() {
local profile=$1
if netctl is-enabled lan_dhcp 2>&1 >> /dev/null ; then
echo "on"
else
echo "off"
fi
return 0
}
run_ethernet_setup(){
local lan_dhcp_enbled=$( _test_netctl_status_('lan_dhcp' ) )
local lan_piratebox_enbled=$( _test_netctl_status_('lan_piratebox_bridge' ) )
local NETCTL=$(whiptail --title "LibraryBox ethernet selection - ArchLinux" --radiolist "Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
"1 PirateBox " "Ethernet included to LibraryBox Adress distribution" $lan_piratebox_enbled \
"2 DHCP" "Use Ethernet port independend from LibraryBox" $lan_dhcp_enbled \
3>&1 1>&2 2>&3 )
local RET=$?
if [ "$RET" = "1" ]; then
return 0
elif [ "$RET" = "0" ]; then
case "$NETCTL" in
1\ *) do_netctl_lan_to_piratebox ;;
2\ *) do_netctl_lan_as_single_dhcp ;;
esac || whiptail --msgbox "There was an error running option $NETCTL" 20 60 1
ASK_TO_REBOOT=1
else
whiptail --msgbox "Unknown function $NETCTL" 20 60 1
return 1
fi
return 0
}
run_wifi_dongle_select(){
local usb_wifi_search=$(lsusb | grep 802)
whiptail --msgbox "Found the following USB wifi (only simple indication):
${usb_wifi_search}
take a notice down on a paper for the next step.
If that is empty, you have to checkout google for you wifi stick, which chipset is included.
You can use the command 'lsusb' on the command line to get the list of connected devices.
" 20 70 9
local enabled_package=$( get_installed_hostapd )
local status_generic='off'
local status_8818eu='off'
local status_8192cu='off'
case "$enabled_package" in
"local/hostapd") status_generic='on';;
"local/hostapd-8188eu") status_8818eu='on';;
"local/hostapd-8192cu") status_8192cu='on';;
esac
local WIFI=$(whiptail --title "LibraryBox hostpad selection - ArchLinux" --radiolist "Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
"1 Generic" "Install a generic USB hostapd (default)" $status_generic \
"2 8818eu " "Switch to USB with Realtek 8818eu based chipset" $status_8818eu \
"3 8192cu" "Switch to USB with Realtek 8192cu based chipset" $status_8192cu \
3>&1 1>&2 2>&3 )
local RET=$?
if [ "$RET" = "1" ]; then
return 0
elif [ "$RET" = "0" ]; then
case "$WIFI" in
1\ *) do_switch_to_hostapd_generic ;;
2\ *) do_switch_to_hostapd_8188eu ;;
3\ *) do_switch_to_hostapd_8192cu ;;
esac || whiptail --msgbox "There was an error running option $WIFI" 20 60 1
ASK_TO_REBOOT=1
else
whiptail --msgbox "Unknown function $WIFI" 20 60 1
return 1
fi
}
#
# Launch confirmation menu for SD Card setup and run the steps.
#
do_sd_card(){
whiptail --title "LibraryBox SD Card - Setup" --yesno "Do you want to setup the SD-Card?" 20 60
RC=$?
if [ "$RC" = "0" ] ; then
# run setup steps
do_swapon_step1
if [ "$?" = "11" ] ; then
whiptail --title "LibraryBox SD Card - Setup" --msgbox "Swap partition already exists" 20 60 1
fi
do_ext_step1
if [ "$?" = "11" ] ; then
whiptail --title "LibraryBox SD Card - Setup" --msgbox "Data partition already exists" 20 60 1
fi
ASK_TO_REBOOT=1
else
return 0
fi
}
#
# Interactive use loop
#
calc_wt_size
while true; do
MINIDLNA_STATUS=$(systemctl is-enabled minidlna)
FUN=$(whiptail --title "LibraryBox Configuration Tool - ArchLinux" --menu "Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
"1 Enable USB Wifi" "Enables USB wifi including a Wait-Time; Reboot required" \
"2 Disable USB Wifi" "Disabled enabled wifi setup; Reboot required" \
"3 Date&Time" "Setup Date and Time" \
"4 Timesave" "Setup Fake RTC and init. cron" \
"5 FTP-Config" "Launch FTP LibraryBox Setup" \
"6 Minidlna startup" " ${MINIDLNA_STATUS} ; Toggle it" \
"7 Ethernet port" "Change setup of ethernet port" \
"8 Change hostapd (WIFI)" "Needed for some wifi drivers" \
"9 Change root password" "Changes default password for root user" \
"10 SD-Card prepare" "Create & format swap and data partition." \
"F About librarybox-config" "Information about this tool" \
3>&1 1>&2 2>&3 )
RET=$?
if [ $RET -eq 1 ]; then
do_finish
elif [ $RET -eq 0 ]; then
case "$FUN" in
1\ *) run_enable_wifi_hotspot ;;
2\ *) run_disable_wifi_hotspot ;;
3\ *) run_dateTime ;;
4\ *) run_timesave ;;
5\ *) run_lbx_ftp_config ;;
6\ *) run_minidlna_toggle ;;
7\ *) run_ethernet_setup ;;
8\ *) run_wifi_dongle_select ;;
9\ *) run_change_pass_root ;;
10\ *) run_sd_card ;;
F\ *) run_about ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
else
exit 1
fi
echo $RET - $FUN
done