-
Notifications
You must be signed in to change notification settings - Fork 1k
/
run.sh
executable file
·219 lines (191 loc) · 7.28 KB
/
run.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
219
#!/bin/sh
export LD_LIBRARY_PATH='/system/sdcard/lib/:/thirdlib:/system/lib'
CONFIGPATH="/system/sdcard/config"
LOGDIR="/system/sdcard/log"
LOGPATH="$LOGDIR/startup.log"
if [ ! -d $LOGDIR ]; then
mkdir -p $LOGDIR
fi
echo "==================================================" >> $LOGPATH
echo "Starting the Dafang Hacks Custom Application Layer" >> $LOGPATH
echo "==================================================" >> $LOGPATH
## Stop telnet for security reasons
killall telnetd
## Load some common functions:
. /system/sdcard/scripts/common_functions.sh
echo "Loaded common functions" >> $LOGPATH
## Create root user home directory and etc directory on sdcard:
if [ ! -d /system/sdcard/root ]; then
mkdir /system/sdcard/root
echo 'PATH=/system/sdcard/bin:$PATH' > /system/sdcard/root/.profile
echo "Created root user home directory" >> $LOGPATH
fi
mkdir -p /system/sdcard/etc
while IFS= read -r etc_element
do
if [ ! -f "/system/sdcard/etc/$etc_element" ] && [ ! -d "/system/sdcard/etc/$etc_element" ]; then
cp -fRL "/etc/$etc_element" /system/sdcard/etc
fi
done <<- END
TZ
protocols
fstab
inittab
init.d
hosts
group
resolv.conf
hostname
profile
os-release
sensor
webrtc_profile.ini
END
echo "Created etc directory on sdcard" >> $LOGPATH
mount -o bind /system/sdcard/bin/busybox /bin/busybox
echo "Bind mounted /system/sdcard/bin/busybox to /bin/busybox" >> $LOGPATH
mount -o bind /system/sdcard/root /root
echo "Bind mounted /system/sdcard/root to /root" >> $LOGPATH
mount -o bind /system/sdcard/etc /etc
echo "Bind mounted /system/sdcard/etc to /etc" >> $LOGPATH
## Create a swap file on SD if desired
SWAP=false
SWAPPATH="/system/sdcard/swapfile"
SWAPSIZE=256
if [ "$SWAP" = true ]; then
if [ ! -f $SWAPPATH ]; then
echo "Creating ${SWAPSIZE}MB swap file on SD card" >> $LOGPATH
dd if=/dev/zero of=$SWAPPATH bs=1M count=$SWAPSIZE
mkswap $SWAPPATH
echo "Swap file created in $SWAPPATH" >> $LOGPATH
fi
echo "Configuring swap file" >> $LOGPATH
swapon $SWAPPATH
echo "Swap set on file $SWAPPATH" >> $LOGPATH
fi
## Create crontab dir and start crond:
if [ ! -d /system/sdcard/config/cron ]; then
mkdir -p ${CONFIGPATH}/cron/crontabs
CRONPERIODIC="${CONFIGPATH}/cron/periodic"
echo ${CONFIGPATH}/cron/crontabs/periodic
# Wish busybox sh had brace expansion...
mkdir -p ${CRONPERIODIC}/15min \
${CRONPERIODIC}/hourly \
${CRONPERIODIC}/daily \
${CRONPERIODIC}/weekly \
${CRONPERIODIC}/monthly
cat > ${CONFIGPATH}/cron/crontabs/root <<EOF
# min hour day month weekday command
*/15 * * * * busybox run-parts ${CRONPERIODIC}/15min
0 * * * * busybox run-parts ${CRONPERIODIC}/hourly
0 2 * * * busybox run-parts ${CRONPERIODIC}/daily
0 3 * * 6 busybox run-parts ${CRONPERIODIC}/weekly
0 5 1 * * busybox run-parts ${CRONPERIODIC}/monthly
EOF
echo "Created cron directories and standard interval jobs" >> $LOGPATH
fi
/system/sdcard/bin/busybox crond -L /system/sdcard/log/crond.log -c /system/sdcard/config/cron/crontabs
## Set Hostname
if [ ! -f $CONFIGPATH/hostname.conf ]; then
cp $CONFIGPATH/hostname.conf.dist $CONFIGPATH/hostname.conf
fi
hostname -F $CONFIGPATH/hostname.conf
if [ -f $CONFIGPATH/usb_eth_driver.conf ]; then
## Start USB Ethernet:
echo "USB_ETHERNET: Detected USB config. Loading USB Ethernet driver" >> $LOGPATH
insmod /system/sdcard/driver/usbnet.ko
insmod /system/sdcard/driver/asix.ko
ifconfig eth0 up
udhcpc_status=$(udhcpc -i eth0 -p /var/run/udhcpc.pid -b -x hostname:"$(hostname)")
else
## Start Wifi:
if [ ! -f $CONFIGPATH/wpa_supplicant.conf ]; then
echo "Warning: You have to configure wpa_supplicant in order to use wifi. Please see /system/sdcard/config/wpa_supplicant.conf.dist for further instructions."
fi
MAC=$(grep MAC < /params/config/.product_config | cut -c16-27 | sed 's/\(..\)/\1:/g;s/:$//')
if [ -f /driver/8189es.ko ]; then
# Its a DaFang
insmod /driver/8189es.ko rtw_initmac="$MAC"
elif [ -f /driver/8189fs.ko ]; then
# Its a XiaoFang T20
insmod /driver/8189fs.ko rtw_initmac="$MAC"
else
# Its a Wyzecam V2
insmod /driver/rtl8189ftv.ko rtw_initmac="$MAC"
fi
wpa_supplicant_status="$(wpa_supplicant -d -B -i wlan0 -c $CONFIGPATH/wpa_supplicant.conf -P /var/run/wpa_supplicant.pid)"
echo "wpa_supplicant: $wpa_supplicant_status" >> $LOGPATH
udhcpc_status=$(udhcpc -i wlan0 -p /var/run/udhcpc.pid -b -x hostname:"$(hostname)")
fi
echo "udhcpc: $udhcpc_status" >> $LOGPATH
## Sync the via NTP:
if [ ! -f $CONFIGPATH/ntp_srv.conf ]; then
cp $CONFIGPATH/ntp_srv.conf.dist $CONFIGPATH/ntp_srv.conf
fi
ntp_srv="$(cat "$CONFIGPATH/ntp_srv.conf")"
timeout -t 30 sh -c "until ping -c1 \"$ntp_srv\" &>/dev/null; do sleep 3; done";
/system/sdcard/bin/busybox ntpd -p "$ntp_srv"
## Load audio driver module:
insmod /system/sdcard/driver/audio.ko
## Initialize the GPIOS:
for pin in 25 26 38 39 49; do
init_gpio $pin
done
# the ir_led pin is a special animal and needs active low
echo 1 > /sys/class/gpio/gpio49/active_low
echo "Initialized gpios" >> $LOGPATH
## Set leds to default startup states:
ir_led off
ir_cut on
yellow_led off
blue_led on
## Load motor driver module:
insmod /driver/sample_motor.ko
# Don't calibrate the motors for now as for newer models the endstops don't work:
# motor hcalibrate
# motor vcalibrate
# calibrate,compatible newer models.(But the old DAFANG does not work.)
# motor calibrate
## Determine the image sensor model:
insmod /system/sdcard/driver/sinfo.ko
echo 1 >/proc/jz/sinfo/info
sensor=$(grep -m1 -oE 'jxf[0-9]*$' /proc/jz/sinfo/info)
echo "Determined image sensor model as $sensor" >> $LOGPATH
## Start the image sensor:
insmod /driver/tx-isp.ko isp_clk=100000000
if [ $sensor = 'jxf22' ]; then
insmod /driver/sensor_jxf22.ko data_interface=2 pwdn_gpio=-1 reset_gpio=18 sensor_gpio_func=0
else
insmod /driver/sensor_jxf23.ko data_interface=2 pwdn_gpio=-1 reset_gpio=18 sensor_gpio_func=0
fi
## Start FTP & SSH Server:
dropbear_status=$(/system/sdcard/bin/dropbearmulti dropbear -R)
echo "dropbear: $dropbear_status" >> $LOGPATH
bftpd_status=$(/system/sdcard/bin/bftpd -d)
echo "bftpd: $bftpd_status" >> $LOGPATH
## Create a certificate for the webserver
if [ ! -f $CONFIGPATH/lighttpd.pem ]; then
export OPENSSL_CONF=$CONFIGPATH/openssl.cnf
/system/sdcard/bin/openssl req -new -x509 -keyout $CONFIGPATH/lighttpd.pem -out $CONFIGPATH/lighttpd.pem -days 365 -nodes -subj "/C=DE/ST=Bavaria/L=Munich/O=.../OU=.../CN=.../emailAddress=..."
chmod 400 $CONFIGPATH/lighttpd.pem
echo "Created new certificate for webserver" >> $LOGPATH
fi
## Start Webserver:
if [ ! -f $CONFIGPATH/lighttpd.conf ]; then
cp $CONFIGPATH/lighttpd.conf.dist $CONFIGPATH/lighttpd.conf
fi
lighttpd_status=$(/system/sdcard/bin/lighttpd -f /system/sdcard/config/lighttpd.conf)
echo "lighttpd: $lighttpd_status" >> $LOGPATH
## Configure OSD:
if [ -f /system/sdcard/controlscripts/configureOsd ]; then
. /system/sdcard/controlscripts/configureOsd 2>/dev/null
fi
## Configure Motion:
if [ -f /system/sdcard/controlscripts/configureMotion ]; then
. /system/sdcard/controlscripts/configureMotion 2>/dev/null
fi
## Autostart all enabled services:
for i in /system/sdcard/config/autostart/*; do
$i
done
echo "Startup finished!" >> $LOGPATH