Files
vigil/setup
T

153 lines
4.3 KiB
Bash
Raw Normal View History

2022-10-28 17:17:05 +00:00
#!/usr/bin/env bash
readonly FILES=(
"./config/motion.conf"
"./config/msmtprc"
"./config/muttrc"
"./scripts/alert"
"./scripts/cameras"
"./scripts/notify"
"./scripts/sync"
)
B2_BUCKET="my-bucket-name"
CAMERA_NAME="Kitchen"
DOMAIN="kitchen.example.com"
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT="587"
EMAIL_USER="user@example.com"
2023-02-01 19:50:50 +00:00
MOTION_DIR="/var/lib/motion"
MOTION_LOG_FILE="/var/log/motion/motion.log"
2022-10-28 17:17:05 +00:00
MOTION_PASSWORD="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 24 ; echo '')"
MOTION_USER="${USER}"
NOTIFICATION_RECIPIENT="1234567890@sms.example.com"
2023-02-01 19:50:50 +00:00
PORT_CONTROL="8080"
PORT_STREAM="3000"
TLS_CERT="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem"
TLS_KEY="/etc/letsencrypt/live/${DOMAIN}/privkey.pem"
2022-10-28 17:17:05 +00:00
input_settings() {
local input
printf "B2 Bucket (%s): " "${B2_BUCKET}"
read -r input
B2_BUCKET="${input:-$B2_BUCKET}"
printf "Camera name (%s): " "${CAMERA_NAME}"
read -r input
CAMERA_NAME="${input:-$CAMERA_NAME}"
printf "Domain (%s): " "${DOMAIN}"
read -r input
DOMAIN="${input:-$DOMAIN}"
printf "Email host (%s): " "${EMAIL_HOST}"
read -r input
EMAIL_HOST="${input:-$EMAIL_HOST}"
printf "Email port (%s): " "${EMAIL_PORT}"
read -r input
EMAIL_PORT="${input:-$EMAIL_PORT}"
printf "Email user (%s): " "${EMAIL_USER}"
read -r input
EMAIL_USER="${input:-$EMAIL_USER}"
printf "Email password (%s): " "${EMAIL_PASSWORD}"
read -r input
EMAIL_PASSWORD="${input:-$EMAIL_PASSWORD}"
2023-02-01 19:50:50 +00:00
printf "Motion directory (%s): " "${MOTION_DIR}"
read -r input
MOTION_DIR="${input:-$MOTION_DIR}"
printf "Motion log file (%s): " "${MOTION_LOG_FILE}"
read -r input
MOTION_LOG_FILE="${input:-$MOTION_LOG_FILE}"
2022-10-28 17:17:05 +00:00
printf "Motion user (%s): " "${MOTION_USER}"
read -r input
MOTION_USER="${input:-$MOTION_USER}"
printf "Motion password (%s): " "${MOTION_PASSWORD}"
read -r input
MOTION_PASSWORD="${input:-$MOTION_PASSWORD}"
printf "Notification recipient (%s): " "${NOTIFICATION_RECIPIENT}"
read -r input
NOTIFICATION_RECIPIENT="${input:-$NOTIFICATION_RECIPIENT}"
2023-02-01 19:50:50 +00:00
printf "Webcontrol port (%s): " "${PORT_CONTROL}"
read -r input
PORT_CONTROL="${input:-$PORT_CONTROL}"
printf "Livestream port (%s): " "${PORT_STREAM}"
read -r input
PORT_STREAM="${input:-$PORT_STREAM}"
printf "TLS certifcate path (%s): " "${TLS_CERT}"
read -r input
TLS_CERT="${input:-$TLS_CERT}"
printf "TLS key path (%s): " "${TLS_KEY}"
read -r input
TLS_KEY="${input:-$TLS_KEY}"
2022-10-28 17:17:05 +00:00
}
print_settings() {
printf "Your settings:\n"
printf "B2 Bucket: %s\n" "${B2_BUCKET}"
printf "Camera name: %s\n" "${CAMERA_NAME}"
printf "Domain: %s\n" "${DOMAIN}"
printf "Email host: %s\n" "${EMAIL_HOST}"
printf "Email port: %s\n" "${EMAIL_PORT}"
printf "Email user: %s\n" "${EMAIL_USER}"
printf "Email password: %s\n" "${EMAIL_PASSWORD}"
2023-02-01 19:50:50 +00:00
printf "Motion directory: %s\n" "${MOTION_DIR}"
printf "Motion log file: %s\n" "${MOTION_LOG_FILE}"
2022-10-28 17:17:05 +00:00
printf "Motion user: %s\n" "${MOTION_USER}"
printf "Motion password: %s\n" "${MOTION_PASSWORD}"
2023-02-01 19:50:50 +00:00
printf "Webcontrol port: %s\n" "${PORT_CONTROL}"
printf "Livestream port: %s\n" "${PORT_STREAM}"
2022-10-28 17:17:05 +00:00
printf "Notification recipient: %s\n" "${NOTIFICATION_RECIPIENT}"
2023-02-01 19:50:50 +00:00
printf "TLS certificate: %s\n" "${TLS_CERT}"
printf "TLS key: %s\n" "${TLS_KEY}"
2022-10-28 17:17:05 +00:00
}
write_settings() {
for f in "${FILES[@]}"; do
sed -i "s/\${B2_BUCKET}/${B2_BUCKET}/g" "${f}"
sed -i "s/\${CAMERA_NAME}/${CAMERA_NAME}/g" "${f}"
sed -i "s/\${DOMAIN}/${DOMAIN}/g" "${f}"
sed -i "s/\${EMAIL_HOST}/${EMAIL_HOST}/g" "${f}"
2023-02-01 19:50:50 +00:00
sed -i "s/\${EMAIL_PASSWORD}/${EMAIL_PASSWORD}/g" "${f}"
2022-10-28 17:17:05 +00:00
sed -i "s/\${EMAIL_PORT}/${EMAIL_PORT}/g" "${f}"
sed -i "s/\${EMAIL_USER}/${EMAIL_USER}/g" "${f}"
2023-02-01 19:50:50 +00:00
sed -i "s/\${MOTION_DIR}/${MOTION_DIR}/g" "${f}"
sed -i "s/\${MOTION_LOG_FILE}/${MOTION_LOG_FILE}/g" "${f}"
2022-10-28 17:17:05 +00:00
sed -i "s/\${MOTION_PASSWORD}/${MOTION_PASSWORD}/g" "${f}"
2023-02-01 19:50:50 +00:00
sed -i "s/\${MOTION_USER}/${MOTION_USER}/g" "${f}"
2022-10-28 17:17:05 +00:00
sed -i "s/\${NOTIFICATION_RECIPIENT}/${NOTIFICATION_RECIPIENT}/g" "${f}"
2023-02-01 19:50:50 +00:00
sed -i "s/\${PORT_CONTROL}/${PORT_CONTROL}/g" "${f}"
sed -i "s/\${PORT_STREAM}/${PORT_STREAM}/g" "${f}"
sed -i "s/\${TLS_CERT}/${TLS_CERT}/g" "${f}"
sed -i "s/\${TLS_KEY}/${TLS_KEY}/g" "${f}"
2022-10-28 17:17:05 +00:00
done
}
main() {
input_settings
print_settings
echo "Update files?"
select yn in "yes" "no"; do
case "${yn}" in
yes ) write_settings && exit 0 ;;
no ) exit 0 ;;
esac
done
}
main "$@"