diff --git a/install-mattermost.sh b/install-mattermost.sh index c90bdd5..464b89b 100755 --- a/install-mattermost.sh +++ b/install-mattermost.sh @@ -9,7 +9,8 @@ conf_file="${working_dir}/conf/mattermost.conf" LOCK_DIR="/tmp/$(basename $0).$$.LOCK" log_file="${LOCK_DIR}/${script_name%%.*}.log" -backup_date="$(date +%Y-%m-%d-%H%M)" +backup_date="$(date +%Y-%m-%d-%H%M%S)" + # ---------- @@ -121,14 +122,14 @@ blank_line() { detect_os () { - if $(which lsb_release > /dev/null 2>&1) ; then + if command -v lsb_release > /dev/null 2>&1 ; then DIST="$(lsb_release -i | awk '{print tolower($3)}')" DIST_VERSION="$(lsb_release -r | awk '{print tolower($2)}')" DIST_CODENAME="$(lsb_release -c | awk '{print tolower($2)}')" if [[ "$DIST" = "debian" ]]; then - if $(echo "$DIST_VERSION" | grep -q '\.') ; then + if echo "$DIST_VERSION" | grep -q '\.' ; then DIST_VERSION=$(echo "$DIST_VERSION" | cut --delimiter='.' -f1) fi fi @@ -209,7 +210,8 @@ DEFAULT_DB_TYPE="pgsql" # generate random password regexp_digit="([23456789].*){2}" -regexp_special_char="([-_%+].*){2}" +regexp_special_char="([-_%].*){2}" + regexp_not_alowed="([0ODl18B])" LENGTH=16 @@ -259,8 +261,8 @@ if [[ -n "$DB_TYPE" ]] ; then fi [[ -n "$DB_NAME" ]] && DEFAULT_DB_NAME="$DB_NAME" -[[ -n "$DB_USER" ]] && DEFAULT_DB_NAME="$DB_USER" -[[ -n "$DB_PASS" ]] && DEFAULT_DB_PASS="$DB_PASS" +[[ -n "$DB_USER" ]] && DEFAULT_DB_USER="$DB_USER" +[[ -n "$DB_PASS" ]] && DEFAULT_DB_PASS="$DB_PASS" [[ -n "$MATTERMOST_USER" ]] && DEFAULT_MATTERMOST_USER="$MATTERMOST_USER" if [[ -n "$MATTERMOST_GROUP" ]]; then @@ -444,23 +446,35 @@ echo -e "\033[32m--\033[m" echo "" echo "Enter Database Name used by Mattermost Service" echo "" -if [[ -n "$DEFAULT_DB_NAME" ]]; then - while [[ "X${DB_NAME}" = "X" ]]; do +while true ; do + + if [[ -n "$DEFAULT_DB_NAME" ]]; then echononl "Database Name [${DEFAULT_DB_NAME}]: " - read DB_NAME - if [[ "X${DB_NAME}" = "X" ]]; then - DB_NAME=$DEFAULT_DB_NAME - fi - done -else - while [[ "X${DB_NAME}" = "X" ]]; do + else echononl "Database Name: " - read DB_NAME - if [[ "X${DB_NAME}" = "X" ]]; then - echo -e "\n\t\033[33m\033[1m Database Name is reqired\033[m\n" - fi - done -fi + fi + + read DB_NAME + + if [[ -z "$DB_NAME" ]] && [[ -n "$DEFAULT_DB_NAME" ]]; then + DB_NAME="$DEFAULT_DB_NAME" + fi + + if [[ -z "$DB_NAME" ]]; then + echo -e "\n\t\033[33m\033[1mDatabase Name is required.\033[m\n" + continue + fi + + if [[ ! "$DB_NAME" =~ ^[a-zA-Z0-9_]+$ ]] ; then + echo -e "\n\t\033[33m\033[1mDatabase Name contains unsupported characters." + echo -e "\tAllowed characters are: a-z A-Z 0-9 _" + echo -e "\tPlease enter the database name again.\033[m\n" + continue + fi + + break + +done DB_USER= echo "" @@ -468,23 +482,35 @@ echo -e "\033[32m--\033[m" echo "" echo "Enter Database User used by Mattermost Service" echo "" -if [[ -n "$DEFAULT_DB_USER" ]]; then - while [[ "X${DB_USER}" = "X" ]]; do +while true ; do + + if [[ -n "$DEFAULT_DB_USER" ]]; then echononl "Database User [${DEFAULT_DB_USER}]: " - read DB_USER - if [[ "X${DB_USER}" = "X" ]]; then - DB_USER=$DEFAULT_DB_USER - fi - done -else - while [[ "X${DB_USER}" = "X" ]]; do + else echononl "Database User: " - read DB_USER - if [[ "X${DB_USER}" = "X" ]]; then - echo -e "\n\t\033[33m\033[1m Database User is reqired\033[m\n" - fi - done -fi + fi + + read DB_USER + + if [[ -z "$DB_USER" ]] && [[ -n "$DEFAULT_DB_USER" ]]; then + DB_USER="$DEFAULT_DB_USER" + fi + + if [[ -z "$DB_USER" ]]; then + echo -e "\n\t\033[33m\033[1mDatabase User is required.\033[m\n" + continue + fi + + if [[ ! "$DB_USER" =~ ^[a-zA-Z0-9_]+$ ]] ; then + echo -e "\n\t\033[33m\033[1mDatabase User contains unsupported characters." + echo -e "\tAllowed characters are: a-z A-Z 0-9 _" + echo -e "\tPlease enter the database user again.\033[m\n" + continue + fi + + break + +done DB_PASS= echo "" @@ -492,27 +518,41 @@ echo -e "\033[32m--\033[m" echo "" echo "Enter Database Password used by Mattermost Service" echo "" -if [[ -n "$DEFAULT_DB_PASS" ]]; then - while [[ "X${DB_PASS}" = "X" ]]; do - echononl "Database Password [${DEFAULT_DB_PASS}]: " - read DB_PASS - if [[ "X${DB_PASS}" = "X" ]]; then - DB_PASS=$DEFAULT_DB_PASS - fi - done -else - while [[ "X${DB_PASS}" = "X" ]]; do +while true ; do + + if [[ -n "$DEFAULT_DB_PASS" ]]; then + echononl "Database Password [********]: " + else echononl "Database Password: " - read DB_PASS - if [[ "X${DB_PASS}" = "X" ]]; then - echo -e "\n\t\033[33m\033[1m Database Password is reqired\033[m\n" - fi - done -fi + fi + + read -s DB_PASS + echo + + if [[ -z "$DB_PASS" ]] && [[ -n "$DEFAULT_DB_PASS" ]]; then + DB_PASS="$DEFAULT_DB_PASS" + fi + + if [[ -z "$DB_PASS" ]]; then + echo -e "\n\t\033[33m\033[1mDatabase Password is required.\033[m\n" + continue + fi + + if [[ ! "$DB_PASS" =~ ^[a-zA-Z1-9_%-]+$ ]] ; then + echo -e "\n\t\033[33m\033[1mDatabase Password contains unsupported characters." + echo -e "\tAllowed characters are: a-z A-Z 1-9 - _ %" + echo -e "\tPlease enter the password again.\033[m\n" + continue + fi + + break + +done + if [[ "$DB_TYPE" = "mysql" ]] ; then if [[ -n "$MYSQL_CREDENTIAL_ARGS" ]] ; then - if ! $(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e 'quit' > /dev/null 2>&1) ; then + if ! mysql $MYSQL_CREDENTIAL_ARGS -N -s -e 'quit' > /dev/null 2>&1 ; then fatal "Parameter MYSQL_CREDENTIAL_ARGS is given, but a connection to MySQL Service failed.!" fi USE_MYSQL_CREDENTIAL_ARGS=true @@ -533,8 +573,8 @@ if [[ "$DB_TYPE" = "mysql" ]] ; then echo -e "\n\t\033[33m\033[1mPassworteingabe erforderlich!\033[m\n" continue fi - if $(pgrep mysqld_safe > /dev/null 2>&1) || $(pgrep mysqld > /dev/null 2>&1); then - if $(mysql --user="root" --password="$_MYSQL_ROOT_PW" -N -s -e 'quit' > /dev/null 2>&1) ; then + if pgrep mysqld_safe > /dev/null 2>&1 || pgrep mysqld > /dev/null 2>&1 ; then + if mysql --user="root" --password="$_MYSQL_ROOT_PW" -N -s -e 'quit' > /dev/null 2>&1 ; then MYSQL_ROOT_PW=$_MYSQL_ROOT_PW else echo -e "\n\t\033[33m\033[1mFalsches Passwort\033[m\n" @@ -570,7 +610,7 @@ fi echo "" if [[ "${DB_TYPE}" = "mysql" ]]; then if $USE_MYSQL_CREDENTIAL_ARGS ; then - echo -e "\tMYSQL_CREDENTIAL_ARGS....: $MYSQL_CREDENTIAL_ARGS" + echo -e "\tMYSQL_CREDENTIAL_ARGS....: **" else echo -e "\tRoot password MySQL......: **" fi @@ -578,7 +618,7 @@ if [[ "${DB_TYPE}" = "mysql" ]]; then fi echo -e "\tDatabase Name............: $DB_NAME" echo -e "\tDatabase User............: $DB_USER" -echo -e "\tDatabase Password........: $DB_PASS" +echo -e "\tDatabase Password........: **" echo "" echononl "einverstanden (yes/no): " read OK @@ -595,8 +635,8 @@ echo "" if ! $USE_MYSQL_CREDENTIAL_ARGS ; then - MYSQL_CREDENTIAL_ARGS="--user='root' --password=$_MYSQL_ROOT_PW" - if ! $(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e 'quit' > /dev/null 2>&1) ; then + MYSQL_CREDENTIAL_ARGS="--user=root --password=$_MYSQL_ROOT_PW" + if ! mysql $MYSQL_CREDENTIAL_ARGS -N -s -e 'quit' > /dev/null 2>&1 ; then fatal "Parameter MYSQL_CREDENTIAL_ARGS is given, but a connection to MySQL Service failed.!" fi fi @@ -609,9 +649,9 @@ echo _failed=false echononl "Check if Nginx Webservice is installed.." -if $(dpkg -s nginx-extras > "$log_file" 2>&1) ; then +if dpkg -s nginx-extras > "$log_file" 2>&1 ; then nginx_installed=true -elif $(dpkg -s nginx-full > "$log_file" 2>&1) ; then +elif dpkg -s nginx-full > "$log_file" 2>&1 ; then nginx_installed=true else nginx_installed=false @@ -625,7 +665,7 @@ else echononl "\033[1mcontinue anyway\033[m [yes/no]: " read OK while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " + echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" @@ -634,7 +674,7 @@ fi _failed=false if [[ "${DB_TYPE}" = "mysql" ]]; then echononl "Check if MySQL Database Service is installed.." - if $(dpkg -s mysql-server > "$log_file" 2>&1) ; then + if dpkg -s mysql-server > "$log_file" 2>&1 ; then database_service_installed=true else database_service_installed=false @@ -648,14 +688,14 @@ if [[ "${DB_TYPE}" = "mysql" ]]; then echononl "\033[1mcontinue anyway\033[m [yes/no]: " read OK while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " + echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" fi else echononl "Check if PostgreSQL Database Service is installed.." - if $(dpkg -s postgresql > "$log_file" 2>&1) ; then + if dpkg -s postgresql > "$log_file" 2>&1 ; then database_service_installed=true else database_service_installed=false @@ -669,7 +709,7 @@ else echononl "\033[1mcontinue anyway\033[m [yes/no]: " read OK while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " + echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" @@ -718,7 +758,7 @@ elif ! $cert_present ; then read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " + echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" @@ -731,7 +771,7 @@ echo -e "\033[37m\033[1mSome pre-installation stuff..\033[m" echo echononl "Stop Mattermost Service.." -if $(systemctl is-active --quiet service mattermost.service) ; then +if systemctl is-active --quiet mattermost.service ; then systemctl stop mattermost.service > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -747,19 +787,26 @@ blank_line if [[ "${DB_TYPE}" = "mysql" ]] ; then - echononl "Create MySQL Database User '${DB_USER}' with Password '${DB_PASS}'.." - if [[ "$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '$DB_USER')" 2>/dev/null)" = 1 ]]; then - echo_skipped + if [[ "$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '$DB_USER' AND host = 'localhost')" 2>/dev/null)" = 1 ]]; then + + echononl "Update password for MySQL Database User '${DB_USER}'@'localhost'.." + mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + "ALTER USER '$DB_USER'@'localhost' IDENTIFIED BY '${DB_PASS}'" > "$log_file" 2>&1 + else - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + + echononl "Create MySQL Database User '${DB_USER}'@'localhost'.." + mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '${DB_PASS}'" > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi + + fi + + if [[ $? -ne 0 ]]; then + echo_failed + error "$(cat "$log_file")" + else + echo_ok fi echononl "Create MySQL Database '${DB_NAME}'.." @@ -787,37 +834,37 @@ if [[ "${DB_TYPE}" = "mysql" ]] ; then echo_ok fi - echononl "FLUSH PRIVILEGES to dadabase engine .." - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - "FLUSH PRIVILEGES" > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi else # Check if PostgreSQL database '$DB_NAME' exists .. # - count=$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$DB_NAME") + count=$(runuser -u postgres -- psql -q -A -t -d postgres -c "SELECT COUNT(*) FROM pg_database WHERE datname = '${DB_NAME}';") if [[ $count -eq 0 ]];then database_exists=false else database_exists=true fi -# sudo -u postgres psql -c "CREATE DATABASE ${DB_NAME};" > $log_file 2>&1 -# sudo -u postgres psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" > $log_file 2>&1 -# sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER};" > $log_file 2>&1 -# sudo -u postgres psql -c "ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};" > $log_file 2>&1 -# sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${DB_USER};" > $log_file 2>&1 + # Check if PostgreSQL database user '$DB_USER' exists .. + # + count=$(runuser -u postgres -- psql -q -A -t -d postgres -c "SELECT COUNT(*) FROM pg_roles WHERE rolname = '${DB_USER}';") + if [[ $count -eq 0 ]]; then + database_user_exists=false + else + database_user_exists=true + fi + +# runuser -u postgres -- psql -c "CREATE DATABASE ${DB_NAME};" > $log_file 2>&1 +# runuser -u postgres -- psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" > $log_file 2>&1 +# runuser -u postgres -- psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER};" > $log_file 2>&1 +# runuser -u postgres -- psql -c "ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};" > $log_file 2>&1 +# runuser -u postgres -- psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${DB_USER};" > $log_file 2>&1 echononl "Create PostgreSQL database '${DB_NAME}'.." if $database_exists ; then echo_skipped else - sudo -u postgres psql -c "CREATE DATABASE ${DB_NAME};" > $log_file 2>&1 + runuser -u postgres -- psql -c "CREATE DATABASE ${DB_NAME};" > $log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -827,7 +874,7 @@ else echononl "\033[1mcontinue anyway\033[m [yes/no]: " read OK while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " + echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" @@ -838,104 +885,89 @@ else fi - echononl "Create PostgreSQL database user ${DB_USER}.." - if $database_exists ; then - echo_skipped + if $database_user_exists ; then + echononl "Update password for PostgreSQL database user ${DB_USER}.." + runuser -u postgres -- psql -c "ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" > "$log_file" 2>&1 else + echononl "Create PostgreSQL database user ${DB_USER}.." + runuser -u postgres -- psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" > "$log_file" 2>&1 + fi - sudo -u postgres psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" > $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + error "$(cat "$log_file")" - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat "$log_file")" - - echo "" - echononl "\033[1mcontinue anyway\033[m [yes/no]: " + echo "" + echononl "\033[1mcontinue anyway\033[m [yes/no]: " + read OK + while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " read OK - while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " - read OK - done - [[ $OK = "yes" ]] || fatal "Abbruch durch User" + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" - else - echo_ok - fi + else + echo_ok fi echononl "Grant the user access to the Mattermost database.." - if $database_exists ; then - echo_skipped - else + runuser -u postgres -- psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};" > "$log_file" 2>&1 - sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER};" > $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + error "$(cat "$log_file")" - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat "$log_file")" - - echo "" - echononl "\033[1mcontinue anyway\033[m [yes/no]: " + echo "" + echononl "\033[1mcontinue anyway\033[m [yes/no]: " + read OK + while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " read OK - while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " - read OK - done - [[ $OK = "yes" ]] || fatal "Abbruch durch User" + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" - else - echo_ok - fi + else + echo_ok fi echononl "Change the owner of database '${DB_NAME}' to '${DB_USER}'.." - if $database_exists ; then - echo_skipped - else + runuser -u postgres -- psql -c "ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};" > "$log_file" 2>&1 - sudo -u postgres psql -c "ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};" > $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + error "$(cat "$log_file")" - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat "$log_file")" - - echo "" - echononl "\033[1mcontinue anyway\033[m [yes/no]: " + echo "" + echononl "\033[1mcontinue anyway\033[m [yes/no]: " + read OK + while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " read OK - while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " - read OK - done - [[ $OK = "yes" ]] || fatal "Abbruch durch User" + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" - else - echo_ok - fi + else + echo_ok fi echononl "Grant access to objects contained in the specified schema.." - if $database_exists ; then - echo_skipped - else + runuser -u postgres -- psql -d "${DB_NAME}" -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${DB_USER};" > "$log_file" 2>&1 - sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${DB_USER};" > $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + error "$(cat "$log_file")" - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat "$log_file")" - - echo "" - echononl "\033[1mcontinue anyway\033[m [yes/no]: " + echo "" + echononl "\033[1mcontinue anyway\033[m [yes/no]: " + read OK + while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " read OK - while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/nno]: " - read OK - done - [[ $OK = "yes" ]] || fatal "Abbruch durch User" + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" - else - echo_ok - fi + else + echo_ok fi fi @@ -976,7 +1008,8 @@ if [[ ! -f "${working_dir}/${DOWNLOAD_ARCHIVE}" ]]; then wget -O "${working_dir}/${DOWNLOAD_ARCHIVE}" "${DOWNLOAD_URL}" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed - error "$(cat "$log_file")" + rm -f "${working_dir}/${DOWNLOAD_ARCHIVE}" + fatal "$(cat "$log_file")" else echo_ok fi @@ -984,14 +1017,32 @@ else echo_skipped fi +echononl "Check Mattermost Server archive.." +if tar -tzf "${working_dir}/${DOWNLOAD_ARCHIVE}" > /dev/null 2> "$log_file" ; then + echo_ok +else + echo_failed + rm -f "${working_dir}/${DOWNLOAD_ARCHIVE}" + fatal "Mattermost Server archive is invalid or incomplete. Please run the installation again." +fi + echononl "Backup Mattermost Installation directory.." if [[ -d "/opt/mattermost" ]]; then cp -a "/opt/mattermost" "/opt/mattermost.${backup_date}" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed - error "$(cat "$log_file")" + fatal "$(cat "$log_file")" else echo_ok + + echononl "Remove existing Mattermost Installation directory.." + rm -rf "/opt/mattermost" > "$log_file" 2>&1 + if [[ $? -ne 0 ]]; then + echo_failed + fatal "$(cat "$log_file")" + else + echo_ok + fi fi else echo_skipped @@ -1001,12 +1052,29 @@ echononl "Extract the Mattermost Server files.." tar -C /opt -xvzf "${working_dir}/${DOWNLOAD_ARCHIVE}" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed - error "$(cat "$log_file")" + fatal "$(cat "$log_file")" else echo_ok fi -echononl "Set ownbership of installation directors '/opt/mattermost'.." +echononl "Verify Mattermost Edition.." +if [[ "$MATTERMOST_EDITION" == "enterprise" ]]; then + if /opt/mattermost/bin/mattermost version 2>&1 | grep -q "Build Enterprise Ready: true"; then + echo_ok + else + echo_failed + fatal "Downloaded Mattermost binary is not Enterprise Ready." + fi +else + if /opt/mattermost/bin/mattermost version 2>&1 | grep -q "Build Enterprise Ready: false"; then + echo_ok + else + echo_failed + fatal "Downloaded Mattermost binary is not Team Edition." + fi +fi + +echononl "Set ownership of installation directory '/opt/mattermost'.." chown -R ${MATTERMOST_USER}:${MATTERMOST_GROUP} /opt/mattermost > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1016,7 +1084,7 @@ else fi echononl "Give write permissions to the mattermost group.." -chmod -R g+w /opt/mattermost> "$log_file" 2>&1 +chmod -R g+w /opt/mattermost > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed error "$(cat "$log_file")" @@ -1044,7 +1112,9 @@ echo echononl "Set up 'SqlSettings'.." if [[ "${DB_TYPE}" = "mysql" ]] ; then - if ! $(grep -q -E "^\s*\"DriverName\":\s+mysql" /opt/mattermost/config/config.json 2> "$log_file") ; then + if ! grep -q -E "^\s*\"DriverName\":\s+\"mysql\"" /opt/mattermost/config/config.json 2> "$log_file" \ + || ! grep -Fq "\"DataSource\": \"${DB_USER}:${DB_PASS}@tcp(localhost:3306)/${DB_NAME}?charset=utf8mb4,utf8\\u0026readTimeout=30s\\u0026writeTimeout=30s\"," \ + /opt/mattermost/config/config.json 2> "$log_file" ; then _found=false :> ${LOCK_DIR}/config.json @@ -1088,7 +1158,10 @@ EOF echo_skipped fi else - if ! $(grep -q -E "^\s*\"DriverName\":\s+postgres" /opt/mattermost/config/config.json 2> "$log_file") ; then + if ! grep -q -E "^\s*\"DriverName\":\s+\"postgres\"" /opt/mattermost/config/config.json 2> "$log_file" \ + || ! grep -Fq "\"DataSource\": \"postgres://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}?sslmode=disable\\u0026connect_timeout=10\"," \ + /opt/mattermost/config/config.json 2> "$log_file" ; then + _found=false :> ${LOCK_DIR}/config.json @@ -1136,7 +1209,9 @@ fi echononl "Set up 'ServiceSettings'.." -if ! $(grep -q -E "^\s*\"SiteURL\":\s+\"https://${FQHN_HOSTNAME}\"" /opt/mattermost/config/config.json 2> "$log_file") ; then +if ! grep -q -E "^\s*\"SiteURL\":\s+\"https://${FQHN_HOSTNAME}\"" /opt/mattermost/config/config.json 2> "$log_file" \ + || ! grep -q -E "^\s*\"ListenAddress\":\s+\"127\.0\.0\.1:8065\"" /opt/mattermost/config/config.json 2> "$log_file" ; then + _found=false :> ${LOCK_DIR}/config.json @@ -1180,7 +1255,7 @@ else echo_skipped fi -echononl "Reset ownbership of '/opt/mattermost/config/config.json'.." +echononl "Reset ownership of '/opt/mattermost/config/config.json'.." chown ${MATTERMOST_USER}:${MATTERMOST_GROUP} /opt/mattermost/config/config.json > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1196,13 +1271,10 @@ echo -e "\033[37m\033[1mSetup Mattermost to use systemd for starting and stoppin echo echononl "Create a systemd unit file.." -if [[ "${DB_TYPE}" = "mysql" ]] ; then - cat < /etc/systemd/system//mattermost.service 2>"$log_file" +cat < /etc/systemd/system/mattermost.service 2>"$log_file" [Unit] Description=Mattermost After=network.target -After=mysql.service -Requires=mysql.service [Service] Type=notify @@ -1219,40 +1291,12 @@ LimitNOFILE=524288 [Install] WantedBy=multi-user.target EOF - if [[ -s "$log_file" ]] ; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi + +if [[ -s "$log_file" ]] ; then + echo_failed + error "$(cat "$log_file")" else - cat < /etc/systemd/system//mattermost.service 2>"$log_file" -[Unit] -Description=Mattermost -After=network.target - -[Service] -Type=notify -ExecStart=/opt/mattermost/bin/mattermost -TimeoutStartSec=3600 -KillMode=mixed -Restart=always -RestartSec=10 -WorkingDirectory=/opt/mattermost -User=mattermost -Group=mattermost -LimitNOFILE=49152 - -[Install] -WantedBy=multi-user.target -EOF - - if [[ -s "$log_file" ]] ; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi + echo_ok fi @@ -1351,11 +1395,8 @@ server { # Enable TLS versions (TLSv1.3 is required upcoming HTTP/3 QUIC). ssl_protocols TLSv1.2 TLSv1.3; - # Enable TLSv1.3's 0-RTT. Use \$ssl_early_data when reverse proxying to - # prevent replay attacks. - # - # @see: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data - ssl_early_data on; + # TLSv1.3 0-RTT is intentionally disabled to avoid replay risks. + ssl_early_data off; # ECDHE better than DHE (faster) ECDHE & DHE GCM better than CBC (attacks on AES) # Everything better than SHA1 (deprecated) @@ -1375,7 +1416,6 @@ server { # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months) # add_header Strict-Transport-Security max-age=15768000; - add_header X-Early-Data \$tls1_3_early_data; add_header X-Frame-Options SAMEORIGIN; # OCSP Stapling deaktiviert: Let's Encrypt hat seinen OCSP-Dienst am @@ -1428,14 +1468,6 @@ server { } } -# This block is useful for debugging TLS v1.3. Please feel free to remove this -# and use the '\$ssl_early_data' variable exposed by NGINX directly should you -# wish to do so. -map \$ssl_early_data \$tls1_3_early_data { - "~." \$ssl_early_data; - default ""; -} - EOF if [[ $? -ne 0 ]]; then echo_failed @@ -1458,13 +1490,22 @@ else echo_skipped fi -echononl "Restart NGINX Service.." -systemctl restart nginx > "$log_file" 2>&1 +echononl "Test NGINX configuration.." +nginx -t > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed error "$(cat "$log_file")" else echo_ok + + echononl "Restart NGINX Service.." + systemctl restart nginx > "$log_file" 2>&1 + if [[ $? -ne 0 ]]; then + echo_failed + error "$(cat "$log_file")" + else + echo_ok + fi fi echo "" @@ -1488,9 +1529,11 @@ fi _key="FQHN_HOSTNAME" _val="$FQHN_HOSTNAME" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then + echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then + perl -i -n -p -e "s/^\s*$_key=.*/${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1498,7 +1541,8 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then + perl -i -n -p -e "s/^(\s*\#\s*$_key=.*)/\1\n${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1523,9 +1567,9 @@ fi _key="MATTERMOST_USER" _val="$MATTERMOST_USER" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^\s*$_key=.*/${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1533,7 +1577,7 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^(\s*\#\s*$_key=.*)/\1\n${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1558,9 +1602,10 @@ fi _key="MATTERMOST_GROUP" _val="$MATTERMOST_GROUP" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then + perl -i -n -p -e "s/^\s*$_key=.*/${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1568,7 +1613,8 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then + perl -i -n -p -e "s/^(\s*\#\s*$_key=.*)/\1\n${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1593,9 +1639,9 @@ fi _key="DB_TYPE" _val="$DB_TYPE" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^\s*$_key=.*/${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1603,7 +1649,7 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^(\s*\#\s*$_key=.*)/\1\n${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1628,9 +1674,9 @@ fi _key="DB_NAME" _val="$DB_NAME" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^\s*$_key=.*/${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1638,7 +1684,7 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^(\s*\#\s*$_key=.*)/\1\n${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1663,9 +1709,9 @@ fi _key="DB_USER" _val="$DB_USER" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^\s*$_key=.*/${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1673,7 +1719,7 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s/^(\s*\#\s*$_key=.*)/\1\n${_key}=\"${_val}\"/" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1698,9 +1744,9 @@ fi _key="DB_PASS" _val="$DB_PASS" echononl "Update Parameter '$_key'.." -if $(grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null) ; then +if grep -q -E "^\s*$_key=\"?$_val\"?\s*$" "$conf_file" 2> /dev/null ; then echo_skipped -elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s§^\s*$_key=.*§${_key}=\"${_val}\"§" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1708,7 +1754,7 @@ elif $(grep -q -E "^\s*$_key=" "$conf_file" 2> /dev/null) ; then else echo_ok fi -elif $(grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null) ; then +elif grep -q -E "^\s*#\s*${_key}" "$conf_file" 2> /dev/null ; then perl -i -n -p -e "s&^(\s*\#\s*$_key=.*)&\1\n${_key}=\"${_val}\"&" "$conf_file" > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -1730,288 +1776,14 @@ EOF fi - - - -clean_up 0 - - -echo -echo -e "\033[37m\033[1mUpdate file '/etc/systemd/system.conf'....\033[m" -echo - -echononl "Set Parameter 'DefaultLimitNOFILE'.." -if ! $(grep -q -E "^\s*DefaultLimitNOFILE=" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^(\s*#DefaultLimitNOFILE=.*)/\1\nDefaultLimitNOFILE=1048576/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -elif ! $(grep -q -E "^\s*DefaultLimitNOFILE=1048576" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^\s*DefaultLimitNOFILE=.*/DefaultLimitNOFILE=1048576/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -echononl "Set Parameter 'DefaultLimitNPROC'.." -if ! $(grep -q -E "^\s*DefaultLimitNPROC=" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^(\s*#DefaultLimitNPROC=.*)/\1\nDefaultLimitNPROC=1048576/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -elif ! $(grep -q -E "^\s*DefaultLimitNPROC=1048576" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^\s*DefaultLimitNPROC=.*/DefaultLimitNPROC=1048576/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -echononl "Set Parameter 'DefaultTasksMax'.." -if ! $(grep -q -E "^\s*DefaultTasksMax=" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^(\s*#DefaultTasksMax=.*)/\1\nDefaultTasksMax=1048576/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -elif ! $(grep -q -E "^\s*DefaultTasksMax=1048576" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^\s*DefaultTasksMax=.*/DefaultTasksMax=1048576/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -echononl "Set Parameter 'DefaultLimitRTPRIO'.." -if ! $(grep -q -E "^\s*DefaultLimitRTPRIO=" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^(\s*#DefaultLimitRTPRIO=.*)/\1\nDefaultLimitRTPRIO=infinity/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -elif ! $(grep -q -E "^\s*DefaultLimitRTPRIO=infinity" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^\s*DefaultLimitRTPRIO=.*/DefaultLimitRTPRIO=infinity/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -echononl "Set Parameter 'DefaultLimitRTTIME'.." -if ! $(grep -q -E "^\s*DefaultLimitRTTIME=" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^(\s*#DefaultLimitRTTIME=.*)/\1\nDefaultLimitRTTIME=infinity/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -elif ! $(grep -q -E "^\s*DefaultLimitRTTIME=infinity" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^\s*DefaultLimitRTTIME=.*/DefaultLimitRTTIME=infinity/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -_failed=false -echononl "Set Parameter 'DefaultLimitCORE'.." -if ! $(grep -q -E "^\s*DefaultLimitCORE=" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^(\s*#DefaultLimitCORE=.*)/\1\nDefaultLimitCORE=infinity/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -elif ! $(grep -q -E "^\s*DefaultLimitCORE=infinity" /etc/systemd/system.conf 2> /dev/null); then - perl -i -n -p -e "s/^\s*DefaultLimitCORE=.*/DefaultLimitCORE=infinity/" \ - /etc/systemd/system.conf > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - - -echononl "Reload Systemd .." -systemctl daemon-reload > "$log_file" 2>&1 -if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" -else - echo_ok -fi - - -echo -echo -e "\033[37m\033[1mSome Certifikation/Key stuff..\033[m" -echo - -cert_copied=false -echononl "Copy Snakeoil Cert to file '/etc/ssl/fullchain.pem'.." -if [[ ! -f "/etc/ssl/fullchain.pem" ]] && [[ ! -h "/etc/ssl/fullchain.pem" ]]; then - cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/fullchain.pem > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - cert_copied=true - fi -else - echo_skipped -fi - -perm_cert="644" -echononl "Set Permission $perm_cert on file '/etc/ssl/fullchain.pem'.." -if $cert_copied ; then - chmod 644 /etc/ssl/fullchain.pem > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -if [[ ! -h "/etc/ssl/${FQHN_HOSTNAME}.crt" ]]; then - if [[ -f "/etc/ssl/${FQHN_HOSTNAME}.crt" ]] ; then - echononl "Remove file '/etc/ssl/${FQHN_HOSTNAME}.crt'.." - rm "/etc/ssl/${FQHN_HOSTNAME}.crt" > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi - fi - echononl "Set Symlink '/etc/ssl/${FQHN_HOSTNAME}.crt --> fullchain.pem'.." - ln -s fullchain.pem /etc/ssl/${FQHN_HOSTNAME}.crt > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echononl "Set Symlink '/etc/ssl/${FQHN_HOSTNAME}.crt --> fullchain.pem'.." - echo_skipped -fi - -blank_line - -key_copied=false -echononl "Copy Snakeoil Key to file '/etc/ssl/privkey.pem'.." -if [[ ! -f "/etc/ssl/privkey.pem" ]] && [[ ! -h "/etc/ssl/privkey.pem" ]]; then - cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/privkey.pem > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - key_copied=true - fi -else - echo_skipped -fi - -perm_key="644" -echononl "Set Permission $perm_key on file '/etc/ssl/privkey.pem'.." -if $key_copied ; then - chmod 644 /etc/ssl/privkey.pem > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echo_skipped -fi - -if [[ ! -h "/etc/ssl/${FQHN_HOSTNAME}.key" ]]; then - if [[ -f "/etc/ssl/${FQHN_HOSTNAME}.key" ]] ; then - echononl "Remove file '/etc/ssl/${FQHN_HOSTNAME}.key'.." - rm "/etc/ssl/${FQHN_HOSTNAME}.key" > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi - fi - echononl "Set Symlink '/etc/ssl/${FQHN_HOSTNAME}.key --> privkey.pem'.." - ln -s fullchain.pem /etc/ssl/${FQHN_HOSTNAME}.key > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -else - echononl "Set Symlink '/etc/ssl/${FQHN_HOSTNAME}.key --> privkey.pem'.." - echo_skipped -fi - - - echo echo -e "\033[37m\033[1mSome naming stuff..\033[m" echo -echononl "Change /etc/hostname - set entry to '$FQHN_HOSTNAME'.." -if [[ "$(head -1 /etc/hostname)" != "$FQHN_HOSTNAME" ]]; then +echononl "Change /etc/hostname - set entry to '$HOSTNAME'.." +if [[ "$(head -1 /etc/hostname)" != "$HOSTNAME" ]]; then cat < /etc/hostname -$FQHN_HOSTNAME +$HOSTNAME EOF if [[ $? -ne 0 ]]; then echo_failed @@ -2027,8 +1799,9 @@ blank_line echo -e " Take care '/etc/hosts' contains line '127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME'.." echononl " \033[1m127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME\033[m .." -if ! $(grep -q -E "^\s*127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME" /etc/hosts 2> "$log_file") ; then - if $(grep -q -E "^\s*127.0.1.1" /etc/hosts 2> "$log_file") ; then +if ! grep -q -E "^\s*127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME" /etc/hosts 2> "$log_file" ; then + if grep -q -E "^\s*127.0.1.1" /etc/hosts 2> "$log_file" ; then + perl -i -n -p -e "s/(^\s*127.0.1.1.*)/#\1\n127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME/" \ /etc/hosts > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then @@ -2037,7 +1810,7 @@ if ! $(grep -q -E "^\s*127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME" /etc/hosts 2> "$log else echo_ok fi - elif $(grep -q -E "^\s*127.0.0.1" /etc/hosts 2> "$log_file") ; then + elif grep -q -E "^\s*127.0.0.1" /etc/hosts 2> "$log_file" ; then perl -i -n -p -e "s/(^\s*127.0.0.1.*)/\1\n127.0.1.1 ${FQHN_HOSTNAME} $HOSTNAME/" \ /etc/hosts > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then @@ -2064,53 +1837,10 @@ fi echo -echo -e "\033[37m\033[1mRepository stuff..\033[m" +echo -e "\033[37m\033[1mInstall optional Mattermost dependencies..\033[m" echo - -echononl "Add the '$JITSI_REPOSITORY_VERSION' Jitsi package repository.." -echo "deb https://download.jitsi.org ${JITSI_REPOSITORY_VERSION}/" > /etc/apt/sources.list.d/jitsi-${JITSI_REPOSITORY_VERSION}.list -if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" -else - echo_ok -fi - -if [[ "$JITSI_REPOSITORY_VERSION" = "stable" ]]; then - if [[ -f "/etc/apt/sources.list.d/jitsi-unstable.list" ]]; then - echononl "Remove Repository List for 'unstable' jitsi packages.." - rm "/etc/apt/sources.list.d/jitsi-unstable.list" > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi - fi -else - if [[ -f "/etc/apt/sources.list.d/jitsi-stable.list" ]]; then - echononl "Remove Repository List for 'stable' jitsi packages.." - rm "/etc/apt/sources.list.d/jitsi-stable.list" > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi - fi -fi - -echononl "Add the Jitsi Maintainer gpg key.." -wget -qO - https://download.jitsi.org/jitsi-key.gpg.key 2> "$log_file" | sudo apt-key add - > "$log_file" 2>&1 -if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" -else - echo_ok -fi - -echononl "Update Repository.." +echononl "Update package lists.." apt-get update > "$log_file" 2>&1 if [[ $? -ne 0 ]]; then echo_failed @@ -2119,6 +1849,9 @@ else echo_ok fi +blank_line + + # Install ffmpeg. Mattermost Agents uses ffmpeg for audio transcription. # This is independent of the selected Mattermost edition. # @@ -2154,22 +1887,4 @@ else fi -# Ensure support is available for apt repositories served via HTTPS -# -echononl "Install 'apt-transport-https'.." -if $(dpkg -s apt-transport-https > "$log_file" 2>&1) ; then - echo_skipped -else - apt-get install -y apt-transport-https > "$log_file" 2>&1 - if [[ $? -ne 0 ]]; then - echo_failed - error "$(cat "$log_file")" - else - echo_ok - fi -fi - -info "To ensure, your system is fully prepared for installing Jitsi Meet, it is - recommend to \033[1mreboot the system before installing Jitsi Meet\033[m." - clean_up 0