motioneye-install.sh 3.2 KB

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