deconz-v5-install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env bash
  2. if [ "$VERBOSE" = "yes" ]; then set -x; STD=""; else STD="silent"; fi
  3. silent() { "$@" > /dev/null 2>&1; }
  4. if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi
  5. YW=$(echo "\033[33m")
  6. RD=$(echo "\033[01;31m")
  7. BL=$(echo "\033[36m")
  8. GN=$(echo "\033[1;92m")
  9. CL=$(echo "\033[m")
  10. RETRY_NUM=10
  11. RETRY_EVERY=3
  12. CM="${GN}✓${CL}"
  13. CROSS="${RD}✗${CL}"
  14. BFR="\\r\\033[K"
  15. HOLD="-"
  16. set -Eeuo pipefail
  17. trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
  18. function error_handler() {
  19. local exit_code="$?"
  20. local line_number="$1"
  21. local command="$2"
  22. local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
  23. echo -e "\n$error_message\n"
  24. }
  25. function msg_info() {
  26. local msg="$1"
  27. echo -ne " ${HOLD} ${YW}${msg}..."
  28. }
  29. function msg_ok() {
  30. local msg="$1"
  31. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  32. }
  33. function msg_error() {
  34. local msg="$1"
  35. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  36. }
  37. msg_info "Setting up Container OS "
  38. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  39. locale-gen >/dev/null
  40. for ((i=RETRY_NUM; i>0; i--)); do
  41. if [ "$(hostname -I)" != "" ]; then
  42. break
  43. fi
  44. echo 1>&2 -en "${CROSS}${RD} No Network! "
  45. sleep $RETRY_EVERY
  46. done
  47. if [ "$(hostname -I)" = "" ]; then
  48. echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  49. echo -e " 🖧 Check Network Settings"
  50. exit 1
  51. fi
  52. msg_ok "Set up Container OS"
  53. msg_ok "Network Connected: ${BL}$(hostname -I)"
  54. set +e
  55. if ping -c 1 -W 1 1.1.1.1 &> /dev/null; then msg_ok "Internet Connected"; else
  56. msg_error "Internet NOT Connected"
  57. read -r -p "Would you like to continue anyway? <y/N> " prompt
  58. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  59. echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
  60. else
  61. echo -e " 🖧 Check Network Settings"
  62. exit 1
  63. fi
  64. fi
  65. RESOLVEDIP=$(getent hosts github.com | awk '{ print $1 }')
  66. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi
  67. set -e
  68. msg_info "Updating Container OS"
  69. $STD apt-get update
  70. $STD apt-get -y upgrade
  71. msg_ok "Updated Container OS"
  72. msg_info "Installing Dependencies"
  73. $STD apt-get install -y curl
  74. $STD apt-get install -y sudo
  75. $STD apt-get install -y gnupg
  76. msg_ok "Installed Dependencies"
  77. msg_info "Setting Phoscon Repository"
  78. $STD apt-key add <(curl -fsSL http://phoscon.de/apt/deconz.pub.key)
  79. sh -c "echo 'deb [arch=amd64] http://phoscon.de/apt/deconz $(lsb_release -cs) main' > /etc/apt/sources.list.d/deconz.list"
  80. msg_ok "Setup Phoscon Repository"
  81. msg_info "Installing deConz"
  82. $STD apt-get update
  83. $STD apt-get install -y deconz
  84. msg_ok "Installed deConz"
  85. msg_info "Creating Service"
  86. service_path="/lib/systemd/system/deconz.service"
  87. echo "[Unit]
  88. Description=deCONZ: ZigBee gateway -- REST API
  89. Wants=deconz-init.service deconz-update.service
  90. StartLimitIntervalSec=0
  91. [Service]
  92. User=root
  93. ExecStart=/usr/bin/deCONZ -platform minimal --http-port=80
  94. Restart=on-failure
  95. RestartSec=30
  96. AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_KILL CAP_SYS_BOOT CAP_SYS_TIME
  97. [Install]
  98. WantedBy=multi-user.target" >$service_path
  99. $STD systemctl enable --now deconz
  100. msg_ok "Created Service"
  101. echo "export TERM='xterm-256color'" >>/root/.bashrc
  102. echo -e "$APPLICATION LXC provided by https://tteck.github.io/Proxmox/\n" > /etc/motd
  103. chmod -x /etc/update-motd.d/*
  104. if ! getent shadow root | grep -q "^root:[^\!*]"; then
  105. msg_info "Customizing Container"
  106. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  107. mkdir -p $(dirname $GETTY_OVERRIDE)
  108. cat <<EOF >$GETTY_OVERRIDE
  109. [Service]
  110. ExecStart=
  111. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  112. EOF
  113. systemctl daemon-reload
  114. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  115. msg_ok "Customized Container"
  116. fi
  117. if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi
  118. msg_info "Cleaning up"
  119. $STD apt-get autoremove
  120. $STD apt-get autoclean
  121. msg_ok "Cleaned"