Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
268 lines (235 sloc) 9.87 KB
#!/bin/bash
# installer zway to raspberry
<% zway = node['z-way'] -%>
ZWAY_DIR=<%= zway['base'] %>
INSTALL_DIR="$(dirname "$ZWAY_DIR")"
TEMP_DIR=/tmp
BOXED=`[ -e /etc/z-way/box_type ] && echo yes`
if [[ $ZWAY_UPIF ]]; then
write_upi() {
echo -e $1 > $ZWAY_UPIF
}
else
write_upi() {
true;
}
fi
##### The percentage of updates #####
write_upi "10%\nStarting upgrading"
#####################################
# Check if Z-Way was already installed in /opt/z-way-server
upgrade_zway="no"
if [[ -d $ZWAY_DIR ]]; then
upgrade_zway="yes"
else
echo "z-way-server new installation"
fi
##### The percentage of updates #####
write_upi "60%\nMaking backup and installing Z-Way"
#####################################
# If downloading and extracting is ok, then make backup and move z-way-server from /tmp to /data
# if need upgrade
if [[ "$upgrade_zway" = "yes" ]]; then
echo "Previous z-way-server installation found"
if ! diff $ZWAY_DIR/config.xml $TMP_ZWAY_DIR/config.xml -w > /dev/null
then
echo "config.xml replaced by the new one - make sure to restore your changes"
echo "diff $ZWAY_DIR/config.xml $TMP_ZWAY_DIR/config.xml:"
diff $ZWAY_DIR/config.xml $TMP_ZWAY_DIR/config.xml -w
echo
fi
echo "!!! Defaults.xml and config.xml updated with new versions !!!"
else
echo "New version z-way-server installed"
fi
##### The percentage of updates #####
write_upi "70%\nGetting Webif for Raspberry Pi and installing"
#####################################
# If first install, get new ID
if [[ ! -e /etc/init.d/zbw_connect ]]
then
echo "First install, getting Remote ID"
echo '#!/bin/bash
### BEGIN INIT INFO
# Provides: zbw_autosetup
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: zbw_autosetup
# Description: the script setup a zbw_connect script
### END INIT INFO
function delete_me()
{
insserv -r zbw_autosetup
rm -f /etc/init.d/zbw_autosetup
rm -f $0
}
if [[ $0 == "/tmp/zbw_autosetup" ]]; then
delete_me;
exit
fi
case "$1" in
start)
# if we already have zbw_connect, delete ourself
if [[ -x /etc/init.d/zbw_connect ]]; then
# a hack to eliminate an error on a remouting / ro
cp $0 /tmp/zbw_autosetup
exec /tmp/zbw_autosetup
fi
if wget -4 http://find.zwave.me/zbw_new_user -O /tmp/zbw_connect_setup.run; then
sleep 10
if bash /tmp/zbw_connect_setup.run; then
# Update service file for Jessie
systemctl daemon-reload
/etc/init.d/zbw_connect start
# a hack to eliminate an error on a remouting / ro
cp $0 /tmp/zbw_autosetup
exec /tmp/zbw_autosetup
fi
mount -o remount,ro /
fi
;;
esac
' > /etc/init.d/zbw_autosetup
chmod +x /etc/init.d/zbw_autosetup
/etc/init.d/zbw_autosetup start
else
# Update zbw_connect to new version
cd /etc/init.d/
./zbw_connect stop
echo 'begin-base64 644 zbw_connect_with_out_key
IyEvYmluL2Jhc2gKIyMjIEJFR0lOIElOSVQgSU5GTwojIFByb3ZpZGVzOiAg
ICAgICAgICB6YndfY29ubmVjdAojIFJlcXVpcmVkLVN0YXJ0OiAgICAkYWxs
CiMgUmVxdWlyZWQtU3RvcDogICAgICRhbGwKIyBEZWZhdWx0LVN0YXJ0OiAg
ICAgMiAzIDQgNQojIERlZmF1bHQtU3RvcDogICAgICAwIDEgNgojIFNob3J0
LURlc2NyaXB0aW9uOiB6YndfY29ubmVjdAojIERlc2NyaXB0aW9uOiAgICAg
ICB0aGUgc2NyaXB0IHRvIGNvbm5lY3QgdG8gemJ3IHNlcnZlcgojIyMgRU5E
IElOSVQgSU5GTwoKUElERklMRT0vdmFyL3J1bi96YndfY29ubmVjdC5waWQK
CiMgdGVzdCBhIHdyaXRhYmxlIG9mIC90bXAKaWYgISB0b3VjaCAvdG1wLy56
YndfY29ubmVjdF9yd190ZXN0Owp0aGVuCiAgICBlY2hvICIvdG1wIGlzIG5v
dCB3cml0YWJsZSIgPiYyCiAgICBleGl0IDEKZmkKcm0gLWYgL3RtcC8uemJ3
X2Nvbm5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IGlzIHN1ZmZpY2llbnQKICAgIFpCV19JTlRFUk5BTF9JUD0iIgogICAg
Zm9yIGkgaW4gJExPQ0FMX0lQUzsgZG8KCWlmIFtbICRpICE9ICIxMjcuMC4w
LjEiIF1dOyB0aGVuCgkgICAgaWYgW1sgJFpCV19JTlRFUk5BTF9JUCBdXTsg
dGhlbgoJCVpCV19JTlRFUk5BTF9JUD0iJFpCV19JTlRFUk5BTF9JUCwkaSI7
CgkgICAgZWxzZQoJCVpCV19JTlRFUk5BTF9JUD0iJGkiOwoJICAgIGZpCglm
aQogICAgZG9uZQp9CgpleHBvcnQgWkJXX1BBU1NXT1JEPSRQQVNTV09SRApl
eHBvcnQgWkJXX0lOVEVSTkFMX0lQCmV4cG9ydCBaQldfSU5URVJOQUxfUE9S
VD0kTE9DQUxfUE9SVApleHBvcnQgWkJXX0JPWFRZUEU9JEJPWFRZUEUKCndo
aWxlIHRydWUKZG8KICAgIGdldF9sb2NhbF9pcHMKCiAgICBzc2ggLWkgL3Rt
cC96YndfY29ubmVjdC5wcml2IC1UIC1vICdTdHJpY3RIb3N0S2V5Q2hlY2tp
bmcgbm8nIC1vICdVc2VyS25vd25Ib3N0c0ZpbGUgL2Rldi9udWxsJyAtbyAn
QmF0Y2hNb2RlIHllcycgLW8gJ1NlbmRFbnYgWkJXXyonIC1vICJFeGl0T25G
b3J3YXJkRmFpbHVyZSB5ZXMiIC1vICJTZXJ2ZXJBbGl2ZUludGVydmFsIDMw
IiAtbyAiU2VydmVyQWxpdmVDb3VudE1heCAzIiAkRldEX09QVFMgJFNTSF9V
U0VSQCRTRVJWRVIKICAgIHNsZWVwIDEKZG9uZQoKZXhpdCAwCg==
====' | uudecode -o zbw_connect.new
tail -n 29 zbw_connect >> zbw_connect.new
mv zbw_connect.new zbw_connect
chmod +x zbw_connect
# Update service file for Jessie
systemctl daemon-reload
# Change default zbw port to 8083
echo "8083" > /etc/zbw/local_port
echo "zbw_connect patched"
./zbw_connect start
fi
##### The percentage of updates #####
write_upi "90%\nRestarting Webif and Z-Way"
#####################################
# Prepare AMA0
sed 's/console=ttyAMA0,115200//; s/kgdboc=ttyAMA0,115200//; s/console=serial0,115200//' /boot/cmdline.txt > /tmp/zway_install_cmdline.txt
if [[ -f /etc/inittab ]]
then
sed 's|[^:]*:[^:]*:respawn:/sbin/getty[^:]*ttyAMA0[^:]*||' /etc/inittab > /tmp/zway_install_inittab
fi
# Disable bluetooth Raspberry Pi 3
RPI_BOARD_REVISION=`grep Revision /proc/cpuinfo | cut -d: -f2 | tr -d " "`
if [[ $RPI_BOARD_REVISION == "a02082" || $RPI_BOARD_REVISION == "a22082" ]]
then
echo "Raspberry Pi 3 Detected. Disabling Bluetooth"
systemctl disable hciuart
# Add "dtoverlay=pi3-miniuart-bt" to /boot/config.txt if needed
if [[ ! `grep "dtoverlay=pi3-miniuart-bt" /boot/config.txt` ]]
then
echo "Adding 'dtoverlay=pi3-miniuart-bt' to /boot/config.txt"
echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt
fi
echo "!!! Update Raspberry Pi 3 Firmware for stability work with commands:"
echo "sudo apt-get install rpi-update"
echo "sudo rpi-update"
fi
# Transform old DevicesData.xml to new format
(cd $ZWAY_DIR && test -x ./z-cfg-update && ls -1 config/zddx/*.xml | LD_LIBRARY_PATH=./libs xargs -l ./z-cfg-update)
if diff /boot/cmdline.txt /tmp/zway_install_cmdline.txt > /dev/null || diff /etc/inittab /tmp/zway_install_inittab > /dev/null
then
rm /tmp/zway_install_cmdline.txt /tmp/zway_install_inittab
# Starting z-way-server mongoose
echo "Starting z-way-server"
/etc/init.d/z-way-server start
else
echo "Preparing AMA0 interface:"
echo " removing 'console=ttyAMA0,115200' and 'kgdboc=ttyAMA0,115200 and 'console=serial0,115200' from kernel command line (/boot/cmdline.txt)"
mv /tmp/zway_install_cmdline.txt /boot/cmdline.txt
echo " removing '*:*:respawn:/sbin/getty ttyAMA0' from /etc/inittab"
mv /tmp/zway_install_inittab /etc/inittab
echo "AMA0 interface reconfigured, please restart Raspberry"
fi
# Make sure to save changes
sync
echo "Thank you for using RaZberry!"
exit 0