#!/bin/bash OS=$(uname -s) if [ "$OS" == "Linux" ]; then OS="linux" fi if [ "$OS" == "Darwin" ]; then OS="darwin" fi PLATFORM=$(uname -m) PLATFORM2="$PLATFORM" if [ "$PLATFORM" == "x86_64" ]; then PLATFORM="x64" PLATFORM2="x64" fi if [ "$PLATFORM" == "i686" ]; then PLATFORM="x86" PLATFORM2="x86" fi if [ "$PLATFORM" == "aarch64" ]; then PLATFORM="arm64" PLATFORM2="arm64" fi if [ "$PLATFORM" == "armv7l" ]; then PLATFORM2="armv7" fi if [ "$PLATFORM" == "armv6l" ]; then PLATFORM2="armv6" fi echo "$OS-$PLATFORM ($PLATFORM2) detected" NODE=v16.15.0 echo "Downloading node https://nodejs.org/dist/${NODE}/node-${NODE}-${OS}-${PLATFORM}.tar.xz" if [ "$OS" == "darwin" ]; then curl --silent --fail https://nodejs.org/dist/${NODE}/node-${NODE}-${OS}-${PLATFORM}.tar.xz --output "node-$NODE.tar.xz" else wget -q https://nodejs.org/dist/${NODE}/node-${NODE}-${OS}-${PLATFORM}.tar.xz -O "node-$NODE.tar.xz" fi if [[ $? -ne 0 ]]; then echo "***** WARNING! Node not found!" else echo "Extracting node" tar -xf node-${NODE}.tar.xz rm node-${NODE}.tar.xz if [ -d "node-${NODE}-${OS}-${PLATFORM}" ]; then echo "Installing node" cp -R node-${NODE}-${OS}-${PLATFORM}/* /usr/local/ echo "Deleting temp files" rm -r -f node-${NODE}-${OS}-${PLATFORM} else echo "***** WARNING! Node not found!" fi fi if [ "$OS" == "linux" ]; then echo "Updating your system" apt-get update > /dev/null echo "Installing dependencies" DEBIAN_FRONTEND="noninteractive" apt-get -qq -y install tzdata apt-get install -qq -y build-essential libavahi-compat-libdnssd-dev DEBIAN_FRONTEND="noninteractive" apt-get -qq -y install samba samba-client smbclient apt-get install -qq -y zip iw libtool libudev-dev libnss-mdns dnsmasq hostapd autoconf automake g++ avahi-daemon avahi-discover mosquitto sqlite3 ntp apt-get install -qq -y python apt-get install -qq -y python3 apt-get install -qq -y ffmpeg fi mkdir -p ~/bary/ cd ~/bary echo "Downloading BARY http://bary.io/bary-core-latest.zip" if [ "$OS" == "darwin" ]; then curl --silent --fail "http://bary.io/bary-core-latest.zip" --output core.zip else wget -q http://bary.io/bary-core-latest.zip -O core.zip fi if [[ $? -ne 0 ]]; then echo "***** ERROR! BARY not found!" exit 1 else echo "Extracting BARY" unzip -o -qq core.zip rm core.zip fi for p in "camera_rtsp" "modbus" "mqtt" "wirenboard" "zigbee2mqtt" "zwavejs" ; do echo "Downloading Plugin http://bary.io/bary_plugin_${p}_stable.zip" if [ "$OS" == "darwin" ]; then curl --silent --fail "http://bary.io/bary_plugin_${p}_stable.zip" --output plugin.zip else wget -q "http://bary.io/bary_plugin_${p}_stable.zip" -O plugin.zip fi unzip -o -qq plugin.zip rm plugin.zip done cp -n ./config/config_example.js ./config/config.js cp -n ./package_example.json ./package.json echo "Installing node dependencies (it may take a long time)" npm install --unsafe-perm --silent if [ "$OS" == "linux" ]; then echo "Installing BARY service" echo "[Unit] Description=bary After=network.target [Service] ExecStart=/usr/local/bin/node ~/bary/server.js WorkingDirectory=~/bary StandardOutput=inherit StandardError=inherit Restart=always User=root [Install] WantedBy=multi-user.target " > /etc/systemd/system/bary.service systemctl daemon-reload systemctl start bary systemctl enable bary.service fi if [ "$OS" == "darwin" ]; then chmod +x ./database chmod +x ./device-scan chmod +x ./server echo "Running BARY" /usr/local/bin/node install.js echo "Please run ./server manually" else echo "Waiting BARY service (QR code will appear in 1 minute)" sleep 60 && /usr/local/bin/node install.js fi