Skip to content

Commit

Permalink
Update for v0.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
trickapm committed Jan 25, 2017
1 parent 04d448f commit eb493f4
Show file tree
Hide file tree
Showing 65 changed files with 1,616 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bak/
releases/
Empty file modified bootstrap/e2fsck
100644 → 100755
Empty file.
20 changes: 20 additions & 0 deletions bootstrap/fang_hacks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Configuraton parameters

# HACKS_ENABLED
# This parameter determines if the scripts on the sdcard are executed.
# When disabled, the webinterface is still available but no other modifications are made.
HACKS_ENABLED=1

# DISABLE_CLOUD
# This parameter determines if cloud apps are started at boot.
# Note you can leave this disabled and use the stop_cloud script to stop the apps after boot.
# This allows the apps to configure the network interface (NETWORK_MODE=0).
# When cloud apps are disabled and the network is configured by fang-hacks scripts (NETWORK_MODE=1 or 2),
# boot time is reduced to ~15 seconds and not dependent on cloud servers availability.
DISABLE_CLOUD=0

# NETWORK_MODE
# 0: Cloud Mode: Let cloud apps manage network
# 1: WiFi Client Mode
# 2: WiFi Access Point Mode
NETWORK_MODE=0
78 changes: 74 additions & 4 deletions bootstrap/fang_hacks.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

HACKS_ENABLED=1
HACKS_HOME=/media/mmcblk0p2/data

#####################################################
source "/etc/fang_hacks.cfg"
HACKS_ENABLED=${HACKS_ENABLED:-1}
HACKS_HOME=${HACKS_HOME:-/media/mmcblk0p2/data}

