GithubHelp home page GithubHelp logo

Comments (4)

brianpham avatar brianpham commented on August 19, 2024 1

Not too sure what went wrong so I just created a hb backup, did a re-install of the image, and restore hb config. Seems to be working properly again.

from homebridge-raspbian-image.

oznu avatar oznu commented on August 19, 2024

can you share the contents of the file?

cat $(which hb-config)

from homebridge-raspbian-image.

brianpham avatar brianpham commented on August 19, 2024

@oznu Here at the content. I don’t see anything wrong though.

pi@homebridge:~ $ cat $(which hb-config)
#!/bin/sh

INTERACTIVE=True
ASK_TO_REBOOT=0
CONFIG=/boot/config.txt

RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\e[1m'
NC='\033[0m'

is_pi () {
  ARCH=$(dpkg --print-architecture)
  if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then
    return 0
  else
    return 1
  fi
}

is_pione() {
   if grep -q "^Revision\s*:\s*00[0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo; then      return 0
   elif grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[0-36][0-9a-fA-F]$" /proc/cpuinfo ; then
      return 0
   else
      return 1
   fi
}

is_pitwo() {
   grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo
   return $?
}

is_pizero() {
   grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo
   return $?
}

is_pifour() {
   grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]11[0-9a-fA-F]$" /proc/cpuinfo
   return $?
}

get_pi_type() {
   if is_pione; then
      echo 1
   elif is_pitwo; then
      echo 2
   else
      echo 0
   fi
}

is_live() {
    grep -q "boot=live" $CMDLINE
    return $?
}

is_ssh() {
  if pstree -p | egrep --quiet --extended-regexp ".*sshd.*\($$\)"; then
    return 0
  else
    return 1
  fi
}

is_fkms() {
  if grep -q okay /proc/device-tree/soc/v3d@7ec00000/status 2> /dev/null || grep -q okay /proc/device-tree/soc/firmwarekms@7e600000/status 2> /dev/null ; then
    return 0
  else
    return 1
  fi
}

is_installed() {
    if [ "$(dpkg -l "$1" 2> /dev/null | tail -n 1 | cut -d ' ' -f 1)" != "ii" ]; then
      return 1
    else
      return 0
    fi
}

deb_ver () {
  ver=`cat /etc/debian_version | cut -d . -f 1`
  echo $ver
}

calc_wt_size() {
  # NOTE: it's tempting to redirect stderr to /dev/null, so supress error
  # output from tput. However in this case, tput detects neither stdout or
  # stderr is a tty and so only gives default 80, 24 values
  WT_HEIGHT=17
  WT_WIDTH=$(tput cols)

  if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
    WT_WIDTH=80
  fi
  if [ "$WT_WIDTH" -gt 178 ]; then
    WT_WIDTH=120
  fi
  WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
}

set_config_var() {
  lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
  if line:match("^#?%s*"..key.."=.*$") then
    line=key.."="..value
    made_change=true
  end
  print(line)
end
if not made_change then
  print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}

get_web_addresses() {
  IP=$(hostname -I)

  printf "  ${BOLD}*${NC} ${GREEN}$1://$(hostname).local:$2$3${NC}\n"

  for ip in $IP; do
    if expr "$ip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
      printf "  ${BOLD}*${NC} ${GREEN}$1://$ip:$2$3${NC}\n"
    else
      printf "  ${BOLD}*${NC} ${GREEN}$1://[$ip]:$2$3${NC}\n"
    fi
  done
}

get_ip_and_port() {
  IP=$(hostname -I)

  printf "  ${BOLD}*${NC} ${GREEN}$(hostname).local:$1$2${NC}\n"

  for ip in $IP; do
    if expr "$ip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
      printf "  ${BOLD}*${NC} ${GREEN}$ip:$1$2${NC}\n"
    else
      printf "  ${BOLD}*${NC} ${GREEN}[$ip]:$1$2${NC}\n"
    fi
  done
}

do_finish() {
  if [ $ASK_TO_REBOOT -eq 1 ]; then
    whiptail --yesno "Would you like to reboot now?" 20 60 2
    if [ $? -eq 0 ]; then # yes
      sync
      reboot
    fi
  fi
  exit 0
}

do_stop_services() {
  systemctl stop homebridge
}

do_start_services() {
  systemctl start homebridge
}

