motioneye-install.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env bash -ex
  2. set -euo pipefail
  3. shopt -s inherit_errexit nullglob
  4. YW=`echo "\033[33m"`
  5. RD=`echo "\033[01;31m"`
  6. BL=`echo "\033[36m"`
  7. GN=`echo "\033[1;92m"`
  8. CL=`echo "\033[m"`
  9. RETRY_NUM=10
  10. RETRY_EVERY=3
  11. NUM=$RETRY_NUM
  12. CM="${GN}✓${CL}"
  13. CROSS="${RD}✗${CL}"
  14. BFR="\\r\\033[K"
  15. HOLD="-"
  16. function msg_info() {
  17. local msg="$1"
  18. echo -ne " ${HOLD} ${YW}${msg}..."
  19. }
  20. function msg_ok() {
  21. local msg="$1"
  22. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  23. }
  24. msg_info "Setting up Container OS "
  25. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  26. locale-gen >/dev/null
  27. while [ "$(hostname -I)" = "" ]; do
  28. 1>&2 echo -en "${CROSS}${RD} No Network! "
  29. sleep $RETRY_EVERY
  30. ((NUM--))
  31. if [ $NUM -eq 0 ]
  32. then
  33. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  34. exit 1
  35. fi
  36. done
  37. msg_ok "Set up Container OS"
  38. msg_ok "Network Connected: ${BL}$(hostname -I)"
  39. msg_info "Updating Container OS"
  40. apt update &>/dev/null
  41. apt-get -qqy upgrade &>/dev/null
  42. msg_ok "Updated Container OS"
  43. msg_info "Installing Dependencies"
  44. apt-get install -y curl &>/dev/null
  45. apt-get install -y sudo &>/dev/null
  46. msg_ok "Installed Dependencies"
  47. echo -en "${GN} Installing Motion... "
  48. apt-get install motion -y &>/dev/null
  49. systemctl stop motion &>/dev/null
  50. systemctl disable motion &>/dev/null
  51. echo -e "${CM}${CL} \r"
  52. msg_info "Installing FFmpeg"
  53. apt-get install ffmpeg v4l-utils -y &>/dev/null
  54. msg_ok "Installed FFmpeg"
  55. msg_info "Installing Python"
  56. apt-get update &>/dev/null
  57. apt-get install python2 -y &>/dev/null
  58. curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py &>/dev/null
  59. python2 get-pip.py &>/dev/null
  60. apt-get install libffi-dev libzbar-dev libzbar0 -y &>/dev/null
  61. apt-get install python2-dev libssl-dev libcurl4-openssl-dev libjpeg-dev -y &>/dev/null
  62. msg_ok "Installed Python"
  63. msg_info "Installing MotionEye"
  64. apt-get update &>/dev/null
  65. sudo pip install motioneye &>/dev/null
  66. mkdir -p /etc/motioneye
  67. cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf
  68. mkdir -p /var/lib/motioneye
  69. msg_ok "Installed MotionEye"
  70. msg_info "Creating Service"
  71. cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service &>/dev/null
  72. systemctl enable motioneye &>/dev/null
  73. systemctl start motioneye
  74. msg_ok "Created Service"
  75. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  76. if [[ $PASS != $ ]]; then
  77. msg_info "Customizing Container"
  78. rm /etc/motd
  79. rm /etc/update-motd.d/10-uname
  80. touch ~/.hushlogin
  81. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  82. mkdir -p $(dirname $GETTY_OVERRIDE)
  83. cat << EOF > $GETTY_OVERRIDE
  84. [Service]
  85. ExecStart=
  86. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  87. EOF
  88. systemctl daemon-reload
  89. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  90. msg_ok "Customized Container"
  91. fi
  92. msg_info "Cleaning up"
  93. apt-get autoremove >/dev/null
  94. apt-get autoclean >/dev/null
  95. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  96. msg_ok "Cleaned"