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"
|
2023-02-02 14:46:35 +00:00
|
|
|
DOMAIN="${HOSTNAME}"
|
2022-10-28 17:17:05 +00:00
|
|
|
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-05-28 18:28:18 +00:00
|
|
|
RSYNC_USER="user"
|
|
|
|
|
RSYNC_SERVER="server"
|
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}"
|
|
|
|
|
|
2023-05-28 18:28:18 +00:00
|
|
|
printf "rsync user (%s): " "${RSYNC_USER}"
|
|
|
|
|
read -r input
|
|
|
|
|
RSYNC_USER="${input:-$RSYNC_USER}"
|
|
|
|
|
|
|
|
|
|
printf "rsync server (%s): " "${RSYNC_SERVER}"
|
|
|
|
|
read -r input
|
|
|
|
|
RSYNC_SERVER="${input:-$RSYNC_SERVER}"
|
|
|
|
|
|
2023-02-01 19:50:50 +00:00
|
|
|
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}"
|
2023-05-28 18:28:18 +00:00
|
|
|
printf "rsync user: %s\n" "${RSYNC_USER}"
|
|
|
|
|
printf "rsync server: %s\n" "${RSYNC_SERVER}"
|
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
|
2023-02-02 14:46:35 +00:00
|
|
|
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}"
|
|
|
|
|
sed -i 's|\${EMAIL_PASSWORD}|'"${EMAIL_PASSWORD}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${EMAIL_PORT}|'"${EMAIL_PORT}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${EMAIL_USER}|'"${EMAIL_USER}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${MOTION_DIR}|'"${MOTION_DIR}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${MOTION_LOG_FILE}|'"${MOTION_LOG_FILE}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${MOTION_PASSWORD}|'"${MOTION_PASSWORD}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${MOTION_USER}|'"${MOTION_USER}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${NOTIFICATION_RECIPIENT}|'"${NOTIFICATION_RECIPIENT}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${PORT_CONTROL}|'"${PORT_CONTROL}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${PORT_STREAM}|'"${PORT_STREAM}"'|g' "${f}"
|
2023-05-28 18:28:18 +00:00
|
|
|
sed -i 's|\${RSYNC_USER}|'"${RSYNC_USER}"'|g' "${f}"
|
|
|
|
|
sed -i 's|\${RSYNC_SERVER}|'"${RSYNC_SERVER}"'|g' "${f}"
|
2023-02-02 14:46:35 +00:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 14:46:35 +00:00
|
|
|
link_files() {
|
2023-02-02 15:39:39 +00:00
|
|
|
chmod 400 "${PWD}/config/msmtprc"
|
|
|
|
|
|
2023-02-02 15:30:21 +00:00
|
|
|
ln -s "${PWD}/config/motion.conf" "/etc/motion/motion.conf"
|
|
|
|
|
ln -s "${PWD}/config/msmtprc" "${MOTION_DIR}/.msmtprc"
|
|
|
|
|
ln -s "${PWD}/config/muttrc" "${MOTION_DIR}/.muttrc"
|
|
|
|
|
ln -s "${PWD}/scripts/alert" "${MOTION_DIR}/alert"
|
|
|
|
|
ln -s "${PWD}/scripts/notify" "${MOTION_DIR}/notify"
|
|
|
|
|
ln -s "${PWD}/scripts/sync" "${MOTION_DIR}/sync"
|
2023-02-02 14:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-28 17:17:05 +00:00
|
|
|
main() {
|
|
|
|
|
input_settings
|
|
|
|
|
|
|
|
|
|
print_settings
|
|
|
|
|
|
|
|
|
|
echo "Update files?"
|
|
|
|
|
select yn in "yes" "no"; do
|
|
|
|
|
case "${yn}" in
|
2023-02-02 14:46:35 +00:00
|
|
|
yes ) write_settings ;;
|
|
|
|
|
no ) exit 0 ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "Link files?"
|
|
|
|
|
select yn in "yes" "no"; do
|
|
|
|
|
case "${yn}" in
|
|
|
|
|
yes ) link_files && exit 0 ;;
|
2022-10-28 17:17:05 +00:00
|
|
|
no ) exit 0 ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|