do_restart_services() {
  whiptail --yesno "Would you like to restart Homebridge now?" 10 60 2
  RET=$?
  if [ $RET -eq 0 ]; then
    printf "Restarting Homebridge...\n"
    systemctl restart homebridge
  fi
}

do_homebridge_update() {
  printf "Updating Homebridge, please wait...\n"
  npm install -g --unsafe-perm homebridge@latest homebridge-config-ui-x@latest
  whiptail --msgbox "Homebridge is up-to-date." 10 60 1
  do_restart_services
}

do_nodejs_update() {
  printf "Updating Node.js to LTS, please wait...\n"

  INDEX=$(curl -s https://nodejs.org/dist/index.json)
  LTS=$(echo $INDEX | jq -r 'map(select(.lts))[0].version')
  CURRENT=$(node -v || echo "0.0.0")

  echo "Installed: $CURRENT"
  echo "Current Node.js LTS: $LTS"

  if [ $LTS != $CURRENT ]; then
    echo "Updating Node.js to $LTS..."

    PREFIX=$(npm -g prefix || echo "/usr/local")
    sudo rm -rf "$PREFIX/lib/node_modules/npm"
    curl -Lsf "https://unofficial-builds.nodejs.org/download/release/$LTS/node-$LTS-linux-armv6l.tar.gz" | sudo tar xzf - -C /usr/local --strip-components=1 --no-same-owner

    echo "Node.js $(node -v)"
    echo "npm $(npm -v)"

    echo "Node.js updated to $LTS"

    echo "Rebuilding modules..."
    cd "$PREFIX/lib/node_modules"
    sudo npm --unsafe-perm rebuild

    whiptail --msgbox "Node.js upgraded from $CURRENT to $LTS." 10 60 1
    do_restart_services
  else
    whiptail --msgbox "Node.js $CURRENT is already up-to-date" 10 60 1
  fi
}

do_restore_config() {
  whiptail --yesno "This will remove all custom Homebridge config and restore it to the factory default. You will need to manually remove any existing connections to this instance in the iOS Home app.\n\nAre you sure you want to proceed?" 20 60 2
  RET=$?
  if [ $RET -eq 0 ]; then
    do_stop_services
    rm -rf /var/lib/homebridge/persist
    rm -rf /var/lib/homebridge/accessories
    rm -rf /var/lib/homebridge/config.json
    do_start_services
  fi
}

do_install_pihole() {
  whiptail --title "Warning" --yesno "Please make sure you are NOT attempting to run this command from the Homebridge UI web terminal.\n\nFor a successful installation of Pi-Hole you must be logged in using SSH (see wiki for instructions).\n\nIf you are already connected via SSH, you can proceed with the installation." 20 60 1 --no-button "Cancel" --yes-button "Continue"
  if [ $? -ne 0 ]; then
    return;
  fi

  whiptail --title "Warning" --yesno "Installing Pi-Hole will prevent you from accessing the Homebridge UI on port 80.\n\nYou will still be able to access the Homebridge UI on port $(cat /etc/hb-ui-port) and via:\n\n* http://homebridge.local:$(cat /etc/hb-ui-port)\n* https://homebridge.local\n\nWARNING: Failing to configure Pi-Hole correctly or attempting to uninstall Pi-Hole may result in Homebridge not working correctly. You should take a backup of your Homebridge instance via the UI before proceeding.\n\nAre you sure you want to continue?" 20 60 1
  RET=$?
  if [ $RET -eq 0 ]; then
    if [ -f /etc/nginx/sites-available/homebridge.local ]; then
      sed -i "/listen 80;/c\  # listen 80;                  # http IPv4 - disabled by Pi-Hole installer" /etc/nginx/sites-available/homebridge.local
      sed -i "/listen \[::\]:80;/c\  # listen \[::\]:80;             # http IPv6 - disabled by Pi-Hole installer" /etc/nginx/sites-available/homebridge.local
      if systemctl is-active --quiet nginx.service; then
        echo "Restarting Nginx..."
        systemctl restart nginx
      fi
    fi
    printf "Starting Pi-hole installer...\n"
    curl -sSL https://install.pi-hole.net | bash

    printf "\n${BOLD}Pi-hole has been installed${NC}\n"
    printf "Access Pi-hole in your browser by going to:\n"
    get_web_addresses http 80 /admin

    printf "\nYou can still access the Homebridge UI by going to:\n"
    get_web_addresses http $(cat /etc/hb-ui-port)
    get_web_addresses https 443
    printf "\n"
    exit 0
  fi
}

do_install_nodered() {
  whiptail --title "Warning" --yesno "This will install Node-RED on your system as a service running on port 1880.\n\nAre you sure you want to continue?" 20 60 1
  RET=$?
  if [ $RET -eq 0 ]; then
    npm install -g --unsafe-perm node-red node-red-node-pi-gpio node-red-node-random node-red-node-ping node-red-contrib-play-audio node-red-node-smooth node-red-node-serialport node-red-contrib-homebridge-automation

    # add helper shortcuts
    if curl -f https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg >/dev/null 2>&1; then
        sudo curl -sL -o /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /usr/share/applications/Node-RED.desktop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/Node-RED.desktop 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /usr/bin/node-red-start https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /usr/bin/node-red-stop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /usr/bin/node-red-restart https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /usr/bin/node-red-reload https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /usr/bin/node-red-log https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo curl -sL -o /etc/logrotate.d/nodered https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null
        sudo chmod +x /usr/bin/node-red-start
        sudo chmod +x /usr/bin/node-red-stop
        sudo chmod +x /usr/bin/node-red-restart
        sudo chmod +x /usr/bin/node-red-reload
        sudo chmod +x /usr/bin/node-red-log
        printf "Added shortcut commands\r\n"
    else
        printf "Could not add shortcut commands\r\n"
    fi

    cat > /etc/systemd/system/nodered.service <<EOL
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED asUser=pi
Group=pi
WorkingDirectory=/home/pi

Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=256"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target
EOL

    systemctl daemon-reload
    systemctl enable nodered.service
    systemctl start nodered.service

    printf "\n${BOLD}Node-RED has been installed${NC}\n"
    printf "Access Node-RED in your browser by going to:\n"
    get_web_addresses http 1880
    printf "\n"
    exit 0
  fi
}

do_install_unifi() {
  whiptail --title "Warning" --yesno "This will install the UniFi Controller software which uses the following ports:\n\n* 8080\n* 8443\n* 8880\n* 8853\n* 6798\n* 27117\n\nAre you sure you want to continue?" 20 60 1
  RET=$?
  if [ $RET -eq 0 ]; then
    # add unifi repo
    echo 'deb http://www.ubnt.com/downloads/unifi/debian stable ubiquiti' | sudo tee /etc/apt/sources.list.d/100-ubnt-unifi.list
    # add unifi gpg key
    wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ubnt.com/unifi/unifi-repo.gpg
    # install packages
    apt update
    apt install -y openjdk-8-jre-headless haveged
    apt install -y unifi

    printf "\n${BOLD}UniFi Controller has been installed${NC}\n"
    printf "Access the UniFi Controller in your browser by going to:\n"
    get_web_addresses https 8443
    printf "\n"
    exit 0
  fi
}

do_install_deconz() {
  whiptail --title "Warning" --yesno "This will install the deCONZ and Phoscon software which will use the following ports:\n\n* 4530 - Phoscon Web App\n* 4531 - WebSockets\n\nAre you sure you want to continue?" 20 60 1
  RET=$?
  if [ $RET -eq 0 ]; then
    isRaspbee="0"
    isRaspbee2="0"

    do_raspbee_setup() {
      echo "Setting up for RaspBee..."
      isRaspbee="1"

      # Install deps
      apt update
      sudo apt install -y i2c-tools build-essential raspberrypi-kernel-headers

      # WiringPi (Pi4 Only)
      if [ is_pifour ]; then
        curl -o /tmp/wiringpi-latest.deb https://project-downloads.drogon.net/wiringpi-latest.deb
        dpkg -i /tmp/wiringpi-latest.deb
        rm -rf /tmp/wiringpi-latest.deb
      else
        apt install wiringpi
      fi

      # Enable UART
      set_config_var enable_uart 1 $CONFIG
    }

    do_raspbee2_setup() {
      isRaspbee2="1"
      do_raspbee_setup

      # RTC-Installation
      [ -d /tmp/raspbee2-rtc-master ] && rm -rf /tmp/raspbee2-rtc-master
      curl -o /tmp/raspbee2-rtc.zip -L# https://github.com/dresden-elektronik/raspbee2-rtc/archive/master.zip
      unzip /tmp/raspbee2-rtc.zip -d /tmp
      cd /tmp/raspbee2-rtc-master
      make
      make install
      cd ~
      rm -rf /tmp/raspbee2-rtc-master
    }

    do_conbee_setup() {
      echo "Setting up for ConBee / ConBee II..."
      isRaspbee="0"
    }

    FUN=$(whiptail --title "Choose Device" --menu "\nPlease select the type of device you have:" 20 60 3 --cancel-button Cancel --ok-button Select \
      "C1 ConBee or ConBee II" "" \
      "C2 RaspBee I" "" \
      "C3 RaspBee II" "" \
      3>&1 1>&2 2>&3)
    RET=$?
    if [ $RET -eq 1 ]; then
      return 0
    elif [ $RET -eq 0 ]; then
      case "$FUN" in
        C1\ *) do_conbee_setup ;;
        C2\ *) do_raspbee_setup ;;
        C3\ *) do_raspbee2_setup ;;
        *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
      esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
    fi

    # Import Phoscon public key
    wget -O - http://phoscon.de/apt/deconz.pub.key | sudo apt-key add -

    # Configure the APT repository for deCONZ
    sudo sh -c "echo 'deb http://phoscon.de/apt/deconz \
            $(lsb_release -cs) main' > \
            /etc/apt/sources.list.d/deconz.list"

    # Update APT package list
    apt update

    # Install deCONZ
    apt install -y deconz

    # Add override service
    mkdir -p /etc/systemd/system/deconz.service.d
    cat > /etc/systemd/system/deconz.service.d/override.conf <<EOL
