Imported sources from subversion.

This commit is contained in:
Ricardo Martins
2013-07-13 17:19:22 +01:00
commit 12d63d1569
455 changed files with 69857 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
root:x:0:
nobody:x:99:

View File

@@ -0,0 +1,5 @@
::sysinit:/sbin/services sysinit
::restart:/sbin/init
terminal::respawn:-/bin/sh
::respawn:-/usr/sbin/dropbear -F
::shutdown:/sbin/services syshalt

View File

@@ -0,0 +1,2 @@
root:$1$mMOnsRbs$uHQG3j4uyr6kX19n5VkkT1:0:0:root:/root:/bin/sh
nobody:x:99:99:nobody:/:/bin/false

View File

@@ -0,0 +1,3 @@
#! /bin/sh
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH

View File

@@ -0,0 +1,15 @@
start()
{
dmesg | grep 'ACPI: reboot needed'
if [ $? -eq 0 ]; then
echo 'Rebooting to enable ACPI'
reboot
else
echo 'ACPI enabled'
fi
}
stop()
{
echo ''
}

View File

@@ -0,0 +1,10 @@
start()
{
mount -t debugfs debugfs /sys/kernel/debug &&
# UART1.
echo 0 > /sys/kernel/debug/omap_mux/uart1_txd &&
echo 20 > /sys/kernel/debug/omap_mux/uart1_rxd &&
umount /sys/kernel/debug
}

View File

