1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00

Merge pull request #160 from YunoHost-Apps/improve-scripts

Improve scripts
This commit is contained in:
Pierre de La Morinerie 2020-02-10 01:51:33 +01:00 committed by GitHub
commit 4a78716279
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 22 deletions

View file

@ -8,7 +8,7 @@ A Yunohost package for [Mattermost](http://www.mattermost.org/), an open-source,
Mattermost requires: Mattermost requires:
* A x86_64 system (check with `uname -m`), * A x86_64 system (check with `uname -m`) (ARM Raspberry Pi wont work, sorry),
* Yunohost 3.2 or higher (check in Yunohost Admin panel), * Yunohost 3.2 or higher (check in Yunohost Admin panel),
* MySQL 5.6 or higher, or MariaDB 10 or higher (check with `mysql --version`). * MySQL 5.6 or higher, or MariaDB 10 or higher (check with `mysql --version`).

View file

@ -3,7 +3,7 @@
domain="ynhtests.local" (DOMAIN) domain="ynhtests.local" (DOMAIN)
path="/path" (PATH) path="/path" (PATH)
admin_email="john@gmail.com" admin_email="john@gmail.com"
admin_password="MattermostPassword!42" admin_password="admin!42"
admin_locale="fr" admin_locale="fr"
team_display_name="Mon équipe" team_display_name="Mon équipe"
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)

View file

@ -64,8 +64,8 @@
"name": "admin_password", "name": "admin_password",
"type": "password", "type": "password",
"ask": { "ask": {
"en": "Password for the chat admin. Must contain at least 10 characters, one lowercase letter, one uppercase letter, one number, and one symbol (e.g. '~!@#$%^&*()').", "en": "Password for the chat admin. At least 8 characters.",
"fr": "Mot de passe pour ladministrateur du chat. Doit contenir au moins 10 caractères, une majuscule, une minuscule, un chiffre, et une ponctuation (ex. '~!@#$%^&*()')." "fr": "Mot de passe pour ladministrateur du chat. Minimum 8 caractères."
}, },
"optional": false "optional": false
}, },

View file