[Service]
User=pi
ExecStart=
ExecStart=/usr/bin/deCONZ -platform minimal --http-port=4530 --ws-port=4531
EOL

    # Enable and start
    systemctl daemon-reload

    systemctl stop deconz-gui
    systemctl disable deconz-gui
    
    systemctl enable deconz
    systemctl restart deconz

    # Complete
    PHOSCON_WEB=$(get_web_addresses http 4530 | sed 's/\x1b\[[0-9;]*m//g')
    whiptail --title "Success" --msgbox "deCONZ and Phoscon have been installed.\n\nYou can access the Phoscon web app via:\n\n$PHOSCON_WEB" 20 60 1

    # Ask to reboot on RaspBee
    if [ "$isRaspbee" = "1" ]; then
      if [ "$isRaspbee2" = "1" ]; then
        whiptail --title "Final Steps" --msgbox "You need to reboot your device to complete installation.\n\nOnce you have reboot you need to configure the RTC module by running:\n\nsudo hwclock --systohc\nsudo hwclock --verbose\n\nSee the RaspBee II install guide for further instructions: https://phoscon.de/en/raspbee2/install#raspbian" 20 60 1
      else 
         whiptail --title "Final Steps" --msgbox "You need to reboot your device to complete installation." 20 60 1
      fi
      whiptail --title "Reboot Required" --yesno "Would you like to reboot now?" 20 60 2
      if [ $? -eq 0 ]; then # yes
        sync
        reboot
      fi
    fi
  fi
}

