#!/bin/bash
read -p "Warning: Only execute this script on a Raspberry Pi or cubietruck. The CCU2 executables won't work on other systems. The script also messes with your libraries, so make a backup before executing it! Do you want to continue? (y/n): " CONTINUE
if [ "$CONTINUE" = "n" ]; then
exit 0;
fi
mkdir /ccu2
wget -P /ccu2 http://www.eq-3.de/Downloads/Software/HM-CCU2-Firmware_Updates/HM-CCU2-2.9.12/HM-CCU-2.9.12.tar.gz
[ $? -ne 0 ] && exit 1
tar -zxf /ccu2/HM-CCU-2.9.12.tar.gz -C /ccu2
[ $? -ne 0 ] && exit 1
rm -f /ccu2/HM-CCU-2.9.12.tar.gz
echo "Downloading UBI Reader..."
echo "(C) 2013 Jason Pruitt (Jason Pruitt), see https://github.com/jrspruitt/ubi_reader"
wget -P /ccu2 https://github.com/jrspruitt/ubi_reader/archive/v2_ui.tar.gz
[ $? -ne 0 ] && exit 1
tar -zxf /ccu2/v2_ui.tar.gz -C /ccu2
[ $? -ne 0 ] && exit 1
/ccu2/ubi_reader-2_ui/extract_files.py -o /ccu2/rootfs /ccu2/rootfs.ubi
[ $? -ne 0 ] && exit 1
mv /ccu2/rootfs/rootfs.ubi/2054179022/root/* /ccu2
[ $? -ne 0 ] && exit 1
rm -f /ccu2/uImage
rm -f /ccu2/rootfs.ubi
rm -f /ccu2/EULA.de
rm -f /ccu2/EULA.en
rm -f /ccu2/v2_ui.tar.gz
rm -f /ccu2/update_script
apt-get update
apt-get -y install lighttpd java7-runtime
chmod 755 /ccu2/bin/*
chmod 755 /ccu2/lib/*
ln -s /ccu2/bin/ReGaHss /bin/ReGaHss
ln -s /ccu2/bin/tclsh /bin/tclsh
ln -s /ccu2/bin/hm_startup /bin/hm_startup
ln -s /ccu2/bin/hm_autoconf /bin/hm_autoconf
ln -s /ccu2/bin/hm_deldev /bin/hm_deldev
ln -s /ccu2/bin/SetInterfaceClock /bin/SetInterfaceClock
ln -s /ccu2/bin/crypttool /bin/crypttool
ln -s /ccu2/bin/eq3configcmd /bin/eq3configcmd
ln -s /ccu2/bin/eq3configd /bin/eq3configd
mkdir /opt/HMServer
ln -s /ccu2/opt/HMServer/HMServer.jar /opt/HMServer/HMServer.jar
ln -s /ccu2/usr/local/etc/config/ /etc/config
mkdir -p /etc/config/addons/www /etc/config/addons/mh
ln -s /ccu2/opt/mh/user/ mh
ln -s /ccu2/etc/config_templates/ /etc/config_templates
ln -s /ccu2/etc/rega.conf /etc/rega.conf
ln -s /ccu2/www /www
echo "
BidCos-RF
xmlrpc_bin://127.0.0.1:2001
BidCos-RF
" > /etc/config/InterfacesList.xml
cp /ccu2/etc/config_templates/log4j.xml /etc/config
echo "1DOM9142949672951033620337008101101Rooms314294967295101065535151151Functions314294967295103065535201201Favoriten314294967295105410101048576320210485763203104857632041048576365535301301Verknüpfungen3142949672951010065535401401Szenen31429496729510111100557765535501501Schaltungen3142949672951012065535700700AlarmMaps3142949672951022065535701701Alarms314294967295102106553500000001950950SYSVAR_PRESENCE108914294967295906553521007200120000110051005HM_AUTOCONF5771429496729500655350100700020var x=system.Exec("/bin/hm_autoconf");655351006MapCondition41943050429496729530165535000100500000000110071007BidCos-RF4587531429496729510BidCos-RFxmlrpc_bin://127.0.0.1:20010110061006MapCondition41943050429496729530165535000100500004202202PC10485763142949672958060655350000203203PDA10485763142949672958060655350000204204Zentrale1048576314294967295806065535000010101010_USER10041048576314294967295106065535000061000100012904294967295100655350100010011001129042949672951006553501000100210021290429496729510065535010001003100312904294967295100655350100010041004Admin12914294967295908655350130110091009RemoteApi129142949672950006553501000020Gateway configuration11429496729510112345678Demonstration boardhttp://www.fernzugriff.com/GatewayServices/Register.asmxwww.fernzugriff.com/GatewayServices/www.fernzugriff.com/GatewayServices/80/etc/ReGaHss/homematic.regadom6021Runtime configuration114294967295100110/com/0COM146050/com/0COM20/com/0COM200/com/0COM249664001xmlrpc_bin://127.0.0.1:19990/etc/config/InterfacesList.xml0000030000065535History data6553513001432001200005000022WEB configuration11429496729510http://www.ise.deimg/ManufLogo.gifhttp://www.fernzugriff.com/fernzugriffimg/ServerLogo.gifise Residential GatewayReGaRA Demoimg/MenuHome.gifimg/MenuGoBack.gif/login.htm/index.htm/pages/pages/tabs/admin/pages/tabs/user/pages/tabs/user/config/80:/config/65535/www/config/stringtable_de.txt33003/var/2Root514294967295103Root devices191429496729510011217655354Root channels35142949672951003133323332433655355Root data points6714294967295100814108939825740108941108925416126416110055779501089655356Root structure314294967295107810131513201330134013501370137003655357Root users1311429496729511PC100406100012910011291002129100312910041291009129655358Root user pages31429496729510230655359Root interfaces4587551429496729510322100745875310084587536553512Gateway17142949672952031323240065535113Gateway3314294967295200012214390655356553565535023StateVariables3314294967295102301200655356553565535024Communication33142949672951024012225260655352665535014Gateway-DP108914294967295201316100700001615Root Programs3142949672951025106553519Presence simulation3142949672951025206553531Messages objects314294967295103106553532Root UI data314294967295303306553527Root System Variables314294967295103424010894110896553528Root Service Messages314294967295103506553533Root Rules943718714294967295103606553534Root Calendars104857914294967295103706553516Root history data points6714294967295102406553535Root Conditions314294967295103806553536Root Single Conditions314294967295103906553537Root Destinations314294967295104006553538Root Single Destinations314294967295104106553539Gateway-IPDP82571429496729520132010070000040Gateway-SysAlDP108914294967295102MAX65000MIN06553516000700001641Gateway-SysSrvDP108914294967295102MAX65000MIN06553516000700001611Eventing11429496729510010ValueEventing11429496729510110051417SMTPServer5898251429496729510118POPClient209715314294967295103033620337" > /etc/config/homematic.regadom
ln -s /ccu2/lib/ld-2.13.so /lib/ld-linux.so.3
ln -s /ccu2/lib/libpthread-2.13.so /lib/libpthread-2.13.so
ln -s /lib/libpthread-2.13.so /lib/libpthread.so.0
ln -s /lib/arm-linux-gnueabihf/librt-2.13.so /lib/librt.so.1
ln -s /ccu2/lib/libXmlRpc.so /lib/libXmlRpc.so
ln -s /ccu2/lib/libxmlparser.so /lib/libxmlparser.so
ln -s /ccu2/lib/libelvutils.so /lib/libelvutils.so
ln -s /ccu2/usr/lib/libstdc++.so.6.0.16 /lib/libstdc++.so.6.0.16
ln -s /lib/libstdc++.so.6.0.16 /lib/libstdc++.so.6
ln -s /ccu2/lib/libm-2.13.so /lib/libm-2.13.so
ln -s /lib/libm-2.13.so /lib/libm.so.6
ln -s /ccu2/lib/libgcc_s.so.1 /lib/libgcc_s.so.1
ln -s /ccu2/lib/libc-2.13.so /lib/libc-2.13.so
ln -s /lib/libc-2.13.so /lib/libc.so.6
ln -s /ccu2/lib/tclrega.so /lib/tclrega.so
ln -s /ccu2/lib/tclrpc.so /lib/tclrpc.so
ln -s /ccu2/lib/tclticks.so /lib/tclticks.so
ln -s /ccu2/lib/tcl8.2/ /lib/tcl8.2
ln -s /ccu2/lib/libtcl8.2.so /lib/libtcl8.2.so
ln -s /ccu2/lib/libdl-2.13.so /lib/libdl-2.13.so
ln -s /lib/libdl-2.13.so /lib/libdl.so.2
rm -Rf /etc/lighttpd/conf.d
ln -s /ccu2/etc/lighttpd/conf.d/ /etc/lighttpd/conf.d
rm -f /etc/lighttpd/lighttpd.conf
rm -f /etc/lighttpd/lighttpd_ssl.conf
rm -f /etc/lighttpd/modules.conf
ln -s /ccu2/etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf
ln -s /ccu2/etc/lighttpd/lighttpd_ssl.conf /etc/lighttpd/lighttpd_ssl.conf
ln -s /ccu2/etc/lighttpd/modules.conf /etc/lighttpd/modules.conf
service lighttpd restart
echo "#!/bin/sh
### BEGIN INIT INFO
# Provides: ReGaHss
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: HomeMatic ReGaHss
### END INIT INFO
set -e
. /lib/lsb/init-functions
start() {
log_daemon_msg \"Starting ReGaHss\" \"ReGaHss\" || true
if start-stop-daemon --start --quiet --oknodo --background -m --pidfile /var/run/ReGaHss.pid --exec /bin/ReGaHss -- -f /etc/rega.conf -l 1; then
sleep 15
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
}
stop() {
log_daemon_msg \"Stopping ReGaHss\" \"ReGaHss\" || true
PID=\`cat /var/run/ReGaHss.pid\`
if start-stop-daemon -K -q -p /var/run/ReGaHss.pid; then
sleep 15
kill -9 \$PID > /dev/null 2>&1
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
}
restart() {
stop
sleep 5
start
}
case \"\$1\" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo \"Usage: \$0 {start|stop|restart}\"
exit 1
esac
exit \$?
" > /etc/init.d/ReGaHss
chmod 755 /etc/init.d/ReGaHss
insserv ReGaHss
service ReGaHss start
echo "#!/bin/sh
### BEGIN INIT INFO
# Provides: HMServer
# Required-Start: ReGaHss
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: HomeMatic Java Server
### END INIT INFO
set -e
. /lib/lsb/init-functions
start() {
log_daemon_msg \"Starting HMServer\" \"HMServer\" || true
start-stop-daemon -S -q -p /var/run/HMServer.pid --exec /usr/bin/java -- -Xmx32m -Dlog4j.configuration=file:///etc/config/log4j.xml -Dfile.encoding=ISO-8859-1 -jar /opt/HMServer/HMServer.jar &
sleep 120
log_end_msg 0 || true
}
stop() {
log_daemon_msg \"Stopping HMServer\" \"HMServer\" || true
PID=\`cat /var/run/HMServer.pid\`
sleep 30
kill -9 \$PID > /dev/null 2>&1
log_end_msg 0 || true
}
restart() {
stop
sleep 5
start
}
case \"\$1\" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo \"Usage: \$0 {start|stop|restart}\"
exit 1
esac
exit \$?
" > /etc/init.d/HMServer
#chmod 755 /etc/init.d/HMServer
#insserv HMServer
#service HMServer start