Refactor setup script

This commit is contained in:
dwrz
2023-02-01 19:50:50 +00:00
parent 767a306442
commit 680a0d8ec4
+44 -12
View File
@@ -16,62 +16,82 @@ DOMAIN="kitchen.example.com"
EMAIL_HOST="smtp.gmail.com" EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT="587" EMAIL_PORT="587"
EMAIL_USER="user@example.com" EMAIL_USER="user@example.com"
MOTION_DIR="/var/lib/motion"
MOTION_LOG_FILE="/var/log/motion/motion.log"
MOTION_PASSWORD="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 24 ; echo '')" MOTION_PASSWORD="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 24 ; echo '')"
MOTION_USER="${USER}" MOTION_USER="${USER}"
NOTIFICATION_RECIPIENT="1234567890@sms.example.com" NOTIFICATION_RECIPIENT="1234567890@sms.example.com"
PORT_CONTROL="8080"
PORT_STREAM="3000"
TLS_CERT="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem"
TLS_KEY="/etc/letsencrypt/live/${DOMAIN}/privkey.pem"
input_settings() { input_settings() {
local input local input
# Set the B2 bucket name.
printf "B2 Bucket (%s): " "${B2_BUCKET}" printf "B2 Bucket (%s): " "${B2_BUCKET}"
read -r input read -r input
B2_BUCKET="${input:-$B2_BUCKET}" B2_BUCKET="${input:-$B2_BUCKET}"
# Set the camera name.
printf "Camera name (%s): " "${CAMERA_NAME}" printf "Camera name (%s): " "${CAMERA_NAME}"
read -r input read -r input
CAMERA_NAME="${input:-$CAMERA_NAME}" CAMERA_NAME="${input:-$CAMERA_NAME}"
# Set the domain.
printf "Domain (%s): " "${DOMAIN}" printf "Domain (%s): " "${DOMAIN}"
read -r input read -r input
DOMAIN="${input:-$DOMAIN}" DOMAIN="${input:-$DOMAIN}"
# Set the Email user and sender.
printf "Email host (%s): " "${EMAIL_HOST}" printf "Email host (%s): " "${EMAIL_HOST}"
read -r input read -r input
EMAIL_HOST="${input:-$EMAIL_HOST}" EMAIL_HOST="${input:-$EMAIL_HOST}"
# Set the Email port and sender.
printf "Email port (%s): " "${EMAIL_PORT}" printf "Email port (%s): " "${EMAIL_PORT}"
read -r input read -r input
EMAIL_PORT="${input:-$EMAIL_PORT}" EMAIL_PORT="${input:-$EMAIL_PORT}"
# Set the Email user and sender.
printf "Email user (%s): " "${EMAIL_USER}" printf "Email user (%s): " "${EMAIL_USER}"
read -r input read -r input
EMAIL_USER="${input:-$EMAIL_USER}" EMAIL_USER="${input:-$EMAIL_USER}"
# Set the Email password.
printf "Email password (%s): " "${EMAIL_PASSWORD}" printf "Email password (%s): " "${EMAIL_PASSWORD}"
read -r input read -r input
EMAIL_PASSWORD="${input:-$EMAIL_PASSWORD}" EMAIL_PASSWORD="${input:-$EMAIL_PASSWORD}"
# Set the Motion user for webcontrol and livestream. 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}"
printf "Motion user (%s): " "${MOTION_USER}" printf "Motion user (%s): " "${MOTION_USER}"
read -r input read -r input
MOTION_USER="${input:-$MOTION_USER}" MOTION_USER="${input:-$MOTION_USER}"
# Set the Motion password for webcontrol and livestream.
printf "Motion password (%s): " "${MOTION_PASSWORD}" printf "Motion password (%s): " "${MOTION_PASSWORD}"
read -r input read -r input
MOTION_PASSWORD="${input:-$MOTION_PASSWORD}" MOTION_PASSWORD="${input:-$MOTION_PASSWORD}"
# Set the notification recipient.
printf "Notification recipient (%s): " "${NOTIFICATION_RECIPIENT}" printf "Notification recipient (%s): " "${NOTIFICATION_RECIPIENT}"
read -r input read -r input
NOTIFICATION_RECIPIENT="${input:-$NOTIFICATION_RECIPIENT}" NOTIFICATION_RECIPIENT="${input:-$NOTIFICATION_RECIPIENT}"
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}"
} }
print_settings() { print_settings() {
@@ -83,9 +103,15 @@ print_settings() {
printf "Email port: %s\n" "${EMAIL_PORT}" printf "Email port: %s\n" "${EMAIL_PORT}"
printf "Email user: %s\n" "${EMAIL_USER}" printf "Email user: %s\n" "${EMAIL_USER}"
printf "Email password: %s\n" "${EMAIL_PASSWORD}" printf "Email password: %s\n" "${EMAIL_PASSWORD}"
printf "Motion directory: %s\n" "${MOTION_DIR}"
printf "Motion log file: %s\n" "${MOTION_LOG_FILE}"
printf "Motion user: %s\n" "${MOTION_USER}" printf "Motion user: %s\n" "${MOTION_USER}"
printf "Motion password: %s\n" "${MOTION_PASSWORD}" printf "Motion password: %s\n" "${MOTION_PASSWORD}"
printf "Webcontrol port: %s\n" "${PORT_CONTROL}"
printf "Livestream port: %s\n" "${PORT_STREAM}"
printf "Notification recipient: %s\n" "${NOTIFICATION_RECIPIENT}" printf "Notification recipient: %s\n" "${NOTIFICATION_RECIPIENT}"
printf "TLS certificate: %s\n" "${TLS_CERT}"
printf "TLS key: %s\n" "${TLS_KEY}"
} }
write_settings() { write_settings() {
@@ -94,12 +120,18 @@ write_settings() {
sed -i "s/\${CAMERA_NAME}/${CAMERA_NAME}/g" "${f}" sed -i "s/\${CAMERA_NAME}/${CAMERA_NAME}/g" "${f}"
sed -i "s/\${DOMAIN}/${DOMAIN}/g" "${f}" sed -i "s/\${DOMAIN}/${DOMAIN}/g" "${f}"
sed -i "s/\${EMAIL_HOST}/${EMAIL_HOST}/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_PORT}/${EMAIL_PORT}/g" "${f}"
sed -i "s/\${EMAIL_USER}/${EMAIL_USER}/g" "${f}" sed -i "s/\${EMAIL_USER}/${EMAIL_USER}/g" "${f}"
sed -i "s/\${EMAIL_PASSWORD}/${EMAIL_PASSWORD}/g" "${f}" sed -i "s/\${MOTION_DIR}/${MOTION_DIR}/g" "${f}"
sed -i "s/\${MOTION_USER}/${MOTION_USER}/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_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/\${NOTIFICATION_RECIPIENT}/${NOTIFICATION_RECIPIENT}/g" "${f}"
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}"
done done
} }