do_install_desktop_and_vnc() {
  get_vnc() {
    if systemctl status vncserver-x11-serviced.service  | grep -q -w active; then
      echo 0
    else
      echo 1
    fi
  }

  do_vnc() {
    DEFAULT=--defaultno
    if [ $(get_vnc) -eq 0 ]; then
      DEFAULT=
    fi
    whiptail --yesno "Would you like the VNC Server and virtual desktop service enabled?" $DEFAULT 20 60 2 --no-button "Disable" --yes-button "Enable"
    RET=$?
    if [ $RET -eq 0 ]; then

      # install desktop
      if is_installed raspberrypi-ui-mods; then
        echo "Raspbian Desktop Already Installed"
      else
        whiptail --title "Warning" --yesno "The Raspbian Desktop will now be installed.\n\nThis may take between 5 and 45 minutes to complete depending on your device." 20 60 2 --no-button "Cancel" --yes-button "Continue"
        if [ $? -eq 0 ]; then
          apt update
          apt install -y raspberrypi-ui-mods
        else
          return 0;
        fi
      fi

      # install and setup VNC
      if is_installed realvnc-vnc-server || (apt update && apt install -y realvnc-vnc-server); then
        cat > /etc/systemd/system/vncserver-pi.service <<EOL
[Unit]
Description=VNC Virtual Desktop Service
After=syslog.target network.target

[Service]
Type=forking
User=pi
Group=pi
WorkingDirectory=/home/pi

PIDFile=/home/pi/.vnc/%H:12.pid
ExecStartPre=-/usr/bin/vncserver -kill :12 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :12
ExecStop=/usr/bin/vncserver -kill :12

[Install]
WantedBy=multi-user.target
EOL
        systemctl enable vncserver-x11-serviced.service &&
        systemctl start vncserver-x11-serviced.service &&
        systemctl enable vncserver-pi.service &&
        systemctl start vncserver-pi.service &&
        STATUS=enabled
      else
        return 1
      fi
    elif [ $RET -eq 1 ]; then
      if is_installed realvnc-vnc-server; then
          systemctl disable vncserver-x11-serviced.service
          systemctl stop vncserver-x11-serviced.service
          systemctl disable vncserver-pi.service
          systemctl stop vncserver-pi.service
      fi
      STATUS=disabled
    else
      return $RET
    fi

    if [ "$STATUS" = "disabled" ]; then
      whiptail --title "Success" --msgbox "The VNC Server and virtual desktop have been disabled." 20 60 1
    else
      # Complete
      VNC_ACCESS_URI=$(get_ip_and_port 5912 | sed 's/\x1b\[[0-9;]*m//g')
      whiptail --title "Success" --msgbox "The VNC Server and virtual desktop have been configured.\n\nYou can connect to the virtual desktop using the RealVNC Viewer on port 5912:\n\n$VNC_ACCESS_URI\n\nDownload RealVNC Viewer:\n\n  * https://www.realvnc.com/download/viewer/" 20 60 1
    fi
  }

  do_vnc
}

