Skip to content

Commit

Permalink
Remove bootstrap submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
trickapm committed Sep 10, 2017
1 parent d260e67 commit 52758ee
Show file tree
Hide file tree
Showing 18 changed files with 1,486 additions and 1 deletion.
1 change: 0 additions & 1 deletion bootstrap
Submodule bootstrap deleted from 395626
Binary file added bootstrap/e2fsck
Binary file not shown.
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
184 changes: 184 additions & 0 deletions bootstrap/fang_hacks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#!/bin/sh

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

logmsg()
{
echo "$(date) - $0: $1" >> /tmp/hacks.log
echo "$1"
}

do_patch()
{
if [ ! -d "$1" ]; then
logmsg "do_patch: \"$1\" must be a directory!"
return 1
fi

if [ ! -f "$2" ]; then
logmsg "do_patch: \"$2\" must be a patch file!"
return 1
fi

old_cwd=$(pwd)
cd "$1"
patch < "$2"
rc=$?
cd "$old_cwd"
return $rc
}

do_resize()
{
logmsg "Resizing /dev/mmcblk0p2"
mount /dev/mmcblk0p1 /media/mmcblk0p1 >/dev/null 2>&1
umount /dev/mmcblk0p2 >/dev/null 2>&1
resize2fs="/media/mmcblk0p1/bootstrap/resize2fs"
e2fsck="/media/mmcblk0p1/bootstrap/e2fsck"
rc=0
if [ -x "$resize2fs" ]; then
$resize2fs -f /dev/mmcblk0p2 >/tmp/hacks.log 2>&1
rc=$?
else
echo "resize2fs not found!"
rc=1
fi

mount /dev/mmcblk0p2 /media/mmcblk0p2 >/dev/null 2>&1
if [ -e "$HACKS_HOME/.resize" ]; then
rm "$HACKS_HOME/.resize"
fi
return $rc
}

# Remove stale log
if [ -f /tmp/hacks.log ]; then
rm /tmp/hacks.log
logmsg "Removed stale logfile"
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
for i in $CGI_FILES/*; do
if [ ! -e "/tmp/www/cgi-bin/$(basename $i)" ]; then
logmsg "Linking $i -> /tmp/www/cgi-bin/$(basename $i)"
ln -sf "$i" "/tmp/www/cgi-bin/$(basename $i)"
else
logmsg "Not linking $i: already exists"
fi
done
else
logmsg "CGI scripts not found in $CGI_FILES!"
fi

if [ $HACKS_ENABLED -ne 1 ]; then
return 0
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

mount /dev/mmcblk0p2 /media/mmcblk0p2 >> /tmp/hacks.log 2>&1
if [ ! -d "$HACKS_HOME" -o ! -f "$HACKS_HOME/etc/profile" ]; then
logmsg "Failed to find $HACKS_HOME!"
return 1
else
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
# todo: apply patches?
true
fi

logmsg "Running startup scripts"
run-parts "$HACKS_HOME/etc/scripts"
logmsg "Finished"

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;
}'
18 changes: 18 additions & 0 deletions bootstrap/rc.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# Set serial number (MAC address) as default hostname
echo "Set hostname ..."
if [ ! -f /etc/hostname ]; then
echo "iSmartAlarm" > /etc/hostname
fi
/bin/hostname -F /etc/hostname

ifconfig lo up

echo 45 > /proc/sys/net/ipv4/tcp_keepalive_time
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
/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
Binary file added bootstrap/resize2fs
Binary file not shown.
Loading

0 comments on commit 52758ee

Please sign in to comment.