#!/usr/bin/env # Check if we can use colours in our output use_colour=0 [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null && use_colour=1 # Some useful functions progress() { [ $use_colour -eq 1 ] && echo -ne "\033[01;32m" echo "$@" >&2 [ $use_colour -eq 1 ] && echo -ne "\033[00m" } info() { [ $use_colour -eq 1 ] && echo -ne "\033[01;34m" echo "$@" >&2 [ $use_colour -eq 1 ] && echo -ne "\033[00m" } die () { [ $use_colour -eq 1 ] && echo -ne "\033[01;31m" echo "$@" >&2 [ $use_colour -eq 1 ] && echo -ne "\033[00m" exit 1 } install_package() { package=$1 info "install ${package}" sudo apt-get -y --force-yes install $package 2>&1 > /dev/null return $? } # check architecture sudo test "`dpkg --print-architecture`" == "armhf" || die "This Repos is only for armhf." info "Installing Zeroconf" install_package "libavahi-compat-libdnssd-dev" install_package "git" #install_package "make" #sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 #sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 info "Installing node" if $(uname -m | grep -Eq ^armv6); then wget -q https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-armv7l.tar.gz tar -xvf node-v4.0.0-linux-armv7l.tar.gz >/dev/null cd node-v4.0.0-linux-armv7l sudo cp -R * /usr/local/ cd /home/pi info "Cleaning ..." rm node-v4.0.0-linux-armv7l.tar.gz rm node-v4.0.0-linux-armv7l -R else curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs >/dev/null fi info "Installing Homebridge Node Modules" sudo npm install -g --unsafe-perm homebridge sudo npm install -g --unsafe-perm homebridge-homematic mkdir /home/pi/.homebridge configfile="/home/pi/.homebridge/config.json" info "Setup for Homematic" hazconfig="$(cat $configfile| grep 'bridge' | wc -l)" if [ "$hazconfig" = "0" ]; then CCUIP=$(whiptail --inputbox "Please enter your CCU IP" 20 60 "000.000.000.000" 3>&1 1>&2 2>&3) subsection=$(whiptail --inputbox "Please choose a name for a subsection at your CCU. Insert all the devices, you want to control from HomeKit, in that subsection." 20 60 "HomeKit" 3>&1 1>&2 2>&3) if [ $? -eq 0 ]; then echo "{\"bridge\": {\"name\": \"Homebridge\", \"username\": \"CC:22:3D:E3:CE:30\",\"port\": 51826,\"pin\": \"031-45-154\"}," >> $configfile; echo "\"description\": \"This is an autogenerated config. only the homematic platform is enabled. see the sample for more\"," >> $configfile; echo "\"platforms\": [" >> $configfile; echo "{\"platform\": \"HomeMatic\",\"name\": \"HomeMatic CCU\",\"ccu_ip\": \"$CCUIP\"," >> $configfile; echo "\"subsection\":\"$subsection\",">>$configfile; echo "\"filter_device\":[],\"filter_channel\":[],\"outlets\":[]}" >> $configfile; echo "],\"accessories\": []}" >> $configfile; fi fi whiptail --yesno "Would you like to start homebridge at boot by default?" $DEFAULT 20 60 2 RET=$? if [ $RET -eq 0 ]; then wget https://raw.githubusercontent.com/thkl/homebridge/xmlrpc/homebridge sudo mv /home/pi/homebridge /etc/init.d/homebridge sudo chmod 755 /etc/init.d/homebridge sudo update-rc.d homebridge defaults fi echo '127.0.0.1 Homebridge' | sudo tee /etc/hosts info "Done. If there are no error messages you are done." info "Your config.json is here : /home/pi/.homebridge/config.json" info "If you want to install more modules use npm install -G MODULENAME" info "Available Modules are here https://www.npmjs.com/browse/keyword/homebridge-plugin" info "Please navigate to https://github.com/nfarina/homebridge for more informations." info "Start the Homebridge by typing homebridge"