do_extra_packages() {
  FUN=$(whiptail --title "Homebridge Raspbian Configuration Tool (hb-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
    "A1 Pi-hole" "Install / Reconfigure Pi-hole" \
    "A2 Node-RED" "Install / Update Node-RED" \
    "A3 UniFi Controller" "Install / Update the Ubiquiti UniFi Controller software" \
    "A4 deCONZ / Phoscon" "Install / Update to manage your ConBee or RaspBee device" \
    "A5 RealVNC Server" "Enable / Disable desktop access over VNC" \
    3>&1 1>&2 2>&3)
  RET=$?
  if [ $RET -eq 1 ]; then
    return 0
  elif [ $RET -eq 0 ]; then
    case "$FUN" in
      A1\ *) do_install_pihole ;;
      A2\ *) do_install_nodered ;;
      A3\ *) do_install_unifi ;;
      A4\ *) do_install_deconz ;;
      A5\ *) do_install_desktop_and_vnc ;;
      *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;    esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
  fi
}

do_configure_nginx() {
  whiptail --title "Warning" --yesno "Using this tool will overwrite any manual changes you may have made to the Homebridge Nginx config file.\n\nAre you sure you wish to continue?" 20 60 1
  RET=$?
  tempDir=$(mktemp -d)
  if [ $RET -eq 0 ]; then
    whiptail --title "Homebridge Raspbian Configuration Tool (hb-config)" --separate-output --checklist "\nNGINX Options:"  20 80 5 --cancel-button Cancel --ok-button Save \
      "1" "Listen on port 80 - http://        " 1  \
      "2" "Listen on port 443 - https://      " 1 \
      "3" "Redirect http:// to https://       " 0 2>$tempDir/results

    if [ $? -eq 0 ]; then
       LISTEN_ON_PORT_80=false
       LISTEN_ON_PORT_443=false
       REDIRECT_HTTP_TO_HTTPS=false

       while read choice
       do
         case "$choice" in
           1) LISTEN_ON_PORT_80=true ;;
           2) LISTEN_ON_PORT_443=true ;;
           3) REDIRECT_HTTP_TO_HTTPS=true ;;
           *) ;;
         esac
       done < $tempDir/results

NGINX_PORT_80_CONFIG=""
if [ "$LISTEN_ON_PORT_80" = "true" ]; then
  NGINX_PORT_80_CONFIG="# http://\n  listen 80;                  # http IPv4\n  listen [::]:80;             # http IPv6\n"
fi