logmsg()
{
Expand Down Expand Up @@ -62,6 +61,53 @@ fi

logmsg "Executing script (enabled: $HACKS_ENABLED)"

if [ "$DISABLE_CLOUD" -eq 0 ]; then
# Wait for cloud apps to start
OS_MAJOR="$(cat /etc/os-release | cut -d'=' -f2 | cut -d'.' -f1)"
logmsg "Waiting for cloud apps..."
count=0
while [ $count -lt 30 ]; do
if [ "$OS_MAJOR" -eq 3 ]; then
if pidof iCamera >/dev/null; then logmsg "iCamera is running!"; break; fi
elif [ "$OS_MAJOR" -eq 2 ]; then
if pidof iSC3S >/dev/null; then logmsg "iSC3S is running!"; break; fi
else
logmsg "Unsupported OS version $(cat /etc/os-release)"; break;
fi
count=$(expr $count + 1)
sleep 1
done
if [ $count -eq 30 ]; then logmsg "Failed to wait for cloud apps!"; fi

# Wait for boa webserver
count=0
while [ $count -lt 30 ]; do
if pidof boa >/dev/null; then logmsg "Boa webserver is running!"; break; fi
count=$(expr $count + 1)
sleep 1
done

if ! pidof boa >/dev/null; then
# Something is wrong, perhaps cloud apps can't connect to wifi?
# Start boa manually so cgi scripts can provide recovery options
logmsg "Starting boa webserver..."
# Copy to /tmp as a workaround for weird boa error (can't open boa.conf)
cp /usr/boa/* /tmp
/tmp/boa >/dev/null 2>&1
fi

else
# Cloud disabled
logmsg "Cloud apps are disabled"
if [ ! -d /media/mmcblk0p1 ]; then mkdir /media/mmcblk0p1; fi
logmsg "Mounting /media/mmcblk0p1"
mount /dev/mmcblk0p1 /media/mmcblk0p1
logmsg "Starting boa webserver..."
# Copy to /tmp as a workaround for weird boa error (can't open boa.conf)
cp /usr/boa/* /tmp
/tmp/boa >/dev/null 2>&1
fi

# Link cgi files again if available (/tmp is volatile)
CGI_FILES="/media/mmcblk0p1/bootstrap/www"
if [ -d "$CGI_FILES" ]; then
Expand All @@ -73,6 +119,8 @@ if [ -d "$CGI_FILES" ]; then
logmsg "Not linking $i: already exists"
fi
done
else
logmsg "CGI scripts not found in $CGI_FILES!"
fi

if [ $HACKS_ENABLED -ne 1 ]; then
Expand All @@ -82,6 +130,8 @@ fi
if [ ! -d "$HACKS_HOME" -o ! -f "$HACKS_HOME/etc/profile" ]; then
logmsg "Failed to find hacks in $HACKS_HOME!"

# Maybe the hotplug is slow...
# Check resize flag so we can do that first before mounting it manually
if [ -e /etc/.resize_runonce ]; then
do_resize && rm /etc/.resize_runonce
fi
Expand All @@ -94,13 +144,33 @@ if [ ! -d "$HACKS_HOME" -o ! -f "$HACKS_HOME/etc/profile" ]; then
logmsg "Mounted $HACKS_HOME"
fi
elif [ -e /etc/.resize_runonce ]; then
# Auto-mounted, but may need to be resized
do_resize && rm /etc/.resize_runonce
fi

if [ -f "$HACKS_HOME/etc/profile" ]; then
source "$HACKS_HOME/etc/profile" >/dev/null
fi

# Configuration files are located on vfat to allow off-line editing in any OS.
# Note: originals are removed or they would overwrite any changes made in the webif,
# each time the script runs!
for i in wpa_supplicant.conf hostapd.conf udhcpd.conf; do
src="/media/mmcblk0p1/bootstrap/$i"
tgt="/media/mmcblk0p2/data/etc/$i"
if [ -e "/media/mmcblk0p1/bootstrap/$i" ]; then
logmsg "Moving $i -> $tgt"
mv "$src" "$tgt"
fi
done

src="/media/mmcblk0p1/bootstrap/fang_hacks_rescue.cfg"
tgt="/etc/fang_hacks.cfg"
if [ -e "$src" ]; then
logmsg "Overwriting configuration file $src -> $tgt"
mv "$src" "$tgt"
fi

if ! type patch >/dev/null; then
logmsg "Patch command not found! Patches will not be applied."
else
Expand Down
20 changes: 20 additions & 0 deletions bootstrap/fang_hacks_rescue.cfg.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Configuraton parameters

# HACKS_ENABLED
# This parameter determines if the scripts on the sdcard are executed.
# When disabled, the webinterface is still available but no other modifications are made.
HACKS_ENABLED=1

# DISABLE_CLOUD
# This parameter determines if cloud apps are started at boot.
# Note you can leave this disabled and use the stop_cloud script to stop the apps after boot.
# This allows the apps to configure the network interface (NETWORK_MODE=0).
# When cloud apps are disabled and the network is configured by fang-hacks scripts (NETWORK_MODE=1 or 2),
# boot time is reduced to ~15 seconds and not dependent on cloud servers availability.
DISABLE_CLOUD=0

# NETWORK_MODE
# 0: Cloud Mode: Let cloud apps manage network
# 1: WiFi Client Mode
# 2: WiFi Access Point Mode
NETWORK_MODE=0
17 changes: 17 additions & 0 deletions bootstrap/hostapd.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interface=wlan0
ctrl_interface=/var/run/hostapd
driver=rtl871xdrv
ssid=XiaoFang
beacon_int=100
hw_mode=g
ieee80211n=1
wme_enabled=1
ht_capab=[SHORT-GI-20][SHORT-GI-40]
max_num_sta=8
auth_algs=1
wpa_passphrase=XiaoFang
wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP # insecure, old clients
rsn_pairwise=CCMP
interface=wlan0
ignore_broadcast_ssid=0
46 changes: 46 additions & 0 deletions bootstrap/iwlist.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

awk '
BEGIN { OFS = "\t"; }
/\<Cell/ {
# Print previous AP
if (wpa) {
security = "WPA"
} else if (wep) {
security = "WEP"
} else {
security = "None"
}
if (essid) print essid, address, security, quality;
# Reset security flags.
wep = 0; wpa = 0;
address = $5
}
/\<ESSID:/ {
essid = substr($0, index($0, ":") + 1);
essid = substr(essid, 2, length(essid) - 2) # discard quotes
}
/\<Quality/ {
split($1, q, "[:=]"); # q[1] -> "Quality", q[2] -> value
split(q[2], qvalues, "/");
if (qvalues[2]) {
quality = int(qvalues[1] / qvalues[2] * 100); # we have both parts, divide
} else {
quality = qvalues[1]; # we have only one part, use it as-is
}
}
/\<Encryption key:(o|O)n/ { wep = 1 }
/\<IE:.*WPA.*/ { wpa = 1 }
END {
# Print last AP
if (wpa) { security = "WPA" } else { if (wep) { security = "WEP" } else { security = "None" }}
if (essid) print essid, address, security, quality;
}'
1 change: 0 additions & 1 deletion bootstrap/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ echo 3 > /proc/sys/net/ipv4/tcp_keepalive_probes
echo 5 > /proc/sys/net/ipv4/tcp_keepalive_intvl

if [ -x "/etc/fang_hacks.sh" ]; then
sleep 30
/etc/fang_hacks.sh
fi
69 changes: 69 additions & 0 deletions bootstrap/rcS
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh
source /etc/fang_hacks.cfg
DISABLE_CLOUD="${DISABLE_CLOUD:-0}"

echo "Load drivers..."

#/usr/bin/timing_cali &

modprobe snx_gpio
#modprobe snx_pwm
#modprobe snx_rtc
modprobe snx_i2s_gpio
modprobe snx_nvram

/etc/init.d/videomdprob.sh &
/etc/init.d/audmdprob.sh &

#power on sensor
/bin/gpio_ms1 -n 6 -m 1 -v 1
modprobe mt7601Usta
#modprobe snx_uvc


#modprobe snx_vo
modprobe snx_sd
if [ "$DISABLE_CLOUD" -eq 0 ]; then
modprobe snx_wdt
fi
modprobe 8188eu
#hwclock -s

if [ -f /lib/modules/2.6.35.12/kernel/drivers/bcmdhd.ko ]; then
#/bin/bcmdl -n /usr/share/WUBB-738GN_4.2/Wi-Fi/nvram_wubb-743gn.nvm /usr/share/WUBB-738GN_4.2/Wi-Fi/fw_bcm43143b0_mfg.bin.trx -C 10
/bin/bcmdl -n /usr/share/WUBB-738GN_4.2/Wi-Fi/nvram_wubb-743gn.nvm /usr/share/WUBB-738GN_4.2/Wi-Fi/cooee.bin.trx -C 10
modprobe bcmdhd
fi

# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/S??* ;do

# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue

case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done

# Here start our services
/etc/init.d/rc.local &

/usr/bin/singleBoadTest/singleBoadTest

if [ "$DISABLE_CLOUD" -eq 0 ]; then
/usr/bin/iSC3S/iSC3S &
fi
Loading

0 comments on commit eb493f4

Please sign in to comment.