2013-05-14 15:09:56 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-05-14 16:09:01 +02:00
|
|
|
### This function makes sure the 'wlan' net is in the 'lan' zone
|
2013-05-14 15:09:56 +02:00
|
|
|
addFirewallNet() {
|
|
|
|
cfgChanged=0; zoneNum=-1; i=0
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-05-14 15:09:56 +02:00
|
|
|
while true; do
|
|
|
|
name=`uci get firewall.@zone[$i].name 2>&1`
|
|
|
|
exists=`echo "$name" | grep "Entry not found" >/dev/null 2>&1; echo $?`
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-05-14 15:09:56 +02:00
|
|
|
if [ $exists -eq 0 ]; then break; fi
|
2013-06-28 12:39:48 +02:00
|
|
|
if [ "x$name" = "xlan" ]; then zoneNum=$i; fi
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-05-14 15:09:56 +02:00
|
|
|
i=`expr $i + 1`
|
|
|
|
done
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-05-14 15:09:56 +02:00
|
|
|
if [ $zoneNum -gt -1 ]; then
|
|
|
|
network=`uci get firewall.@zone[$zoneNum].network 2>&1`
|
|
|
|
hasWlan=`echo $network | grep "wlan" >/dev/null 2>&1; echo $?`
|
|
|
|
if [ $hasWlan -eq 1 ]; then
|
|
|
|
uci set firewall.@zone[$zoneNum].network="lan wlan"
|
|
|
|
uci commit firewall
|
|
|
|
/etc/init.d/dnsmasq reload
|
|
|
|
cfgChanged=1
|
|
|
|
fi
|
|
|
|
fi
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-05-14 15:09:56 +02:00
|
|
|
if [ $cfgChanged -eq 1 ]; then
|
|
|
|
echo "Added network 'wlan' to zone lan."
|
|
|
|
else
|
|
|
|
echo "Firewall configuration not changed."
|
|
|
|
fi
|
|
|
|
}
|
2013-05-03 01:09:46 +02:00
|
|
|
|
|
|
|
|
2013-05-14 16:09:01 +02:00
|
|
|
### Replace the banner with a custom one
|
2013-08-01 16:29:17 +02:00
|
|
|
if [ ! -f $IPKG_INSTROOT/etc/banner.default ]; then
|
|
|
|
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
|
2016-02-29 17:35:17 +01:00
|
|
|
cat <<-\EOM > $IPKG_INSTROOT/etc/banner
|
2016-05-22 01:03:40 +02:00
|
|
|
,------. ,--.,--. ,----. ,------.
|
|
|
|
| .-. \ ,---. ,---. ,-| || | ,---. '.-. || .-. \
|
|
|
|
| | \ :| .-. || .-. |' .-. || || .-. : .' < | | \ :
|
|
|
|
| '--' /' '-' '' '-' '\ `-' || |\ --./'-' || '--' /
|
|
|
|
`-------' `---' `---' `---' `--' `----'`----' `-------'
|
|
|
|
__ ___ ______ _ ____
|
|
|
|
\ \ / (_) ____(_) | _ \
|
|
|
|
\ \ /\ / / _| |__ _ ______| |_) | _____ __
|
|
|
|
\ \/ \/ / | | __| | |______| _ < / _ \ \/ /
|
|
|
|
\ /\ / | | | | | | |_) | (_) > <
|
|
|
|
\/ \/ |_|_| |_| |____/ \___/_/\_\
|
2013-05-03 01:09:46 +02:00
|
|
|
EOM
|
|
|
|
fi
|
2013-05-14 15:09:56 +02:00
|
|
|
|
2013-08-01 16:29:17 +02:00
|
|
|
### Add some convenience aliases to root's profile
|
2013-08-20 22:38:16 +02:00
|
|
|
mkdir -p $IPKG_INSTROOT/root
|
2013-08-01 16:29:17 +02:00
|
|
|
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
|
|
|
|
if [ $? -gt 0 ]; then
|
2016-02-29 17:35:17 +01:00
|
|
|
cat <<-\EOM >> $IPKG_INSTROOT/root/.profile
|
2013-05-03 01:09:46 +02:00
|
|
|
# DO NOT MODIFY - this block of lines has been added by the wifibox package.
|
2013-10-08 16:55:50 +02:00
|
|
|
alias d='ls -la'
|
2013-07-04 17:26:13 +02:00
|
|
|
alias d3dapi='/usr/share/lua/wifibox/script/d3dapi'
|
2013-05-03 01:09:46 +02:00
|
|
|
alias encore='ulimit -c unlimited'
|
2013-07-29 12:17:08 +02:00
|
|
|
alias wopkg='opkg -f /usr/share/lua/wifibox/opkg.conf'
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2016-02-29 17:35:17 +01:00
|
|
|
alias tailfw='loglite /tmp/wifibox.log firmware'
|
|
|
|
tailp3d() {
|
|
|
|
logfile=/tmp/print3d-ttyACM0.log
|
|
|
|
if [ $# -gt 0 ]; then logfile=$1; fi
|
|
|
|
loglite "$logfile" print3d
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:55:50 +02:00
|
|
|
loop() {
|
2016-02-29 17:35:17 +01:00
|
|
|
if [ $# -lt 2 ]; then echo "Please supply a delay and a command."; return 1; fi
|
|
|
|
DELAY=$1; shift; while true; do $@; sleep $DELAY; done
|
2013-10-08 16:55:50 +02:00
|
|
|
}
|
2013-05-03 01:09:46 +02:00
|
|
|
EOM
|
|
|
|
fi
|
|
|
|
|
2013-10-28 19:38:53 +01:00
|
|
|
#preserve saved sketches during firmware update
|
2013-12-04 15:44:47 +01:00
|
|
|
echo "/root/sketches" >> $IPKG_INSTROOT/etc/sysupgrade.conf
|
2013-10-28 19:38:53 +01:00
|
|
|
|
2016-03-18 11:31:07 +01:00
|
|
|
|
|
|
|
|
2013-05-14 16:09:01 +02:00
|
|
|
### Finally make sure basic configuration is set correctly
|
|
|
|
|
2016-03-29 14:34:58 +02:00
|
|
|
LOGROTATE_CRON_LINE="*/2 * * * * /usr/sbin/logrotate /etc/logrotate.conf"
|
2013-08-16 21:44:54 +02:00
|
|
|
|
2013-07-04 17:26:13 +02:00
|
|
|
if [ -z "$IPKG_INSTROOT" ]; then
|
2016-01-05 18:25:38 +01:00
|
|
|
# No installation root, we are being installed on a live box so run uci commands directly.
|
|
|
|
|
2014-03-08 23:24:00 +01:00
|
|
|
echo "Enabling and configuring wifi device..."
|
2014-01-31 22:39:36 +01:00
|
|
|
uci set wireless.@wifi-device[0].disabled=0
|
2015-06-12 16:02:35 +02:00
|
|
|
uci delete wireless.radio0.channel
|
2014-01-31 22:39:36 +01:00
|
|
|
uci commit wireless; wifi
|
2013-05-14 11:34:55 +02:00
|
|
|
|
2014-03-08 23:24:00 +01:00
|
|
|
echo "Disabling default route and DNS server for lan network interface..."
|
|
|
|
uci set dhcp.lan.dhcp_option='3 6'
|
|
|
|
uci commit dhcp; /etc/init.d/dnsmasq reload
|
|
|
|
|
2013-07-04 17:26:13 +02:00
|
|
|
addFirewallNet
|
2013-05-14 11:34:55 +02:00
|
|
|
|
2013-07-04 17:26:13 +02:00
|
|
|
echo "Adding network interface 'wlan'..."
|
2014-03-08 23:24:00 +01:00
|
|
|
uci set network.wlan=interface
|
|
|
|
uci commit network; /etc/init.d/network reload
|
2016-01-05 18:25:38 +01:00
|
|
|
|
|
|
|
echo "Setting default wifibox log level..."
|
|
|
|
uci set wifibox.general.system_log_level='info'
|
|
|
|
uci -q delete wifibox.system.loglevel # remove key used in older versions (<=0.10.8a) if it exists
|
|
|
|
uci commit wifibox
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2016-03-18 11:31:07 +01:00
|
|
|
crontab -l 2> /dev/null | grep logrotate\.conf > /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
# add line, method from http://askubuntu.com/a/58582
|
|
|
|
# Note: `crontab -l` will throw an error to stderr because the file does not exist, but that does not matter
|
|
|
|
(crontab -l 2> /dev/null; echo "$LOGROTATE_CRON_LINE" ) | crontab -
|
|
|
|
fi
|
|
|
|
|
2013-07-04 17:26:13 +02:00
|
|
|
else
|
2016-01-05 18:25:38 +01:00
|
|
|
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0.
|
|
|
|
|
2013-08-01 16:29:17 +02:00
|
|
|
cat <<-EOM >> $IPKG_INSTROOT/etc/uci-defaults/setup-wifibox.sh
|
|
|
|
uci set system.@system[0].hostname=wifibox
|
2013-08-16 22:11:09 +02:00
|
|
|
uci set system.@system[0].log_size=64
|
2013-08-01 16:29:17 +02:00
|
|
|
uci set network.lan.ipaddr=192.168.5.1
|
|
|
|
echo -e "beta\nbeta" | passwd root
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-08-22 18:34:45 +02:00
|
|
|
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
|
|
|
|
uci set uhttpd.main.lua_prefix='/d3dapi'
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-08-01 16:29:17 +02:00
|
|
|
uci set wireless.@wifi-device[0].disabled=0
|
2015-06-12 16:02:35 +02:00
|
|
|
uci delete wireless.radio0.channel
|
2013-08-01 16:29:17 +02:00
|
|
|
# TODO: add firewall net
|
|
|
|
uci set network.wlan=interface
|
2014-03-08 23:24:00 +01:00
|
|
|
|
|
|
|
uci set dhcp.lan.dhcp_option='3 6'
|
2016-01-05 18:25:38 +01:00
|
|
|
|
|
|
|
uci set wifibox.general.system_log_level='info'
|
|
|
|
uci -q delete wifibox.system.loglevel # remove key used in older versions (<=0.10.8a) if it exists
|
2016-01-06 17:25:54 +01:00
|
|
|
|
2016-03-18 11:31:07 +01:00
|
|
|
crontab -l 2> /dev/null | grep logrotate\.conf > /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
# add line, method from http://askubuntu.com/a/58582
|
|
|
|
# Note: `crontab -l` will throw an error to stderr because the file does not exist, but that does not matter
|
|
|
|
(crontab -l 2> /dev/null; echo "$LOGROTATE_CRON_LINE" ) | crontab -
|
|
|
|
fi
|
|
|
|
|
2016-01-06 17:25:54 +01:00
|
|
|
exit 0
|
2013-08-01 16:29:17 +02:00
|
|
|
EOM
|
2013-10-08 16:55:50 +02:00
|
|
|
|
2013-08-01 16:29:17 +02:00
|
|
|
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
|
2013-07-04 17:26:13 +02:00
|
|
|
fi
|
2013-05-14 17:26:21 +02:00
|
|
|
|
2016-03-18 11:31:07 +01:00
|
|
|
$IPKG_INSTROOT/etc/init.d/wifibox enable
|
|
|
|
$IPKG_INSTROOT/etc/init.d/wifibox start
|
|
|
|
$IPKG_INSTROOT/etc/init.d/dhcpcheck enable
|
|
|
|
$IPKG_INSTROOT/etc/init.d/cron enable
|
|
|
|
$IPKG_INSTROOT/etc/init.d/cron start
|
|
|
|
|
2013-05-14 17:26:21 +02:00
|
|
|
exit 0
|