-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlbx_functions.sh
211 lines (157 loc) · 4.63 KB
/
lbx_functions.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
#!/bin/sh
PIRATEBOX_FOLDER=/opt/piratebox
PIRATEBOX_CONFIG="${PIRATEBOX_FOLDER}"/conf/piratebox.conf
PIRATEBOX_HOSTAPD_CONF="${PIRATEBOX_FOLDER}"/conf/hostapd.conf
FTP_CONFIG_SCRIPT="${PIRATEBOX_FOLDER}""/bin/ftp_enable.sh"
FTP_CONFIG_AVAILABLE="-e $FTP_CONFIG_SCRIPT"
### Minidlna service-file
MINIDLNA_SERVICE=minidlna
PACKAGE_LOCATION=/prebuild
### Configuration stuff
SWAP_PARTITION="/dev/mmcblk0p3"
EXT_PARTITION="/dev/mmcblk0p4"
EXT_MOUNTPOINT="/mnt/sdcard"
USB_MOUNTPOINT="/mnt/usb"
do_enable_wifi_hotspot(){
sed 's|DO_BRIDGE="no"|DO_BRIDGE="yes"|' -i $PIRATEBOX_CONFIG
sed 's|USE_APN="no"|USE_APN="yes"|' -i $PIRATEBOX_CONFIG
sed 's|PROBE_INTERFACE="no"|PROBE_INTERFACE="yes"|' -i $PIRATEBOX_CONFIG
}
do_disable_wifi_hotspot(){
sed 's|DO_BRIDGE="yes"|DO_BRIDGE="no"|' -i $PIRATEBOX_CONFIG
sed 's|USE_APN="yes"|USE_APN="no"|' -i $PIRATEBOX_CONFIG
sed 's|PROBE_INTERFACE="yes"|PROBE_INTERFACE="no"|' -i $PIRATEBOX_CONFIG
}
do_timesave_enable() {
${PIRATEBOX_FOLDER}/bin/timesave.sh ${PIRATEBOX_FOLDER}/conf/piratebox.conf install
systemctl enable cronie.service
echo "
[Unit]
Description=Restore fake RTC-time
[Service]
ExecStart=/bin/bash ${PIRATEBOX_FOLDER}/bin/timesave.sh ${PIRATEBOX_FOLDER}/conf/piratebox.conf recover
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/timesave.service
systemctl enable timesave.service
}
do_netctl_lan_to_piratebox(){
if ! netctl is-enabled lan_piratebox_bridge ; then
netctl disable lan_dhcp
netctl enable lan_piratebox_bridge
fi
}
do_netctl_lan_as_single_dhcp(){
if ! netctl is-enabled lan_dhcp ; then
netctl disable lan_piratebox_bridge
netctl enable lan_dhcp
fi
}
do_launch_ftp_setup(){
if $FTP_CONFIG_AVAILABLE ; then
. $FTP_CONFIG_SCRIPT
else
return 128
fi
}
do_swapon_step1(){
if [ -e ${SWAP_PARTITION} ] ; then
return 11
fi
fdisk /dev/mmcblk0 <<EOF
n
p
3
+256M
w
EOF
echo "
[Unit]
Description=Make SWAP Filesystem once
[Service]
ExecStart=/bin/bash /bin/cli_lbx.sh do_swapon_step2
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/make_swap.service
systemctl enable make_swap.service
}
do_swapon_step2(){
mkswap ${SWAP_PARTITION}
grep -q "${SWAP_PARTITION}" /etc/fstab || echo "${SWAP_PARTITION} none swap defaults 0 0" >> /etc/fstab
systemctl disable make_swap.service
swapon ${SWAP_PARTITION}
}
do_ext_step1(){
if [ -e ${EXT_MOUNTPOINT} ] ; then
return 11
fi
fdisk /dev/mmcblk0 <<EOF
n
p
4
w
EOF
echo "
[Unit]
Description=Create Storage Filesystem on SD-Card
[Service]
ExecStart=/bin/bash /bin/cli_lbx.sh do_ext_step2
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/make_ext.service
systemctl enable make_ext.service
}
do_ext_step2(){
mkdir -p ${EXT_MOUNTPOINT}
mkfs.ext4 ${EXT_PARTITION}
grep -q "${EXT_MOUNTPOINT}" /etc/fstab || echo "${EXT_PARTITION} ${EXT_MOUNTPOINT} auto defaults 0 0" >> /etc/fstab
systemctl disable make_ext.service
mount ${EXT_MOUNTPOINT}
}
do_enable_minidlna(){
## LibraryBox config file copy once (piratebox is the targetfolder for the logfile)
grep -q piratebox /etc/minidlna.conf || cp ${PIRATEBOX_FOLDER}/src/linux.example.minidlna.conf /etc/minidlna.conf
systemctl start $MINIDLNA_SERVICE
systemctl enable $MINIDLNA_SERVICE
}
do_disable_minidlna(){
systemctl stop $MINIDLNA_SERVICE
systemctl disable $MINIDLNA_SERVICE
}
get_installed_hostapd(){
local installed=$(pacman -Qs hostapd | head -n 1 | cut -d ' ' -f 1)
echo $installed
return 0
}
_remove_installed_hostapd(){
#get current installed
local installed_package=$( pacman -Qs hostapd | head -n 1 | cut -d ' ' -f 1)
RC=$?
if [ "$RC" = "0" ] ; then
echo "package found: $insalled_package"
pacman -dd --noconfirm -R $installed_package
return $?
fi
return $RC
}
do_switch_to_hostapd_generic(){
_remove_installed_hostapd && echo "Removed old package"
local package_path="${PACKAGE_LOCATION}"/hostapd/hostapd-?.?-*.pkg.*
pacman --noconfirm --force -U $package_path && \
sed 's#driver=.*#driver=nl80211#' -i $PIRATEBOX_HOSTAPD_CONF
return $?
}
do_switch_to_hostapd_8188eu(){
_remove_installed_hostapd && echo "Removed old package"
local package_path="${PACKAGE_LOCATION}"/hostapd/hostapd-8188eu-?.?-*.pkg.*
pacman --noconfirm --force -U $package_path && \
sed 's#driver=.*#driver=rtl871xdrv#' -i $PIRATEBOX_HOSTAPD_CONF
return $?
}
do_switch_to_hostapd_8192cu(){
_remove_installed_hostapd && echo "Removed old package"
local package_path="${PACKAGE_LOCATION}"/hostapd/hostapd-8192cu-?.?_*.pkg.*
pacman --noconfirm --force -U $package_path && \
sed 's#driver=.*#driver=rtl871xdrv#' -i $PIRATEBOX_HOSTAPD_CONF
return $?
}