unifi-install.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env bash -ex
  2. #https://community.ui.com/questions/UniFi-Installation-Scripts-or-UniFi-Easy-Update-Script-or-UniFi-Lets-Encrypt-or-UniFi-Easy-Encrypt-/ccbc7530-dd61-40a7-82ec-22b17f027776
  3. set -euo pipefail
  4. shopt -s inherit_errexit nullglob
  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. NUM=$RETRY_NUM
  13. CM="${GN}✓${CL}"
  14. CROSS="${RD}✗${CL}"
  15. BFR="\\r\\033[K"
  16. HOLD="-"
  17. function msg_info() {
  18. local msg="$1"
  19. echo -ne " ${HOLD} ${YW}${msg}..."
  20. }
  21. function msg_ok() {
  22. local msg="$1"
  23. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  24. }
  25. msg_info "Setting up Container OS "
  26. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  27. locale-gen >/dev/null
  28. while [ "$(hostname -I)" = "" ]; do
  29. 1>&2 echo -en "${CROSS}${RD} No Network! "
  30. sleep $RETRY_EVERY
  31. ((NUM--))
  32. if [ $NUM -eq 0 ]
  33. then
  34. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  35. exit 1
  36. fi
  37. done
  38. msg_ok "Set up Container OS"
  39. msg_ok "Network Connected: ${BL}$(hostname -I)"
  40. msg_info "Updating Container OS"
  41. apt update &>/dev/null
  42. apt-get -qqy upgrade &>/dev/null
  43. msg_ok "Updated Container OS"
  44. msg_info "Installing Dependencies"
  45. apt-get install -y curl &>/dev/null
  46. apt-get install -y sudo &>/dev/null
  47. msg_ok "Installed Dependencies"
  48. msg_info "Installing UniFi Network Application"
  49. wget -qL https://get.glennr.nl/unifi/install/install_latest/unifi-latest.sh && bash unifi-latest.sh --skip &>/dev/null
  50. msg_ok "Installed UniFi Network Application"
  51. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  52. if [[ $PASS != $ ]]; then
  53. msg_info "Customizing Container"
  54. rm /etc/motd
  55. rm /etc/update-motd.d/10-uname
  56. touch ~/.hushlogin
  57. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  58. mkdir -p $(dirname $GETTY_OVERRIDE)
  59. cat << EOF > $GETTY_OVERRIDE
  60. [Service]
  61. ExecStart=
  62. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  63. EOF
  64. systemctl daemon-reload
  65. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  66. msg_ok "Customized Container"
  67. fi
  68. msg_info "Cleaning up"
  69. apt-get autoremove >/dev/null
  70. apt-get autoclean >/dev/null
  71. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  72. msg_ok "Cleaned"