vigil

Security camera system built on motion and yolov7.
git clone git://code.dwrz.net/vigil
Log | Files | Refs

setup (5457B)


      1 #!/usr/bin/env bash
      2 
      3 readonly FILES=(
      4   "./config/motion.conf"
      5   "./config/msmtprc"
      6   "./config/muttrc"
      7   "./scripts/alert"
      8   "./scripts/cameras"
      9   "./scripts/notify"
     10   "./scripts/sync"
     11 )
     12 
     13 B2_BUCKET="my-bucket-name"
     14 CAMERA_NAME="Kitchen"
     15 DOMAIN="${HOSTNAME}"
     16 EMAIL_HOST="smtp.gmail.com"
     17 EMAIL_PORT="587"
     18 EMAIL_USER="user@example.com"
     19 MOTION_DIR="/var/lib/motion"
     20 MOTION_LOG_FILE="/var/log/motion/motion.log"
     21 MOTION_PASSWORD="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 24 ; echo '')"
     22 MOTION_USER="${USER}"
     23 NOTIFICATION_RECIPIENT="1234567890@sms.example.com"
     24 RSYNC_USER="user"
     25 RSYNC_SERVER="server"
     26 PORT_CONTROL="8080"
     27 PORT_STREAM="3000"
     28 TLS_CERT="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem"
     29 TLS_KEY="/etc/letsencrypt/live/${DOMAIN}/privkey.pem"
     30 
     31 input_settings() {
     32   local input
     33 
     34   printf "B2 Bucket (%s): " "${B2_BUCKET}"
     35   read -r input
     36   B2_BUCKET="${input:-$B2_BUCKET}"
     37 
     38   printf "Camera name (%s): " "${CAMERA_NAME}"
     39   read -r input
     40   CAMERA_NAME="${input:-$CAMERA_NAME}"
     41 
     42   printf "Domain (%s): " "${DOMAIN}"
     43   read -r input
     44   DOMAIN="${input:-$DOMAIN}"
     45 
     46   printf "Email host (%s): " "${EMAIL_HOST}"
     47   read -r input
     48   EMAIL_HOST="${input:-$EMAIL_HOST}"
     49 
     50   printf "Email port (%s): " "${EMAIL_PORT}"
     51   read -r input
     52   EMAIL_PORT="${input:-$EMAIL_PORT}"
     53 
     54   printf "Email user (%s): " "${EMAIL_USER}"
     55   read -r input
     56   EMAIL_USER="${input:-$EMAIL_USER}"
     57 
     58   printf "Email password (%s): " "${EMAIL_PASSWORD}"
     59   read -r input
     60   EMAIL_PASSWORD="${input:-$EMAIL_PASSWORD}"
     61 
     62   printf "Motion directory (%s): " "${MOTION_DIR}"
     63   read -r input
     64   MOTION_DIR="${input:-$MOTION_DIR}"
     65 
     66   printf "Motion log file (%s): " "${MOTION_LOG_FILE}"
     67   read -r input
     68   MOTION_LOG_FILE="${input:-$MOTION_LOG_FILE}"
     69 
     70   printf "Motion user (%s): " "${MOTION_USER}"
     71   read -r input
     72   MOTION_USER="${input:-$MOTION_USER}"
     73 
     74   printf "Motion password (%s): " "${MOTION_PASSWORD}"
     75   read -r input
     76   MOTION_PASSWORD="${input:-$MOTION_PASSWORD}"
     77 
     78   printf "Notification recipient (%s): " "${NOTIFICATION_RECIPIENT}"
     79   read -r input
     80   NOTIFICATION_RECIPIENT="${input:-$NOTIFICATION_RECIPIENT}"
     81 
     82   printf "Webcontrol port (%s): " "${PORT_CONTROL}"
     83   read -r input
     84   PORT_CONTROL="${input:-$PORT_CONTROL}"
     85 
     86   printf "Livestream port (%s): " "${PORT_STREAM}"
     87   read -r input
     88   PORT_STREAM="${input:-$PORT_STREAM}"
     89 
     90   printf "rsync user (%s): " "${RSYNC_USER}"
     91   read -r input
     92   RSYNC_USER="${input:-$RSYNC_USER}"
     93 
     94   printf "rsync server (%s): " "${RSYNC_SERVER}"
     95   read -r input
     96   RSYNC_SERVER="${input:-$RSYNC_SERVER}"
     97 
     98   printf "TLS certifcate path (%s): " "${TLS_CERT}"
     99   read -r input
    100   TLS_CERT="${input:-$TLS_CERT}"
    101 
    102   printf "TLS key path (%s): " "${TLS_KEY}"
    103   read -r input
    104   TLS_KEY="${input:-$TLS_KEY}"
    105 }
    106 
    107 print_settings() {
    108   printf "Your settings:\n"
    109   printf "B2 Bucket: %s\n" "${B2_BUCKET}"
    110   printf "Camera name: %s\n" "${CAMERA_NAME}"
    111   printf "Domain: %s\n" "${DOMAIN}"
    112   printf "Email host: %s\n" "${EMAIL_HOST}"
    113   printf "Email port: %s\n" "${EMAIL_PORT}"
    114   printf "Email user: %s\n" "${EMAIL_USER}"
    115   printf "Email password: %s\n" "${EMAIL_PASSWORD}"
    116   printf "Motion directory: %s\n" "${MOTION_DIR}"
    117   printf "Motion log file: %s\n" "${MOTION_LOG_FILE}"
    118   printf "Motion user: %s\n" "${MOTION_USER}"
    119   printf "Motion password: %s\n" "${MOTION_PASSWORD}"
    120   printf "Webcontrol port: %s\n" "${PORT_CONTROL}"
    121   printf "Livestream port: %s\n" "${PORT_STREAM}"
    122   printf "rsync user: %s\n" "${RSYNC_USER}"
    123   printf "rsync server: %s\n" "${RSYNC_SERVER}"
    124   printf "Notification recipient: %s\n" "${NOTIFICATION_RECIPIENT}"
    125   printf "TLS certificate: %s\n" "${TLS_CERT}"
    126   printf "TLS key: %s\n" "${TLS_KEY}"
    127 }
    128 
    129 write_settings() {
    130   for f in "${FILES[@]}"; do
    131     sed -i 's|\${B2_BUCKET}|'"${B2_BUCKET}"'|g' "${f}"
    132     sed -i 's|\${CAMERA_NAME}|'"${CAMERA_NAME}"'|g' "${f}"
    133     sed -i 's|\${DOMAIN}|'"${DOMAIN}"'|g' "${f}"
    134     sed -i 's|\${EMAIL_HOST}|'"${EMAIL_HOST}"'|g' "${f}"
    135     sed -i 's|\${EMAIL_PASSWORD}|'"${EMAIL_PASSWORD}"'|g' "${f}"
    136     sed -i 's|\${EMAIL_PORT}|'"${EMAIL_PORT}"'|g' "${f}"
    137     sed -i 's|\${EMAIL_USER}|'"${EMAIL_USER}"'|g' "${f}"
    138     sed -i 's|\${MOTION_DIR}|'"${MOTION_DIR}"'|g' "${f}"
    139     sed -i 's|\${MOTION_LOG_FILE}|'"${MOTION_LOG_FILE}"'|g' "${f}"
    140     sed -i 's|\${MOTION_PASSWORD}|'"${MOTION_PASSWORD}"'|g' "${f}"
    141     sed -i 's|\${MOTION_USER}|'"${MOTION_USER}"'|g' "${f}"
    142     sed -i 's|\${NOTIFICATION_RECIPIENT}|'"${NOTIFICATION_RECIPIENT}"'|g' "${f}"
    143     sed -i 's|\${PORT_CONTROL}|'"${PORT_CONTROL}"'|g' "${f}"
    144     sed -i 's|\${PORT_STREAM}|'"${PORT_STREAM}"'|g' "${f}"
    145     sed -i 's|\${RSYNC_USER}|'"${RSYNC_USER}"'|g' "${f}"
    146     sed -i 's|\${RSYNC_SERVER}|'"${RSYNC_SERVER}"'|g' "${f}"
    147     sed -i 's|\${TLS_CERT}|'"${TLS_CERT}"'|g' "${f}"
    148     sed -i 's|\${TLS_KEY}|'"${TLS_KEY}"'|g' "${f}"
    149   done
    150 }
    151 
    152 link_files() {
    153   chmod 400 "${PWD}/config/msmtprc"
    154 
    155   ln -s "${PWD}/config/motion.conf" "/etc/motion/motion.conf"
    156   ln -s "${PWD}/config/msmtprc" "${MOTION_DIR}/.msmtprc"
    157   ln -s "${PWD}/config/muttrc"  "${MOTION_DIR}/.muttrc"
    158   ln -s "${PWD}/scripts/alert" "${MOTION_DIR}/alert"
    159   ln -s "${PWD}/scripts/notify" "${MOTION_DIR}/notify"
    160   ln -s "${PWD}/scripts/sync" "${MOTION_DIR}/sync"
    161 }
    162 
    163 main() {
    164   input_settings
    165 
    166   print_settings
    167 
    168   echo "Update files?"
    169   select yn in "yes" "no"; do
    170     case "${yn}" in
    171       yes ) write_settings ;;
    172       no ) exit 0 ;;
    173     esac
    174   done
    175 
    176   echo "Link files?"
    177   select yn in "yes" "no"; do
    178     case "${yn}" in
    179       yes ) link_files && exit 0 ;;
    180       no ) exit 0 ;;
    181     esac
    182   done
    183 }
    184 
    185 main "$@"