motioneye-install.sh 3.4 KB

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