NGINX_PORT_443_CONFIG=""
if [ "$LISTEN_ON_PORT_443" = "true" ]; then
  NGINX_PORT_443_CONFIG="# https://\n  listen 443 ssl http2;       # https IPv4\n  listen [::]:443 ssl http2;  # https IPv6\n"
fi

NGINX_REDIRECT_HTTP_TO_HTTPS=""
if [ "$REDIRECT_HTTP_TO_HTTPS" = "true" ] && [ "$LISTEN_ON_PORT_80" = "true" ]; then
  NGINX_PORT_80_CONFIG=""
  NGINX_REDIRECT_HTTP_TO_HTTPS="
server {
  listen 80;                  # http IPv4
  listen [::]:80;             # http IPv6

  # replace the _ with your domain name if required
  # eg.
  # server_name example.com;
  server_name _;

  return 302 https://\$host\$request_uri;
}"
fi

NGINX_TEMPLATE="# this file was generated using the hb-config tool

server {
  $NGINX_PORT_80_CONFIG
  $NGINX_PORT_443_CONFIG
  # replace the _ with your domain name if required
  # eg.
  # server_name example.com;
  server_name _; # replace with your domain

  # path to ssl certificate file
  # If using Let's Encrypt replace this path with the location of the fullchain.pem file for your domain
  # eg.
  # ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate /etc/nginx/ssl/homebridge.local.crt;

  # path to ssl private key file
  # If using Let's Encrypt replace this path with the location of the privkey.pem file for your domain
  # eg.
  # ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  ssl_certificate_key /etc/nginx/ssl/homebridge.local.key;

  ssl_session_cache           builtin:1000  shared:SSL:10m;
  ssl_protocols               TLSv1.2 TLSv1.3;
  ssl_ciphers                 ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  ssl_prefer_server_ciphers   off;
  # ssl_stapling                on;
  # ssl_stapling_verify         on;

  # large upload size to allow for uploading 3rd party backup files
  client_max_body_size 2G;

  error_page 502 /custom_502.html;

  location /startup-status.json {
    alias /usr/share/nginx/html/status.json;
  }

  location / {
    proxy_pass                  http://127.0.0.1:$(cat /etc/hb-ui-port);
    proxy_http_version          1.1;
    proxy_buffering             off;
    proxy_set_header            Host \$host;
    proxy_set_header            Upgrade \$http_upgrade;
    proxy_set_header            Connection \"Upgrade\";
    proxy_set_header            X-Real-IP \$remote_addr;
    proxy_set_header            X-Forward-For \$proxy_add_x_forwarded_for;
  }

  location = /custom_502.html {
    root /usr/share/nginx/html;
    internal;
  }
}
$NGINX_REDIRECT_HTTP_TO_HTTPS
"

      echo "$NGINX_TEMPLATE" > /etc/nginx/sites-available/homebridge.local
      /usr/local/sbin/nginx-homebridge-self-signed-cert
      systemctl enable nginx

      if systemctl is-active --quiet nginx.service; then
        echo "Restarting Nginx..."
        systemctl restart nginx
      else
        echo "Starting Nginx..."
        systemctl start nginx
      fi

      if [ $? -eq 0 ]; then
        whiptail --title "Success" --msgbox "NGINX has been configured successfully." 20 60 1
       else
        whiptail --title "Error" --msgbox "An error occured while attempting to reload the NGINX config." 20 60 1
      fi

    fi
  fi
}

do_configure_raspbian() {
  raspi-config
}

do_update() {
  tempDir=$(mktemp -d)
  scriptUrl=https://raw.githubusercontent.com/homebridge/homebridge-raspbian-image/master/stage3_homebridge/01-homebridge/files/hb-config

  # download the update to a temporary directory
  scriptUrl=$scriptUrl?$(date --iso-8601)
  printf "Downloading hb-config update...\n$scriptUrl\n"
  curl -fL# $scriptUrl > $tempDir/hb-config

  # check the download was a success
  RET=$?
  if [ $RET -ne 0 ]; then
    whiptail --title "Error" --msgbox "An error occured while attempting to update the hb-config tool." 20 60 1
  else
    # syntax check the script is a valid bash script
    if bash -n $tempDir/hb-config; then
      chmod +x $tempDir/hb-config
      mv $tempDir/hb-config /usr/local/sbin/hb-config
      whiptail --title "Success" --msgbox "The hb-config tool has been updated and will now exit.\n\nIf you like the Homebridge Raspberry Pi image please show your support by starring the project on GitHub:\n\nhttps://github.com/homebridge/homebridge-raspbian-image" 20 60 1
      exit 0
    else
      whiptail --title "Error" --msgbox "The downloaded script was corrupted and did not pass the syntax check." 20 60 1
    fi
  fi
}

