From 84ade4d9e47faaf4f5b5b0c0a7422e639b0e8ce9 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 19:38:35 +0000 Subject: [PATCH 1/7] README.md: drop misleading statement about building the docker image Docker image is being pulled now, not built. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index b70f9bec..16629fd8 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ The most convenient way to install the Bluecherry docker image is to use this sc The included Dockerfile generates an image based on an **Ubuntu 20.04** docker image. The latest tagged version of the **Bluecherry Server v3.x.x** from the [bluecherry-apps](https://github.com/bluecherrydvr/bluecherry-apps) source repository. The included docker-compose file uses **MySQL version 8.x.x** to host the bluecherry database. -The current version of this docker code intends to build a bluecherry docker image that is as small as possible, and which does *not* bake in any configuration into the image (since docker images are intended to be ephemeral). - Instead, needed configuration parameters such as database and server passwords are passed into the docker container via environment variables. Environment variables are defined and passed using typical methods with `docker` or `docker-compose` commands. ## Initialization and Usage From 6c5861baa2512f49d17714bf99c292619f06b5b3 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 19:39:25 +0000 Subject: [PATCH 2/7] Drop duplicate configure_nfs function body and duplicate commented out prompts --- scripts/install.sh | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 9e9fd1ea..7f81cb7d 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -136,7 +136,6 @@ read -p "Please provide the SMTP password: " smtppassword read -p "Please provide the SMTP port: " smtpport #read -p "Please provide the SMTP username: " smtplogin -#read -p "Please provide the NFS mount point for the NFS export" nfsmountpoint echo " @@ -196,7 +195,6 @@ echo "installing nfs" read -p "Please provide the IP address of the NFS server: " nfsserver read -p "Please provide the NFS server export path: " nfsexport -#read -p "Please provide the NFS mount point for the NFS export" nfsmountpoint echo " @@ -432,32 +430,6 @@ case $add_nfs in esac -configure_nfs() { - -echo "installing nfs" - -read -p "Please provide the IP address of the NFS server: " nfsserver -read -p "Please provide the NFS server export path: " nfsexport - -echo " - -version: '3.8' -services: - - bluecherry: - volumes: -# - ./recordings:/var/lib/bluecherry/recordings - - videos:/media/bluecherry/nfs - -volumes: - videos: - driver_opts: - type: "nfs" - o: "addr=$nfsserver,nolock,soft" - device: ":$nfsexport" -" > $workingpath/bluecherry-docker/docker-compose.override.yml - -} # Let the user know how to access to Bluecherry web UI IP=$(ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') From 88d079f4abd4fffbd602f70163f3dfc282d6c3ce Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 19:48:51 +0000 Subject: [PATCH 3/7] scripts/install.sh: switch shebang to bash and go full strict mode --- scripts/install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 7f81cb7d..03641eaf 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,5 +1,7 @@ -#!/bin/sh +#!/bin/bash set -e +set -u +set -o pipefail export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin From f975bcf9cfd4d4e319a5d3571775c2da2365ecc1 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 20:06:00 +0000 Subject: [PATCH 4/7] scripts/install.sh: reindent --- scripts/install.sh | 343 ++++++++++++++++++++++----------------------- 1 file changed, 168 insertions(+), 175 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 03641eaf..c93420db 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -27,67 +27,67 @@ check_docker_process() { docker_compose_init() { -# Make sure we are still in the bluecherry-docker directory + # Make sure we are still in the bluecherry-docker directory -#uptimekuma + #uptimekuma -echo "Downloading latest Bluecherry and related images...this may take a while..." + echo "Downloading latest Bluecherry and related images...this may take a while..." -cd "$workingpath/bluecherry-docker" + cd "$workingpath/bluecherry-docker" -# Init the mailenv config + # Init the mailenv config -cp $workingpath/bluecherry-docker/mailenv-example $workingpath/bluecherry-docker/.mailenv + cp $workingpath/bluecherry-docker/mailenv-example $workingpath/bluecherry-docker/.mailenv -docker compose pull -docker compose up bc-mysql -d + docker compose pull + docker compose up bc-mysql -d -echo "Sleeping 45 seconds to make sure the database is initialized correctly..." + echo "Sleeping 45 seconds to make sure the database is initialized correctly..." -sleep 45 -docker compose stop bc-mysql -docker compose up -d bc-mysql + sleep 45 + docker compose stop bc-mysql + docker compose up -d bc-mysql -echo "Sleeping another 15 seconds to run the database creation scripts..." -echo "\n\n" + echo "Sleeping another 15 seconds to run the database creation scripts..." + echo "\n\n" -sleep 15 -docker compose run bluecherry bc-database-create -docker compose down -#for i in {1..50}; do -# if docker compose pull; then -# if docker compose up -d; then -# break -# fi -# fi + sleep 15 + docker compose run bluecherry bc-database-create + docker compose down + #for i in {1..50}; do + # if docker compose pull; then + # if docker compose up -d; then + # break + # fi + # fi sleep 10 -docker compose up -d -#done + docker compose up -d + #done } configure_env() { -echo "\n\n******************************************************************\n\n" -echo "You will be asked the following to configure the docker container: + echo "\n\n******************************************************************\n\n" + echo "You will be asked the following to configure the docker container: Time Zone (formatted like this - See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) Create a password for the mysql admin Create a password for the mysql bluecherry user " -echo "Time Zone (i.e. - America/Chicago): " -read timezoneset + echo "Time Zone (i.e. - America/Chicago): " + read timezoneset -#read -p "Time Zone (i.e. - America/Chicago):" timezone -#timezoneset="${timezone:=American/Chicago}" -read -p "Please provide a mysql admin password:" mysqladminpass -read -p "Please provide a mysql bluecherry password:" mysqlbluecherrypass + #read -p "Time Zone (i.e. - America/Chicago):" timezone + #timezoneset="${timezone:=American/Chicago}" + read -p "Please provide a mysql admin password:" mysqladminpass + read -p "Please provide a mysql bluecherry password:" mysqlbluecherrypass -# Install variables -echo " + # Install variables + echo " # Set to your desired timezone. See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones TZ=$timezoneset @@ -130,16 +130,16 @@ BLUECHERRY_USER_ID=1000 configure_smtp() { -echo "Configure SMTP" + echo "Configure SMTP" -read -p "Please provide the SMTP server: " smtpserver -read -p "Please provide the SMTP username: " smtplogin -read -p "Please provide the SMTP password: " smtppassword -read -p "Please provide the SMTP port: " smtpport -#read -p "Please provide the SMTP username: " smtplogin + read -p "Please provide the SMTP server: " smtpserver + read -p "Please provide the SMTP username: " smtplogin + read -p "Please provide the SMTP password: " smtppassword + read -p "Please provide the SMTP port: " smtpport + #read -p "Please provide the SMTP username: " smtplogin -echo " + echo " SMTP_USERNAME=$smtplogin SMTP_PASSWORD=$smtppassword @@ -153,52 +153,50 @@ ALWAYS_ADD_MISSING_HEADERS=yes } check_process() { - process_name=$1 - status=$(docker ps --filter "name=$process_name" --format '{{.Names}}' | grep -w "$process_name") - - if [ -n "$status" ]; then - echo "\e[32m$process_name is running\e[0m" # Green color for running process - -#exit 1 - else - echo "\e[31m$process_name is not running\e[0m" # Red color for not running process - fi -#exit 1 + process_name=$1 + status=$(docker ps --filter "name=$process_name" --format '{{.Names}}' | grep -w "$process_name") + if [ -n "$status" ]; then + echo "\e[32m$process_name is running\e[0m" # Green color for running process + #exit 1 + else + echo "\e[31m$process_name is not running\e[0m" # Red color for not running process + fi + #exit 1 } check_docker_processes() { - if docker ps --format '{{.Names}}' | grep -q -w 'bc-server' && docker ps --format '{{.Names}}' | grep -q -w 'bc-mysql'; then - echo "**********************************************************************" - echo - echo "Installation finished, you can access the Bluecherry server here below" - echo "The default login is Admin and the default password is bluecherry" - echo - echo "https://$IP:7001" - echo - echo "**********************************************************************" - else - echo -e "\n\n\e[31mWARNING: Either bc-server or bc-mysql process is not running in Docker. Below is a listing of the current bc-server and bc-mysql processes\e[0m\n\n" - echo -e "If you are unable to resolve this issue please visit the Bluecherry community at https://forums.bluecherrydvr.com\n\n" - echo -e "Below are statuses of the 'bc-server' and 'bc-mysql' containers:\n\n" -check_process "bc-server" -check_process "bc-mysql" - echo -e "\n\n" - - fi + if docker ps --format '{{.Names}}' | grep -q -w 'bc-server' && docker ps --format '{{.Names}}' | grep -q -w 'bc-mysql'; then + echo "**********************************************************************" + echo + echo "Installation finished, you can access the Bluecherry server here below" + echo "The default login is Admin and the default password is bluecherry" + echo + echo "https://$IP:7001" + echo + echo "**********************************************************************" + else + echo -e "\n\n\e[31mWARNING: Either bc-server or bc-mysql process is not running in Docker. Below is a listing of the current bc-server and bc-mysql processes\e[0m\n\n" + echo -e "If you are unable to resolve this issue please visit the Bluecherry community at https://forums.bluecherrydvr.com\n\n" + echo -e "Below are statuses of the 'bc-server' and 'bc-mysql' containers:\n\n" + check_process "bc-server" + check_process "bc-mysql" + echo -e "\n\n" + + fi } configure_nfs() { -echo "installing nfs" + echo "installing nfs" -read -p "Please provide the IP address of the NFS server: " nfsserver -read -p "Please provide the NFS server export path: " nfsexport + read -p "Please provide the IP address of the NFS server: " nfsserver + read -p "Please provide the NFS server export path: " nfsexport -echo " + echo " version: '3.8' services: @@ -221,27 +219,27 @@ volumes: clone_bluecherrydocker() { - local directory=$pwd/bluecherry-docker + local directory=$pwd/bluecherry-docker if [ -d "$directory" ]; then echo "Directory $directory exists...skipping...." - return 0 -else + return 0 + else -echo "Directory $directory...proceeding with cloning" + echo "Directory $directory...proceeding with cloning" -cd "$workingpath" -#mkdir bluecherry-server -#cd bluecherry-server -git clone https://github.com/bluecherrydvr/bluecherry-docker.git + cd "$workingpath" + #mkdir bluecherry-server + #cd bluecherry-server + git clone https://github.com/bluecherrydvr/bluecherry-docker.git -# Sigh...Fedora LXC containers and maybe others set max keys at 2000. We need more. For now more systems are needed to test on. -# https://unix.stackexchange.com/questions/600968/disk-quota-exceeded-when-trying-to-deploy-docker-container-inside-lxc -#echo 5000 | tee /proc/sys/kernel/keys/maxkeys -#echo "kernel.keys.maxkeys=5000" > /etc/sysctl.d/99-custom.conf + # Sigh...Fedora LXC containers and maybe others set max keys at 2000. We need more. For now more systems are needed to test on. + # https://unix.stackexchange.com/questions/600968/disk-quota-exceeded-when-trying-to-deploy-docker-container-inside-lxc + #echo 5000 | tee /proc/sys/kernel/keys/maxkeys + #echo "kernel.keys.maxkeys=5000" > /etc/sysctl.d/99-custom.conf -#return 1 -fi + #return 1 + fi } @@ -249,86 +247,86 @@ fi install_bluecherry() { -echo -e "\n\nInstalling Bluecherry.......\n\n" - -distribution=$(detect_distribution) - -case $distribution in - "debian" | "ubuntu") - install_debian_packages - ;; - "centos" | "rhel" | "fedora" | "rocky" | "Rocky") - install_redhat_packages - ;; - "sles" | "opensuse" | "suse") - install_suse_packages - ;; - "arch") - install_arch_packages - ;; - "fedora") - install_fedora_packages - ;; - # Add cases for other distributions and call the appropriate installation functions - *) - echo "Unsupported distribution, please contact Bluecherry for support in adding your distribution. Please provide output of /etc/os-release and /etc/lsb_release" - exit 1 - ;; -esac + echo -e "\n\nInstalling Bluecherry.......\n\n" + + distribution=$(detect_distribution) + + case $distribution in + "debian" | "ubuntu") + install_debian_packages + ;; + "centos" | "rhel" | "fedora" | "rocky" | "Rocky") + install_redhat_packages + ;; + "sles" | "opensuse" | "suse") + install_suse_packages + ;; + "arch") + install_arch_packages + ;; + "fedora") + install_fedora_packages + ;; + # Add cases for other distributions and call the appropriate installation functions + *) + echo "Unsupported distribution, please contact Bluecherry for support in adding your distribution. Please provide output of /etc/os-release and /etc/lsb_release" + exit 1 + ;; + esac } # Function to detect the Linux distribution detect_distribution() { - if [ -f "/etc/os-release" ]; then - . /etc/os-release - echo "$ID" - else - echo "Unsupported distribution" - exit 1 - fi + if [ -f "/etc/os-release" ]; then + . /etc/os-release + echo "$ID" + else + echo "Unsupported distribution" + exit 1 + fi } # Function to install packages on Debian-based distributions install_debian_packages() { - apt-get update - apt-get install -y git + apt-get update + apt-get install -y git } # Function to install packages on Red Hat-based distributions install_redhat_packages() { - yum update - yum install -y git - install_docker -# Fix mainly for rocky...but we will try on all RHEL releases - sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/docker.service - sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/containerd.service - systemctl daemon-reload - systemctl stop docker - systemctl start docker + yum update + yum install -y git + install_docker + # Fix mainly for rocky...but we will try on all RHEL releases + sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/docker.service + sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/containerd.service + systemctl daemon-reload + systemctl stop docker + systemctl start docker } # Function to install packages on SUSE-based distributions install_suse_packages() { - zypper refresh - zypper install -y git - install_docker + zypper refresh + zypper install -y git + install_docker } # Function to install packages on Arch Linux install_arch_packages() { - pacman -Syu --noconfirm git - install_docker - sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/docker.service - sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/containerd.service - systemctl start docker - systemctl enable docker - pacman -Syu --noconfirm docker-compose + pacman -Syu --noconfirm git + install_docker + sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/docker.service + sed -i 's/^LimitNOFILE=infinity$/LimitNOFILE=1048576/' /usr/lib/systemd/system/containerd.service + systemctl start docker + systemctl enable docker + pacman -Syu --noconfirm docker-compose } # Function to install packages on Fedora install_fedora_packages() { - dnf update - dnf install -y git - install_docker + dnf update + dnf install -y git + install_docker } install_docker() { @@ -336,36 +334,31 @@ install_docker() { if command -v docker > /dev/null 2>&1; then echo -e "\n\nDocker is installed....skipping!\n\n" return 0 - else - - - curl -fsSL https://get.docker.com -o /tmp/install-docker.sh - sh /tmp/install-docker.sh - systemctl start docker - systemctl enable docker + curl -fsSL https://get.docker.com -o /tmp/install-docker.sh + sh /tmp/install-docker.sh + systemctl start docker + systemctl enable docker fi } uptimekuma() { -echo -e "Installing Uptime Kuma for monitoring of Bluecherry services\n\n" - - DOWNLOAD_URL='https://github.com/louislam/uptime-kuma/releases/download/1.21.3/dist.tar.gz' + echo -e "Installing Uptime Kuma for monitoring of Bluecherry services\n\n" - cd "$workingpath/bluecherry-docker" || exit 1 + DOWNLOAD_URL='https://github.com/louislam/uptime-kuma/releases/download/1.21.3/dist.tar.gz' - wget "${DOWNLOAD_URL}" - tar -zxf "$workingpath/dist.tar.gz" -C "$workingpath" + cd "$workingpath/bluecherry-docker" || exit 1 + wget "${DOWNLOAD_URL}" + tar -zxf "$workingpath/dist.tar.gz" -C "$workingpath" + echo -e "Installing Uptime Kuma for monitoring of Bluecherry services\n\n" -echo -e "Installing Uptime Kuma for monitoring of Bluecherry services\n\n" - -cd bluecherry-docker -wget https://github.com/louislam/uptime-kuma/releases/download/1.21.3/dist.tar.gz -tar -xvf dist.tar.gz + cd bluecherry-docker + wget https://github.com/louislam/uptime-kuma/releases/download/1.21.3/dist.tar.gz + tar -xvf dist.tar.gz } read -p "Do you want to install docker and setup Bluecherry server? [y/n]: " answer @@ -373,10 +366,10 @@ read -p "Do you want to install docker and setup Bluecherry server? [y/n]: " ans # Execute the appropriate function based on the answer case $answer in y) - install_docker - install_bluecherry -# configure_env - #clone_bluecherrydocker + install_docker + install_bluecherry + # configure_env + #clone_bluecherrydocker ;; n) ;; @@ -389,12 +382,12 @@ read -p "Do you want to download and configure the Bluecherry docker images? If case $clonedocker in y) -clone_bluecherrydocker -configure_env -docker_compose_init + clone_bluecherrydocker + configure_env + docker_compose_init ;; n) -# exit + # exit ;; *) echo "Invalid answer" @@ -408,7 +401,7 @@ case $smtp in configure_smtp ;; n) -# exit + # exit ;; *) echo "Invalid answer" @@ -422,9 +415,9 @@ read -p "Do you want to add a NFS mount? [y/n]: " add_nfs case $add_nfs in y) configure_nfs -;; + ;; n) -# exit + # exit ;; *) echo "Invalid answer" From 93db4f236ca43096913e3d506fa72b0f9c212d2d Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 20:33:53 +0000 Subject: [PATCH 5/7] scripts/install.sh: fix or suppress shellcheck warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $ shellcheck scripts/install.sh In scripts/install.sh line 10: [ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; } ^------^ SC2046 (warning): Quote this to prevent word splitting. In scripts/install.sh line 41: cp $workingpath/bluecherry-docker/mailenv-example $workingpath/bluecherry-docker/.mailenv ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting. ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: cp "$workingpath"/bluecherry-docker/mailenv-example "$workingpath"/bluecherry-docker/.mailenv In scripts/install.sh line 53: echo "\n\n" ^----^ SC2028 (info): echo may not expand escape sequences. Use printf. In scripts/install.sh line 72: echo "\n\n******************************************************************\n\n" ^-- SC2028 (info): echo may not expand escape sequences. Use printf. In scripts/install.sh line 81: read timezoneset ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 85: read -p "Please provide a mysql admin password:" mysqladminpass ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 86: read -p "Please provide a mysql bluecherry password:" mysqlbluecherrypass ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 123: # run `id $(whoami)` to find the UID/GID of your user ^------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`. ^-------^ SC2046 (warning): Quote this to prevent word splitting. Did you mean: # run $(id $(whoami)) to find the UID/GID of your user In scripts/install.sh line 135: read -p "Please provide the SMTP server: " smtpserver ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 136: read -p "Please provide the SMTP username: " smtplogin ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 137: read -p "Please provide the SMTP password: " smtppassword ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 138: read -p "Please provide the SMTP port: " smtpport ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 151: " > $workingpath/bluecherry-docker/.mailenv ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: " > "$workingpath"/bluecherry-docker/.mailenv In scripts/install.sh line 196: read -p "Please provide the IP address of the NFS server: " nfsserver ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 197: read -p "Please provide the NFS server export path: " nfsexport ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 212: type: "nfs" ^-^ SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? In scripts/install.sh line 213: o: "addr=$nfsserver,nolock,soft" ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: o: "addr="$nfsserver",nolock,soft" In scripts/install.sh line 214: device: ":$nfsexport" ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: device: ":"$nfsexport"" In scripts/install.sh line 215: " > $workingpath/bluecherry-docker/docker-compose.override.yml ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: " > "$workingpath"/bluecherry-docker/docker-compose.override.yml In scripts/install.sh line 222: local directory=$pwd/bluecherry-docker ^--^ SC2154 (warning): pwd is referenced but not assigned (for output from commands, use "$(pwd ...)" ). In scripts/install.sh line 258: "centos" | "rhel" | "fedora" | "rocky" | "Rocky") ^------^ SC2221 (warning): This pattern always overrides a later one on line 267. In scripts/install.sh line 267: "fedora") ^------^ SC2222 (warning): This pattern never matches because of a previous pattern on line 258. In scripts/install.sh line 280: . /etc/os-release ^-------------^ SC1091 (info): Not following: /etc/os-release was not specified as input (see shellcheck -x). In scripts/install.sh line 364: read -p "Do you want to install docker and setup Bluecherry server? [y/n]: " answer ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 381: read -p "Do you want to download and configure the Bluecherry docker images? If this is the first run of the script then select 'y' [y/n]: " clonedocker ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 397: read -p "Do you want to configure SMTP settings? [y/n]: " smtp ^--^ SC2162 (info): read without -r will mangle backslashes. In scripts/install.sh line 413: read -p "Do you want to add a NFS mount? [y/n]: " add_nfs ^--^ SC2162 (info): read without -r will mangle backslashes. --- scripts/install.sh | 48 ++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index c93420db..a7a8e5f6 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -7,7 +7,7 @@ export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Make sure we are root or we sudo'd! -[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; } +[ "$(id -u)" != "0" ] && { echo "Error: You must be root to run this script"; exit 1; } # set the current path so we aren't confused when moving directories. Always assuming $workingpath/bluecherry-docker for all Bluecherry scripts @@ -38,7 +38,7 @@ docker_compose_init() { # Init the mailenv config - cp $workingpath/bluecherry-docker/mailenv-example $workingpath/bluecherry-docker/.mailenv + cp "$workingpath"/bluecherry-docker/mailenv-example "$workingpath"/bluecherry-docker/.mailenv docker compose pull docker compose up bc-mysql -d @@ -50,7 +50,7 @@ docker_compose_init() { docker compose up -d bc-mysql echo "Sleeping another 15 seconds to run the database creation scripts..." - echo "\n\n" + echo -e "\n\n" sleep 15 docker compose run bluecherry bc-database-create @@ -69,7 +69,7 @@ docker_compose_init() { configure_env() { - echo "\n\n******************************************************************\n\n" + echo -e "\n\n******************************************************************\n\n" echo "You will be asked the following to configure the docker container: Time Zone (formatted like this - See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) @@ -78,12 +78,12 @@ Create a password for the mysql bluecherry user " echo "Time Zone (i.e. - America/Chicago): " - read timezoneset + read -r timezoneset #read -p "Time Zone (i.e. - America/Chicago):" timezone #timezoneset="${timezone:=American/Chicago}" - read -p "Please provide a mysql admin password:" mysqladminpass - read -p "Please provide a mysql bluecherry password:" mysqlbluecherrypass + read -r -p "Please provide a mysql admin password:" mysqladminpass + read -r -p "Please provide a mysql bluecherry password:" mysqlbluecherrypass # Install variables @@ -120,7 +120,7 @@ BLUECHERRY_USERHOST=% # UID/GID to run bluecherry user as. If you want to access recordings from the host, it is # recommended to set them the same as a user/group that you want access to read it. -# run `id $(whoami)` to find the UID/GID of your user +# run \`id \$(whoami)\` to find the UID/GID of your user BLUECHERRY_GROUP_ID=1000 BLUECHERRY_USER_ID=1000 @@ -132,10 +132,10 @@ configure_smtp() { echo "Configure SMTP" - read -p "Please provide the SMTP server: " smtpserver - read -p "Please provide the SMTP username: " smtplogin - read -p "Please provide the SMTP password: " smtppassword - read -p "Please provide the SMTP port: " smtpport + read -r -p "Please provide the SMTP server: " smtpserver + read -r -p "Please provide the SMTP username: " smtplogin + read -r -p "Please provide the SMTP password: " smtppassword + read -r -p "Please provide the SMTP port: " smtpport #read -p "Please provide the SMTP username: " smtplogin @@ -148,7 +148,7 @@ SMTP_PORT=$smtpport SERVER_HOSTNAME=$smtpserver ALWAYS_ADD_MISSING_HEADERS=yes -" > $workingpath/bluecherry-docker/.mailenv +" > "$workingpath"/bluecherry-docker/.mailenv } @@ -193,8 +193,8 @@ configure_nfs() { echo "installing nfs" - read -p "Please provide the IP address of the NFS server: " nfsserver - read -p "Please provide the NFS server export path: " nfsexport + read -r -p "Please provide the IP address of the NFS server: " nfsserver + read -r -p "Please provide the NFS server export path: " nfsexport echo " @@ -209,17 +209,18 @@ services: volumes: videos: driver_opts: - type: "nfs" - o: "addr=$nfsserver,nolock,soft" - device: ":$nfsexport" -" > $workingpath/bluecherry-docker/docker-compose.override.yml + type: \"nfs\" + o: \"addr=$nfsserver,nolock,soft\" + device: \":$nfsexport\" +" > "$workingpath"/bluecherry-docker/docker-compose.override.yml } clone_bluecherrydocker() { - local directory=$pwd/bluecherry-docker + local directory + directory="$(pwd)"/bluecherry-docker if [ -d "$directory" ]; then echo "Directory $directory exists...skipping...." return 0 @@ -255,7 +256,7 @@ install_bluecherry() { "debian" | "ubuntu") install_debian_packages ;; - "centos" | "rhel" | "fedora" | "rocky" | "Rocky") + "centos" | "rhel" | "rocky" | "Rocky") install_redhat_packages ;; "sles" | "opensuse" | "suse") @@ -277,6 +278,7 @@ install_bluecherry() { # Function to detect the Linux distribution detect_distribution() { if [ -f "/etc/os-release" ]; then + # shellcheck disable=SC1091 # "Not following: /etc/os-release was not specified as input" . /etc/os-release echo "$ID" else @@ -361,6 +363,7 @@ uptimekuma() { tar -xvf dist.tar.gz } +# shellcheck disable=SC2162 # "read without -r will mangle backslashes." read -p "Do you want to install docker and setup Bluecherry server? [y/n]: " answer # Execute the appropriate function based on the answer @@ -378,6 +381,7 @@ case $answer in ;; esac +# shellcheck disable=SC2162 # "read without -r will mangle backslashes." read -p "Do you want to download and configure the Bluecherry docker images? If this is the first run of the script then select 'y' [y/n]: " clonedocker case $clonedocker in @@ -394,6 +398,7 @@ case $clonedocker in esac +# shellcheck disable=SC2162 # "read without -r will mangle backslashes." read -p "Do you want to configure SMTP settings? [y/n]: " smtp case $smtp in @@ -410,6 +415,7 @@ esac echo -e "\nNote: NFS is typically recommended for external storage. Read the Bluecherry docs for information on adding CIFS (smb) shares\n\n" +# shellcheck disable=SC2162 # "read without -r will mangle backslashes." read -p "Do you want to add a NFS mount? [y/n]: " add_nfs case $add_nfs in From 2f1ae8491f0816cf9e5383d7f2263c305ece0105 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 20:40:38 +0000 Subject: [PATCH 6/7] scripts/install.sh: mark as executable --- scripts/install.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/install.sh diff --git a/scripts/install.sh b/scripts/install.sh old mode 100644 new mode 100755 From 45912c724519a6efeb17f36ab1ef0eb8d5f6a808 Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 23 Nov 2023 22:47:14 +0000 Subject: [PATCH 7/7] Add Expect script to drive the interactive scripts/install.sh --- tests/install.expect | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 tests/install.expect diff --git a/tests/install.expect b/tests/install.expect new file mode 100755 index 00000000..df267061 --- /dev/null +++ b/tests/install.expect @@ -0,0 +1,27 @@ +#!/usr/bin/expect -f +#exp_internal 1 +set timeout 60 +spawn bluecherry-docker/scripts/install.sh +expect -ex {Do you want to install docker and setup Bluecherry server? [y/n]: } +send -- "y\r" + +expect -ex {Do you want to download and configure the Bluecherry docker images? If this is the first run of the script then select 'y' [y/n]: } +send -- "y\r" +expect -ex {Time Zone (i.e. - America/Chicago): } +send -- "Etc/UTC\r" +expect -ex {Please provide a mysql admin password:} +send -- "mysql-admin-password\r" +expect -ex {Please provide a mysql bluecherry password:} +send -- "mysql-bluecherry-password\r" + +expect -ex {Sleeping 45 seconds to make sure the database is initialized correctly...} +set timeout 60 +expect -ex {Sleeping another 15 seconds to run the database creation scripts...} + +expect -ex {Do you want to configure SMTP settings? [y/n]: } +send -- "n\r" + +expect -ex {Do you want to add a NFS mount? [y/n]: } +send -- "n\r" + +expect eof