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

scripts: remove all usages of sudo

The scripts are already run as root.
This commit is contained in:
Pierre de La Morinerie 2020-02-09 00:27:51 +01:00
parent e526f969a9
commit fefff41733
5 changed files with 61 additions and 61 deletions

View file

@ -9,7 +9,7 @@ A Yunohost package for [Mattermost](http://www.mattermost.org/), an open-source,
Mattermost requires:
* A x86_64 system (check with `uname -m`),
* Yunohost 2.7 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`).
## Installing

View file

@ -107,7 +107,7 @@ ynh_app_setting_set "$app" mysqlpwd "$db_password"
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')
sudo 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"
#=================================================
@ -117,36 +117,36 @@ ynh_app_setting_set "$app" smtppwd "$mattermost_user_password"
ynh_app_setting_set "$app" final_path "$final_path"
ynh_setup_source "$final_path"
sudo mkdir -p "$data_path"
sudo mkdir -p "$logs_path"
mkdir -p "$data_path"
mkdir -p "$logs_path"
#=================================================
# EDIT MATTERMOST CONFIG
#=================================================
# Configure Service Settings
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
sudo sed -i "s|\"ListenAddress\": \".*\"|\"ListenAddress\": \"127.0.0.1:${port}\"|g" $final_path/config/config.json
sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
sed -i "s|\"ListenAddress\": \".*\"|\"ListenAddress\": \"127.0.0.1:${port}\"|g" $final_path/config/config.json
# Configure the database connection
db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8"
sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
# Configure uploaded files directory
sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
# Configure SMTP account for sending email notifications
sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${mattermost_user}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${mattermost_user_password}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${mattermost_user}\"|g" $final_path/config/config.json
sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${mattermost_user_password}\"|g" $final_path/config/config.json
sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
# Disable Mattermost debug console by default
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
# Configure log file location
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json
sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json
# Configure analytics according to user choice
if [ $analytics -eq 0 ]; then
sudo sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
fi
ynh_app_setting_set "$app" analytics "$analytics"
@ -154,9 +154,9 @@ ynh_app_setting_set "$app" analytics "$analytics"
# SECURE FILES AND DIRECTORIES
#=================================================
sudo chown -R "$mattermost_user:www-data" "$final_path"
sudo chown -R "$mattermost_user:www-data" "$data_path"
sudo chown -R "$mattermost_user:adm" "$logs_path"
chown -R "$mattermost_user:www-data" "$final_path"
chown -R "$mattermost_user:www-data" "$data_path"
chown -R "$mattermost_user:adm" "$logs_path"
#=================================================
# NGINX CONFIGURATION
@ -174,7 +174,7 @@ ynh_add_systemd_config
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
yunohost service add "$app" --log "$logs_path/mattermost.log"
#=================================================
# SETUP SSOWAT
@ -191,13 +191,13 @@ fi
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx
systemctl reload nginx
#=================================================
# START SERVER
#=================================================
sudo systemctl start "$app"
systemctl start "$app"
#=================================================
# CREATE ADMIN AND FIRST TEAM
@ -207,10 +207,10 @@ admin_username=$(cut -d @ -f 1 <<< "$admin_email")
team_name=$(echo "$team_display_name" | iconv -f utf8 -t ascii//TRANSLIT//IGNORE | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)
cd "$final_path/bin"
sudo ./mattermost user create --username "$admin_username" --email "$admin_email" --password "$admin_password" --locale "$admin_locale" --system_admin
sudo ./mattermost user verify "$admin_username"
sudo ./mattermost team create --name "$team_name" --display_name "$team_display_name" --email "$admin_email"
sudo ./mattermost team add "$team_name" "$admin_username"
./mattermost user create --username "$admin_username" --email "$admin_email" --password "$admin_password" --locale "$admin_locale" --system_admin
./mattermost user verify "$admin_username"
./mattermost team create --name "$team_name" --display_name "$team_display_name" --email "$admin_email"
./mattermost team add "$team_name" "$admin_username"
ynh_app_setting_set "$app" admin_email "$admin_email"
ynh_app_setting_set "$app" admin_locale "$admin_locale"

View file

@ -29,8 +29,8 @@ logs_path="/var/log/$app"
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
if sudo yunohost service status | grep -q "$app"; then
sudo yunohost service remove "$app"
if yunohost service status | grep -q "$app"; then
yunohost service remove "$app"
fi
#=================================================
@ -38,15 +38,15 @@ fi
#=================================================
# Remove systemd service
if $(sudo systemctl -q is-active "$app"); then
sudo systemctl stop "$app"
if $(systemctl -q is-active "$app"); then
systemctl stop "$app"
fi
ynh_remove_systemd_config
# Legacy, for older versions of this app which used supervisor
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
sudo supervisorctl stop "$app"
sudo ynh_secure_remove --file="/etc/supervisor/conf.d/${app}.conf"
supervisorctl stop "$app"
ynh_secure_remove --file="/etc/supervisor/conf.d/${app}.conf"
fi
#=================================================
@ -72,7 +72,7 @@ ynh_remove_nginx_config
# REMOVE LOG FILE
#=================================================
sudo ynh_secure_remove --file="$logs_path"
ynh_secure_remove --file="$logs_path"
#=================================================
# REMOVE DEDICATED USER

View file

@ -82,13 +82,13 @@ fi
#=================================================
# Restore permissions on app files
sudo chown -R "$mattermost_user:www-data" "$final_path"
chown -R "$mattermost_user:www-data" "$final_path"
mkdir -p "$data_path"
sudo chown -R "$mattermost_user:www-data" "$data_path"
chown -R "$mattermost_user:www-data" "$data_path"
mkdir -p "$logs_path"
sudo chown -R "$mattermost_user:adm" "$logs_path"
chown -R "$mattermost_user:adm" "$logs_path"
#=================================================
# RESTORE SSOWAT
@ -109,13 +109,13 @@ fi
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
sudo systemctl enable "$app"
systemctl enable "$app"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
yunohost service add "$app" --log "$logs_path/mattermost.log"
#=================================================
# GENERIC FINALIZATION
@ -123,10 +123,10 @@ sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
# RELOAD NGINX
#=================================================
sudo service nginx reload
service nginx reload
#=================================================
# START SERVER
#=================================================
sudo systemctl start "$app"
systemctl start "$app"

View file

@ -51,8 +51,8 @@ fi
ynh_clean_setup () {
if [ "$can_restore_backup" = true ]; then
# Stop attempting to restart the app
if $(sudo systemctl -q is-active "$app"); then
sudo systemctl stop "$app"
if $(systemctl -q is-active "$app"); then
systemctl stop "$app"
fi
# Restore the backup
ynh_restore_upgradebackup
@ -60,7 +60,7 @@ ynh_clean_setup () {
else
# Backup restoration is not available:
# let's try at least to restart the server.
sudo systemctl start "$app"
systemctl start "$app"
fi
}
@ -72,14 +72,14 @@ ynh_abort_if_errors
#=================================================
# Stop the server (if the app is already using systemd)
if $(sudo systemctl -q is-active "$app"); then
sudo systemctl stop "$app"
if $(systemctl -q is-active "$app"); then
systemctl stop "$app"
fi
# Legacy, for previous versions of this app which used supervisor
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
sudo supervisorctl stop "$app"
sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
supervisorctl stop "$app"
rm -f "/etc/supervisor/conf.d/${app}.conf"
fi
#=================================================
@ -89,7 +89,7 @@ fi
config_file="$final_path/config/config.json"
backup_config_file="/tmp/config.json"
sudo cp -f "$config_file" "$backup_config_file"
cp -f "$config_file" "$backup_config_file"
#=================================================
# MIGRATE SETTINGS FROM PREVIOUS VERSIONS
@ -120,7 +120,7 @@ ynh_setup_source "$final_path"
# RESTORE CONFIGURATION FILE
#=================================================
sudo cp -f "$backup_config_file" "$config_file"
cp -f "$backup_config_file" "$config_file"
#=================================================
# NGINX CONFIGURATION
@ -138,7 +138,7 @@ ynh_add_systemd_config
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
yunohost service add "$app" --log "$logs_path/mattermost.log"
#=================================================
# SPECIFIC UPGRADE STEPS
@ -146,32 +146,32 @@ sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
# 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
sudo sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file"
sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file"
# Move log files to a directory (rather than directly in /var/log)
# See https://github.com/YunoHost-Apps/mattermost_ynh/issues/61
sudo mkdir -p "$logs_path"
sudo sed -i "s|\"FileLocation\": \"/var/log\"|\"FileLocation\": \"$logs_path\"|g" "$config_file"
mkdir -p "$logs_path"
sed -i "s|\"FileLocation\": \"/var/log\"|\"FileLocation\": \"$logs_path\"|g" "$config_file"
if [ -f "/var/log/${app}.log" ]; then
sudo mv "/var/log/${app}.log" "$logs_path/"
mv "/var/log/${app}.log" "$logs_path/"
fi
#=================================================
# RESTORE FILE PERMISSIONS
#=================================================
sudo chown -R "$mattermost_user:www-data" "$final_path"
sudo chown -R "$mattermost_user:www-data" "$data_path"
sudo chown -R "$mattermost_user:adm" "$logs_path"
chown -R "$mattermost_user:www-data" "$final_path"
chown -R "$mattermost_user:www-data" "$data_path"
chown -R "$mattermost_user:adm" "$logs_path"
#=================================================
# RELOAD NGINX
#=================================================
sudo service nginx reload
service nginx reload
#=================================================
# START SERVER
#=================================================
sudo systemctl start "$app"
systemctl start "$app"