do_about() {
  IMAGE_VERSION=$(cat /etc/hb-release)

  whiptail --title "About" --msgbox "\
This tool provides a straight-forward way of managing Homebridge on a Raspberry Pi. Although it can be run at any time, some of the options may have difficulties if you have heavily customised your installation.

Image Version: $IMAGE_VERSION

Homebridge - @nfarina
https://github.com/homebridge/homebridge

Homebridge Config UI X - @oznu
https://github.com/oznu/homebridge-config-ui-x

Homebridge Raspbian Image - @oznu
https://github.com/homebridge/homebridge-raspbian-image


\
" 20 80 1
}

# Everything else needs to be run as root
if [ $(id -u) -ne 0 ]; then
  printf "Script must be run as root. Try 'sudo hb-config'\n"
  exit 1
fi

#
# Interactive use loop
#
if [ "$INTERACTIVE" = True ]; then
  [ -e $CONFIG ] || touch $CONFIG
  calc_wt_size
  while true; do
    if is_pi ; then
      FUN=$(whiptail --title "Homebridge Raspbian Configuration Tool (hb-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
        "1 Upgrade Node.js" "Upgrade Node.js to the latest LTS version" \
        "2 Update Homebridge" "Update Homebridge to the latest version" \
        "3 Restore Config" "Restores the Homebridge config to the factory default" \
        "4 Extra Packages" "Optional packages, eg. Pi-Hole, Node-RED, UniFi Controller" \
        "5 Nginx Options" "Configure Homebridge Nginx settings" \
        "6 Configure OS" "Open the Raspbian Configuration Tool" \
        "7 Networking" "Open the the NetworkManager UI" \
        "8 Update" "Update this tool to the latest version" \
        "9 About" "Information about this configuration tool" \
        3>&1 1>&2 2>&3)
    else
      FUN=$(whiptail --title "Homebridge Raspbian Configuration Tool (hb-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
        "1 Upgrade Node.js" "Upgrade Node.js to the latest LTS version" \
        "2 Update Homebridge" "Update Homebridge to the latest version" \
        "3 Restore Config" "Restores the Homebridge config to the factory default" \
        "4 Extra Packages" "Optional packages, eg. Pi-Hole, Node-RED, UniFi Controller" \
        "5 Nginx Options" "Configure Homebridge Nginx settings" \
        "6 Configure OS" "Open the Raspbian Configuration Tool" \
        "7 Networking" "Open the the NetworkManager UI" \
        "8 Update" "Update this tool to the latest version" \
        "9 About" "Information about this configuration tool" \
        3>&1 1>&2 2>&3)
    fi
    RET=$?
    if [ $RET -eq 1 ]; then
      do_finish
    elif [ $RET -eq 0 ]; then
      if is_pi ; then
        case "$FUN" in
          1\ *) do_nodejs_update ;;
          2\ *) do_homebridge_update ;;
          3\ *) do_restore_config ;;
          4\ *) do_extra_packages ;;
          5\ *) do_configure_nginx ;;
          6\ *) do_configure_raspbian ;;
          7\ *) nmtui ;;
          8\ *) do_update ;;
          9\ *) do_about ;;
          *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
        esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
      else
        case "$FUN" in
          1\ *) do_nodejs_update ;;
          2\ *) do_homebridge_update ;;
          3\ *) do_restore_config ;;
          4\ *) do_extra_packages ;;
          5\ *) do_configure_nginx ;;
          6\ *) do_configure_raspbian ;;
          7\ *) nmtui ;;
          8\ *) do_update ;;
          9\ *) do_about ;;
          *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
        esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
      fi
    else
      exit 1
    fi
  done
fi

from homebridge-raspbian-image.

brianpham avatar brianpham commented on August 19, 2024

@oznu Any suggestions here? Everything else seems to be working properly. About to attempt to just rebuiild from scratch to see if that would fix the issue.

from homebridge-raspbian-image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.