@@ -0,0 +1,57 @@
dune_base='/opt/lsts/dune'
if [ -z "$cfg_dune" ]; then
cfg_dune="$(hostname)"
fi
maybe_upgrade()
{
if ! [ -f $dune_base/dune-*.tar.bz2 ]; then
return 1
fi
echo -n "* Starting DUNE upgrade... "
rm -rf $dune_base/.dune-upgrade &&
mkdir $dune_base/.dune-upgrade &&
tar -x -C $dune_base/.dune-upgrade -f $dune_base/dune-*.tar.bz2 &&
rm $dune_base/dune-*.tar.bz2 &&
for dir in $dune_base/.dune-upgrade/dune-*/*; do
d="$(basename "$dir")"
rm -rf "$dune_base/$d"
mv "$dir" $dune_base
done
rm -rf $dune_base/.dune-upgrade
echo "done"
}
start()
{
echo "$dune_base/log/core.%t" > /proc/sys/kernel/core_pattern
maybe_upgrade
$dune_base/bin/dune-launcher -m -p Hardware -c "$cfg_dune" < /dev/null > /dev/null 2>&1 &
}
stop()
{
while [ 1 ]; do
echo "* Stopping process..."
killall dune-launcher > /dev/null 2>&1
killall dune > /dev/null 2>&1
for r in 0 1 2 3 4 5 6 7 8 9; do
if [ -n "$(pidof dune)" ]; then
echo "* Waiting for process to exit ($r)..."
sleep 1
else
echo "* Process not running."
return 1
fi
done
echo "* Forcing exit..."
killall -9 dune-launcher > /dev/null 2>&1
killall -9 dune > /dev/null 2>&1
sleep 1
done
}

View File

@@ -0,0 +1,13 @@
start()
{
/opt/lsts/dune/bin/dune-gsmux \
/dev/ttyO1 \
/opt/lsts/dune/log \
< /dev/null \
>> /opt/lsts/dune/log/gsmux.log 2>&1 &
}
stop()
{
killall dune-gsmux
}

View File

@@ -0,0 +1,9 @@
start()
{
/sbin/huawei-monitor > /dev/null 2>&1 &
}
stop()
{
echo ""
}

View File

@@ -0,0 +1,9 @@
start()
{
/usr/sbin/inetd
}
stop()
{
killall inetd
}

View File

@@ -0,0 +1,17 @@
start()
{
dmesg | grep microcode_updated
if [ $? -ne 0 ]; then
echo -en 'Waiting for system to settle '
for x in 0 1 2; do echo -en '.'; sleep 1; done
cmd_line="$(dmesg | grep "command line:" | cut -f2- -d: | sed 's/noapic//g')"
/sbin/microcode_ctl -u &&
/sbin/kexec -l /boot/kernel --append "$cmd_line microcode_updated" &&
/sbin/kexec -e
fi
}
stop()
{
echo ""
}

View File

@@ -0,0 +1,192 @@
#! /bin/sh
#############################################################################
# Copyright (C) 2012 Laboratório de Sistemas e Tecnologia Subaquática #
# Departamento de Engenharia Electrotécnica e de Computadores #
# Rua Dr. Roberto Frias, 4200-465 Porto, Portugal #
#############################################################################
# Author: Ricardo Martins #
#############################################################################
GSM_USER='vodafone'
GSM_PASS='vodafone'
GSM_APN='internet.vodafone.pt'
GSM_MODE='AT\^SYSCFG=2,2,3fffffff,0,1'
GSM_PIN='AT'
FWL_EXT_ITF='ppp0'
FWL_INT_ITF='eth0'
CHAT_SCRIPT=$(cat <<EOF
ABORT 'BUSY' \
ABORT 'NO CARRIER' \
ABORT 'VOICE' \
ABORT 'NO DIALTONE' \
ABORT 'NO DIAL TONE' \
ABORT 'NO ANSWER' \
ABORT 'DELAYED' \
REPORT CONNECT \
TIMEOUT 6 \
'' 'ATQ0' \
'OK-AT-OK' 'ATZ' \
TIMEOUT 3 \
'OK' '$GSM_PIN' \
'OK-AT-OK' 'ATI' \
'OK' 'ATZ' \
'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' \
'OK' '$GSM_MODE' \
'OK-AT-OK' 'AT+CGDCONT=1,\"IP\",\"$GSM_APN\"' \
'OK' 'ATDT*99***1#' \
TIMEOUT 30 \
CONNECT ''
EOF
)
modem_probe()
{
nr="$(cat /proc/tty/driver/usbserial | grep GSM | head -n 1 | cut -f1 -d:)"
if [ -z "$nr" ]; then
echo ""
else
echo "/dev/ttyUSB$nr"
fi
}
ppp_start()
{
modem="$(modem_probe)"
if [ -z "$modem" ]; then
echo -e "\nERROR: failed to find GSM modem.\n"
exit 1
fi
auth=''
if [ -n "$GSM_USER" ] && [ -n "$GSM_PASS" ]; then
auth="user \"$GSM_USER\" password \"$GSM_PASS\""
fi
echo -e "\n* Removing default route"
/sbin/route del default dev eth0 > /dev/null 2>&1
echo -e "\n* Starting PPP"
/usr/sbin/pppd \
"$modem" \
921600 \
$auth \
lock \
crtscts \
modem \
passive \
novj \
defaultroute \
noipdefault \
usepeerdns \
noauth \
hide-password \
persist \
holdoff 10 \
maxfail 2 \
updetach \
connect "/usr/sbin/chat -E -v -t15 $CHAT_SCRIPT" > /var/run/ppp.log 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: PPP failed to establish a connection.\n"
exit 1
fi
ip=$(ifconfig ppp0 | grep inet | cut -f2 -d: | cut -f1 -d' ')
echo " - External IP is $ip"
}
ppp_stop()
{
pid="$(cat /var/run/ppp0.pid 2> /dev/null)"
echo -e "\n* Stopping PPP"
if [ -z "$pid" ]; then
echo " - Daemon is not running"
return 0
fi
for n in 1 2 3 4 5; do
if ! [ -d "/proc/$pid" ]; then
echo " - Daemon stopped"
return 0
fi
echo " - Sending SIGTERM to '$pid' (try $n)"
kill "$pid" > /dev/null 2>&1
sleep 2
done
kill -9 "$pid" > /dev/null 2>&1
echo " - Daemon terminated"
return 0
}
nat_start()
{
echo -e "\n* Enabling NAT"
echo " - Enabling IP forwarding"
echo '1' > /proc/sys/net/ipv4/ip_forward
echo '1' > /proc/sys/net/ipv4/ip_dynaddr
echo " - Flushing rules"
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F
echo " - Installing rules"
iptables -A FORWARD -i "$FWL_EXT_ITF" -o "$FWL_INT_ITF" -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i "$FWL_EXT_ITF" -o "$FWL_EXT_ITF" -j ACCEPT
iptables -A FORWARD -i "$FWL_EXT_ITF" -o "$FWL_INT_ITF" -j ACCEPT
iptables -A FORWARD -i "$FWL_INT_ITF" -o "$FWL_EXT_ITF" -j ACCEPT
iptables -A FORWARD -j LOG
iptables -t nat -A POSTROUTING -o "$FWL_EXT_ITF" -j MASQUERADE
}
nat_stop()
{
echo -e "\n* Disabling NAT"
echo " - Disabling IP forwarding"
echo '0' > /proc/sys/net/ipv4/ip_forward
echo '0' > /proc/sys/net/ipv4/ip_dynaddr
echo " - Flushing NAT rules"
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F
}
start()
{
ppp_start && nat_start
if [ $? -eq 0 ]; then
echo -e "\n* Connection Established\n"
else
echo -e "\nERROR: failed to establish a connection\n"
fi
}
stop()
{
nat_stop && ppp_stop
if [ $? -eq 0 ]; then
echo -e "\n* Service stopped\n"
else
echo -e "\nERROR: failed to stop service.\n"
fi
}

View File

@@ -0,0 +1,65 @@
start()
{
if [ -n "$cfg_bridge0_ip" ]; then
for itf in $cfg_bridge0_itfs; do
ifconfig $itf 0.0.0.0
done
brctl addbr bridge0
for itf in $cfg_bridge0_itfs; do
brctl addif bridge0 $itf
done
ifconfig bridge0 $cfg_bridge0_ip netmask $cfg_bridge0_nmask up
ifconfig bridge0 multicast
route add -net 224.0.0.0 netmask 240.0.0.0 dev bridge0
fi
# Public ethernet.
if [ -n "$cfg_eth_ext_ip" ]; then
if [ -n "$cfg_eth_ext_mk" ]; then
ifconfig eth0 "$cfg_eth_ext_ip" netmask "$cfg_eth_ext_mk" up
else
ifconfig eth0 "$cfg_eth_ext_ip" up
fi
ifconfig eth0 multicast
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
# Fixed mac address with $cfg_eth_ext_mac based derivated from IP address $cfg_eth_ext_ip
if [ -n "$cfg_eth_ext_mac" ]; then
ifconfig eth0 hw ether $cfg_eth_ext_mac
fi
fi
if [ -n "$cfg_eth_ext_gw" ]; then
route add default gw "$cfg_eth_ext_gw"
fi
if [ -n "$cfg_eth_ext_dns" ]; then
echo "nameserver $cfg_eth_ext_dns" > /etc/resolv.conf
fi
# Private ethernet.
if [ -n "$cfg_eth_prv_ip" ]; then
ifconfig eth0:prv "$cfg_eth_prv_ip" up
fi
}
stop()
{
# Public ethernet.
if [ -n "$cfg_eth_ext_gw" ]; then
route del default
fi
if [ -n "$cfg_eth_ext_ip" ]; then
route del -net 224.0.0.0 netmask 240.0.0.0 dev eth0
ifconfig eth0 down
fi
# Private ethernet.
if [ -n "$cfg_eth_prv_ip" ]; then
ifconfig eth0:prv down
fi
}

View File

@@ -0,0 +1,9 @@
start()
{
/usr/bin/ldattach PPS "$cfg_pps_attach_dev"
}
stop()
{
killall ldattach
}

View File

@@ -0,0 +1,15 @@
start()
{
if ! [ -f /etc/setserial.cfg ]; then
return 0
fi
while read line; do
/bin/setserial $line
done < /etc/setserial.cfg
}
stop()
{
return 0
}

View File

@@ -0,0 +1,41 @@
start()
{
for unit in $cfg_storage; do
label="$(echo $unit | cut -f1 -d:)"
fstype="$(echo $unit | cut -f2 -d:)"
point="$(echo $unit | cut -f3 -d:)"
if ! [ -d "$point" ]; then
mkdir -p "$point"
fi
n=0; while [ $n -lt 20 ]; do
args=''
if [ $fstype = 'ext3' ]; then
args='-o noatime,data=ordered'
fi
mount -t $fstype $args LABEL="$label" "$point"
if [ $? -eq 0 ]; then
break;
fi
sleep 1
let n++
done
done
}
stop()
{
units=''
for unit in $cfg_storage; do
units="$unit $units"
done
for unit in $units; do
point="$(echo $unit | cut -f3 -d:)"
echo "* Unmounting $point..."
umount "$point"
done
}

View File

@@ -0,0 +1,50 @@
syslog_base='/opt/lsts/glued'
syslog_pid='/var/run/syslog.pid'
start()
{
if ! [ -d "$syslog_base" ]; then
mkdir -p "$syslog_base"
fi
/sbin/klogd -n -c 8 < /dev/null > /dev/null &
kpid="$!"
/sbin/syslogd -n -l 8 -s 256 -b 5 -O "$syslog_base/system.log" < /dev/null > /dev/null &
spid="$!"
echo "$kpid $spid" > "$syslog_pid"
}
stop()
{
echo -n "* Terminating syslog... "
pids="$(cat "$syslog_pid" 2> /dev/null)"
rm "$syslog_pid" 2> /dev/null
if [ -z "$pids" ]; then
echo "DONE"
return 0
fi
for t in 1 2 3; do
kill "$pids" > /dev/null 2>&1
echo -n "$t "
usleep 500000
ok=1
for pid in $pids; do
if [ -f "/proc/$pid/stat" ]; then
ok=0
fi
done
if [ $ok -eq 1 ]; then
echo "DONE"
return 0
fi
done
echo "K"
kill -9 "$pids"
}

View File

@@ -0,0 +1,168 @@
#! /bin/sh
#############################################################################
# Copyright (C) 2007-2009 Laboratório de Sistemas e Tecnologia Subaquática #
# Departamento de Engenharia Electrotécnica e de Computadores #
# Rua Dr. Roberto Frias, 4200-465 Porto, Portugal #
#############################################################################
# Author: Ricardo Martins #
#############################################################################
# $Id:: upgrade 1244 2012-10-08 07:21:07Z rasm $:#
#############################################################################
base='/opt/lsts/glued'
hostname="$(hostname)"
flashcp='/usr/sbin/flashcp'
scratch="$base/.glued"
clean()
{
if [ -d "$base"/.glued-new ]; then
rm -rf "$base"/.glued-new
fi
if [ -d "$base"/.glued-old ]; then
rm -rf "$base"/.glued-old
fi
}
version()
{
file="$(ls -1 $base/glued-*-*-rootfs.tar.bz2 2> /dev/null | head -n 1)"
if [ -z "$file" ]; then
return 1
fi
# Filter version.
ver="$(echo $file | sed "s%$base/glued-%%")"
ver="$(echo $ver | sed "s%-$hostname-bundle\.tar%%")"
export fw_version="$ver"
export fw_file="$file"
return 0
}
new_unpack()
{
echo -n "* Unpacking new rootfs... "
mkdir ${base}/.glued-new
tar -C ${base}/.glued-new -x -f "$fw_file"; rv=$?
if [ -d /etc/dropbear ]; then
cp -a /etc/dropbear ${base}/.glued-new/etc
fi
if [ $rv -eq 0 ]; then
rm "$fw_file"
echo "done"
return 0
fi
echo "failed"
return 1
}
kernel_dst()
{
echo -n "* Detecting kernel destination... "
# Kernel resides in the root filesystem.
if [ -d /boot/extlinux ]; then
echo "filesystem"
return 0
fi
if ! [ -f /proc/mtd ]; then
echo "filesystem"
return 0
fi
grep 'uboot=ext2' /proc/cmdline > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "filesystem"
return 0
fi
export fw_kernel_mtd="$(grep \"kernel\" /proc/mtd | cut -f1 -d':')"
if [ -z "$fw_kernel_mtd" ]; then
export fw_kernel_mtd="$(grep \"Kernel\" /proc/mtd | cut -f1 -d':')"
if [ -z "$fw_kernel_mtd" ]; then
echo "failed to detect kernel's MTD partition"
return 1
fi
fi
echo "mtd"
return 0
}
kernel_upgrade()
{
# Upgrade MTD
if [ -n "$fw_kernel_mtd" ]; then
echo -n "* Upgrading kernel... "
"$flashcp" -v "$base/.glued-new/boot/kernel" /dev/"$fw_kernel_mtd" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "failed"
return 1
fi
echo "done"
return 0
fi
}
old_move()
{
echo "* Mounting rootfs read-write..."
mount -o remount,rw /
echo "* Unmounting pseudo filesystems..."
umount /sys
umount /dev/pts
umount /dev/shm
umount /proc
if [ -f /boot/extlinux/extlinux.sys ]; then
/bin/chattr -i /boot/extlinux/extlinux.sys
fi
echo "* Moving old rootfs..."
mkdir $base/.glued-old &&
mv /bin /boot /etc /init /lib /proc /root /sbin /sys /tmp /usr /var $base/.glued-old &&
$base/.glued-old/bin/echo "* Moving new rootfs into place..." &&
$base/.glued-old/bin/busybox cp -a $base/.glued-new/* / &&
$base/.glued-old/bin/echo "* Mounting procfs..." &&
$base/.glued-old/bin/busybox mount -t proc proc /proc &&
if [ -d "/boot/extlinux" ]; then
$base/.glued-old/usr/sbin/extlinux -i /boot/extlinux
fi
$base/.glued-old/bin/echo "* Flushing filesystem cache... "
$base/.glued-old/bin/busybox sync
$base/.glued-old/bin/busybox sync
$base/.glued-old/bin/busybox sync
$base/.glued-old/bin/busybox sync
$base/.glued-old/bin/busybox sync
$base/.glued-old/bin/echo "* Preparing reboot... "
$base/.glued-old/bin/busybox mount -o remount,ro /opt
$base/.glued-old/bin/busybox umount /proc
$base/.glued-old/bin/busybox touch /.reboot
$base/.glued-old/bin/busybox kill -SIGQUIT 1
exit 0
}
start()
{
clean
version || return 1
kernel_dst || return 1
new_unpack || return 1
kernel_upgrade || return 1
old_move || return 1
}
stop()
{
echo -n ""
}

View File

@@ -0,0 +1,4 @@
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
ntp 123/tcp # Network Time Protocol
ntp 123/udp # Network Time Protocol

View File

@@ -0,0 +1,15 @@
#! /bin/sh
modem_vid='12d1'
modem_pid='1446'
while [ 1 ]; do
vid=$(grep "$modem_vid" /sys/bus/usb/devices/?-?*/idVendor)
pid=$(grep "$modem_pid" /sys/bus/usb/devices/?-?*/idProduct)
if [ -n "$vid" ] && [ -n "$pid" ]; then
/usr/bin/uswitch "$modem_vid" "$modem_pid"
fi
sleep 5
done

