#!/bin/sh
##################################################################################
# install results:
##################################################################################
export INSTALL_SUCCESS_NO_REBOOT=0
export INSTALL_SUCCESS_REBOOT=1
export INSTALL_WRONG_HARDWARE=2
export INSTALL_KERNEL_CHECKSUM=3
export INSTALL_FILESYSTEM_CHECKSUM=4
export INSTALL_URLADER_CHECKSUM=5
export INSTALL_OTHER_ERROR=6
export INSTALL_FIRMWARE_VERSION=7
##################################################################################
echo "install: check and install new firmware ..."
LED_DEVICE=/proc/led_mod/led
if [ ! -f /proc/led_mod/led ] ; then
LED_DEVICE=/var/led
echo "set led: ${LED_DEVICE}"
fi
##################################################################################
# start info led flashing
##################################################################################
echo "set INFO led to blink (modul=7, state=4)"
echo 7,4 > ${LED_DEVICE}
cat > /var/tmp/debug.cfg << 'EOF'
#!/bin/sh
LED_DEVICE=/proc/led_mod/led
if [ ! -f /proc/led_mod/led ] ; then
LED_DEVICE=/var/led
echo "set led: ${LED_DEVICE}"
fi
# start internet phone led flashing
echo "set internet phone led to blink (modul=14, state=3)"
echo 14,3 > ${LED_DEVICE}
# check kernel version
KERNEL_VERSION=`uname -r | grep 2.6`
if [ -z "${KERNEL_VERSION}" ]
then
KERNEL_VERSION="linux24"
ETHERWAKE="etherwake"
else
KERNEL_VERSION="linux26"
ETHERWAKE="ether-wake"
fi
# init busybox var
BUSYBOX="/bin/busybox"
# wait to be able to interrupt in case of emergency
sleep 120
# enable ENUM
sed "s/avme/avm/g" /usr/www/all/html/de/fon/sipoptionen.html > /var/tmp/sipoptionen.html
sed "s/avme/avm/g" /usr/www/all/html/de/fon/sipoptionen.js > /var/tmp/sipoptionen.js
chmod 444 /var/tmp/sipoptionen.html
chmod 444 /var/tmp/sipoptionen.js
mount -o bind /var/tmp/sipoptionen.html /usr/www/all/html/de/fon/sipoptionen.html
mount -o bind /var/tmp/sipoptionen.js /usr/www/all/html/de/fon/sipoptionen.js
# load SSH-Server (dropbear) and etherwake
# CONFIGURATION
# SSH
# port
dropbearport="22"
# password
PASSWD='MEINPASSWORT'
# Etherwake
# MAC address
wolmac="MAC ADRESSE"
# interface to use for WOL
# intf = std - ata
# eth0 = LAN1 - WAN
# eth1 = LAN2 - LAN1
wolinterface="eth0"
# CONFIGURATION END
# try to load files from USB drive
for f in /var/media/ftp/*
do
if [ -f ${f}/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/dropbear ]
then
echo "${f}/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/dropbear"
cp ${f}/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/dropbear /var/tmp/dropbear
fi
done
# check if file already exists
if [ ! -f /var/tmp/dropbear ]
then
# wait for server
while !(ping -c 1 home.arcor.de)
do
sleep 5
done
# load files
wget -qO /var/tmp/dropbear http://home.arcor.de/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/dropbear
fi
# try to load files from USB drive
for f in /var/media/ftp/*
do
if [ -f ${f}/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/busybox ]
then
echo "${f}/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/busybox"
cp ${f}/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/busybox /var/tmp/busybox
fi
done
# check if file already exists
if [ ! -f /var/tmp/busybox ]
then
# wait for server
while !(ping -c 1 home.arcor.de)
do
sleep 5
done
# load files
wget -qO /var/tmp/busybox http://home.arcor.de/USERNAME_ARCOR/ssh/files/${KERNEL_VERSION}/busybox
fi
# make them executable
chmod +x /var/tmp/busybox
chmod +x /var/tmp/dropbear
# set busybox var
BUSYBOX="/var/tmp/busybox"
# change root password
${BUSYBOX} sed -e "/root:/s#^root:[^:]*:#root:${PASSWD}:#" -i /var/tmp/shadow
# create symlink for dropbearkey
ln -s /var/tmp/dropbear dropbearkey
${BUSYBOX} uudecode -o /var/tmp/dropbear_rsa_host_key << 'RSA'
begin 600 /var/tmp/dropbear_rsa_host_key
HIER STAND EIN CODE
`
end
RSA
${BUSYBOX} uudecode -o /var/tmp/dropbear_dss_host_key << 'DSS'
begin 600 /var/tmp/dropbear_dss_host_key
HIER STAND EIN CODE
end
DSS
# start dropbear
sleep 60
/var/tmp/dropbear -p ${dropbearport} -r /var/tmp/dropbear_rsa_host_key -d /var/tmp/dropbear_dss_host_key
# create simplified WOL script
echo "${BUSYBOX} ${ETHERWAKE} -i ${wolinterface} ${wolmac}" > /var/tmp/startpc
# make it executable
chmod +x /var/tmp/startpc
# make FBF accessable from the internet (192.168.178.253)
sleep 10
ifconfig eth0:1 192.168.178.253 netmask 255.255.255.0 broadcast 192.168.178.255 up
# stop internet phone led flashing
echo 14,1 > ${LED_DEVICE}
EOF
# write debug.cfg
cat /var/tmp/debug.cfg > /var/flash/debug.cfg
# delete /var/tmp/debug.cfg
rm /var/tmp/debug.cfg
# change branding to avm
ENVIRON=
[ -f /proc/avalanche/env ] && ENVIRON=/proc/avalanche/env
[ -f /proc/sys/urlader/environment ] && ENVIRON=/proc/sys/urlader/environment
if [ "${OEM}" != "avm" ]
then
if [ -f "${ENVIRON}" -a -d /usr/www/avm ]
then
echo "firmware_version avm" > ${ENVIRON}
fi
fi
# reboot
exit $INSTALL_SUCCESS_REBOOT
# (c) 2006 Andreas Baginski