@ -97,7 +97,7 @@ logs_path="/var/log/$app"
db_name="$app" db_name="$app"
db_user="mmuser" db_user="mmuser"
db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') db_password=$(ynh_string_random --length=24)
ynh_mysql_create_db "$db_name" "$db_user" "$db_password" ynh_mysql_create_db "$db_name" "$db_user" "$db_password"
ynh_app_setting_set "$app" mysqlpwd "$db_password" ynh_app_setting_set "$app" mysqlpwd "$db_password"
@ -106,7 +106,7 @@ ynh_app_setting_set "$app" mysqlpwd "$db_password"
#================================================= #=================================================
mattermost_user="$app" mattermost_user="$app"
mattermost_user_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') mattermost_user_password=$(ynh_string_random --length=24)
useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user" useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user"
ynh_app_setting_set "$app" smtppwd "$mattermost_user_password" ynh_app_setting_set "$app" smtppwd "$mattermost_user_password"
@ -125,28 +125,34 @@ mkdir -p "$logs_path"
#================================================= #=================================================
# Configure Service Settings # Configure Service Settings
sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"SiteURL\": \"\"" --replace_string "\"SiteURL\": \"https://${domain}${path_url}\"" --target_file $final_path/config/config.json
sed -i "s|\"ListenAddress\": \".*\"|\"ListenAddress\": \"127.0.0.1:${port}\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"ListenAddress\": \".*\"" --replace_string "\"ListenAddress\": \"127.0.0.1:${port}\"" --target_file $final_path/config/config.json
# Configure the database connection # Configure the database connection
db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8" db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8"
sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"DataSource\": \".*\"" --replace_string "\"DataSource\": \"${db_connection_url}\"" --target_file $final_path/config/config.json
# Configure uploaded files directory # Configure uploaded files directory
sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"Directory\": \"./data/\"" --replace_string "\"Directory\": \"${data_path}/\"" --target_file $final_path/config/config.json
# Configure SMTP account for sending email notifications # Configure SMTP account for sending email notifications
sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json ynh_replace_string --match_string "\"SendEmailNotifications\": false" --replace_string "\"SendEmailNotifications\": true" --target_file $final_path/config/config.json
sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"FeedbackName\": \"\"" --replace_string "\"FeedbackName\": \"Mattermost notification\"" --target_file $final_path/config/config.json
sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"FeedbackEmail\": \"\"" --replace_string "\"FeedbackEmail\": \"no-reply@${domain}\"" --target_file $final_path/config/config.json
sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${mattermost_user}\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"SMTPUsername\": \"\"" --replace_string "\"SMTPUsername\": \"${mattermost_user}\"" --target_file $final_path/config/config.json
sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${mattermost_user_password}\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"SMTPPassword\": \"\"" --replace_string "\"SMTPPassword\": \"${mattermost_user_password}\"" --target_file $final_path/config/config.json
sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"SMTPServer\": \"\"" --replace_string "\"SMTPServer\": \"localhost\"" --target_file $final_path/config/config.json
sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"SMTPPort\": \"\"" --replace_string "\"SMTPPort\": \"25\"" --target_file $final_path/config/config.json
# Disable Mattermost debug console by default # Disable Mattermost debug console by default
sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json ynh_replace_string --match_string "\"EnableConsole\": true" --replace_string "\"EnableConsole\": false" --target_file $final_path/config/config.json
# Configure log file location # Configure log file location
sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json ynh_replace_string --match_string "\"FileLocation\": \"\"" --replace_string "\"FileLocation\": \"$logs_path\"" --target_file $final_path/config/config.json
# Disable questionable password complexity rules
ynh_replace_string --match_string "\"MinimumLength\": 10" --replace_string "\"MinimumLength\": 8" --target_file $final_path/config/config.json
ynh_replace_string --match_string "\"Lowercase\": true" --replace_string "\"Lowercase\": false" --target_file $final_path/config/config.json
ynh_replace_string --match_string "\"Number\": true" --replace_string "\"Number\": false" --target_file $final_path/config/config.json
ynh_replace_string --match_string "\"Uppercase\": true" --replace_string "\"Uppercase\": false" --target_file $final_path/config/config.json
ynh_replace_string --match_string "\"Symbol\": true" --replace_string "\"Symbol\": false" --target_file $final_path/config/config.json
# Configure analytics according to user choice # Configure analytics according to user choice
if [ $analytics -eq 0 ]; then if [ $analytics -eq 0 ]; then
sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json ynh_replace_string --match_string "\"EnableDiagnostics\": true" --replace_string "\"EnableDiagnostics\": false" --target_file $final_path/config/config.json
fi fi
ynh_app_setting_set "$app" analytics "$analytics" ynh_app_setting_set "$app" analytics "$analytics"

View file

@ -146,12 +146,12 @@ yunohost service add "$app" --log "$logs_path/mattermost.log"
# Fix log FileLocation path (changed in Mattermost 3.8, makes Mattermost >= 4.2 crash) # Fix log FileLocation path (changed in Mattermost 3.8, makes Mattermost >= 4.2 crash)
# https://docs.mattermost.com/administration/changelog.html#release-v3-8-3 # https://docs.mattermost.com/administration/changelog.html#release-v3-8-3
sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file" ynh_replace_string --match_string "\"FileLocation\": \"/var/log/mattermost.log\"" --replace_string "\"FileLocation\": \"/var/log\"" --target_file "$config_file"
# Move log files to a directory (rather than directly in /var/log) # Move log files to a directory (rather than directly in /var/log)
# See https://github.com/YunoHost-Apps/mattermost_ynh/issues/61 # See https://github.com/YunoHost-Apps/mattermost_ynh/issues/61
mkdir -p "$logs_path" mkdir -p "$logs_path"
sed -i "s|\"FileLocation\": \"/var/log\"|\"FileLocation\": \"$logs_path\"|g" "$config_file" ynh_replace_string --match_string "\"FileLocation\": \"/var/log\"" --replace_string "\"FileLocation\": \"$logs_path\"" --target_file "$config_file"
if [ -f "/var/log/${app}.log" ]; then if [ -f "/var/log/${app}.log" ]; then
mv "/var/log/${app}.log" "$logs_path/" mv "/var/log/${app}.log" "$logs_path/"
fi fi