View File

@@ -0,0 +1,116 @@
#! /bin/sh
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
. /etc/config
if [ -z "$cfg_tmpfs_size" ]; then
cfg_tmpfs_size='2097152'
fi
if [ -z "$cfg_min_free_kbytes" ]; then
cfg_min_free_kbytes='8192'
fi
sysinit()
{
if [ -f /.reboot ]; then
mount -t proc proc /proc
mount -o remount,rw /
rm /.reboot
mount -o remount,ro /
reboot
return 0
fi
# Mount pseudo-filesystems.
mount -t sysfs sysfs /sys &&
mount -t proc proc /proc &&
mkdir /dev/shm /dev/pts &&
mount -t tmpfs -o size="$cfg_tmpfs_size" tmpfs /dev/shm &&
mount -t devpts devpts /dev/pts &&
# Register mdev as hotplug event handler.
echo >/dev/mdev.seq &&
echo /sbin/mdev > /proc/sys/kernel/hotplug &&
# Update ld cache, populate /dev.
# mount -o remount,rw / &&
/sbin/mdev -s &&
# /sbin/ldconfig &&
# mount -o remount,ro / &&
# Set minimum free kbytes.
echo "$cfg_min_free_kbytes" > /proc/sys/vm/min_free_kbytes &&
# Set hostname.
hostname "$cfg_hostname" &&
# Loopback device.
ifconfig lo 127.0.0.1 netmask 255.0.0.0 up &&
# Load modules.
modprobe -a $cfg_modules $cfg_modules1
# Start services.
for service in $cfg_services0 $cfg_services1 $cfg_services2; do
. /etc/rc.d/$service
start
done
}
syshalt()
{
if [ -f /.reboot ]; then
return 0
fi
srv=''
for s in $cfg_services0 $cfg_services1 $cfg_services2; do
srv="$s $srv"
done
for s in $srv; do
. /etc/rc.d/$s
stop
done
umount -r /dev/pts /dev/shm /sys / /proc
}
service()
{
. /etc/rc.d/"$1"
case "$2" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 4
start
;;
*)
echo "Usage: $0 <service> [start,stop,restart]"
exit 1
;;
esac
}
case "$1" in
sysinit)
sysinit
;;
syshalt)
syshalt
;;
*)
service "$1" "$2"
;;
esac

View File

@@ -0,0 +1,12 @@
#! /bin/sh
config='/etc/config'
if [ -f "$config" ]; then
source "$config"
echo "$cfg_glued_version"
exit 0
fi
echo "ERROR: failed to load '$config'."
exit 1