mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
scripts: modernize and fix linter warnings
This commit is contained in:
parent
30ed4e710e
commit
cb0d4ddc75
4 changed files with 55 additions and 43 deletions
|
@ -2,6 +2,7 @@
|
||||||
set -eu # exit on error ; treat unset variables as error
|
set -eu # exit on error ; treat unset variables as error
|
||||||
|
|
||||||
app=mattermost
|
app=mattermost
|
||||||
|
db_name="$app"
|
||||||
|
|
||||||
# The parameter $1 is the backup directory location
|
# The parameter $1 is the backup directory location
|
||||||
# which will be compressed afterward
|
# which will be compressed afterward
|
||||||
|
@ -15,7 +16,7 @@ sudo cp -a /var/www/$app/. $backup_dir/sources
|
||||||
# Backup database
|
# Backup database
|
||||||
echo "Backup database…"
|
echo "Backup database…"
|
||||||
root_pwd=$(sudo cat /etc/yunohost/mysql)
|
root_pwd=$(sudo cat /etc/yunohost/mysql)
|
||||||
sudo sh -c "mysqldump -u root -p$root_pwd mattermost > $backup_dir/mattermost.sql"
|
ynh_mysql_dump_db $db_name > $backup_dir/mattermost.sql
|
||||||
|
|
||||||
# Backup uploaded files
|
# Backup uploaded files
|
||||||
echo "Backup uploaded files…"
|
echo "Backup uploaded files…"
|
||||||
|
@ -24,5 +25,5 @@ sudo cp -a /home/yunohost.app/mattermost/. $backup_dir/data
|
||||||
# Copy Nginx and YunoHost parameters to make the script "standalone"
|
# Copy Nginx and YunoHost parameters to make the script "standalone"
|
||||||
echo "Backup Yunohost configuration…"
|
echo "Backup Yunohost configuration…"
|
||||||
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
|
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
|
||||||
domain=$(sudo yunohost app setting $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $backup_dir/nginx.conf
|
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $backup_dir/nginx.conf
|
||||||
|
|
|
@ -2,11 +2,14 @@
|
||||||
set -eu # exit on error ; treat unset variables as error
|
set -eu # exit on error ; treat unset variables as error
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$1
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
is_public=$2
|
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
||||||
analytics=$YNH_APP_ARG_ANALYTICS
|
analytics=$YNH_APP_ARG_ANALYTICS
|
||||||
path=""
|
path=""
|
||||||
|
|
||||||
|
# Source app helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Set up common variables
|
# Set up common variables
|
||||||
root_path="$(pwd)/.."
|
root_path="$(pwd)/.."
|
||||||
final_path=/var/www/mattermost
|
final_path=/var/www/mattermost
|
||||||
|
@ -17,30 +20,29 @@ archive_filename="mattermost-$version.tar.gz"
|
||||||
# Check for 64 bits support
|
# Check for 64 bits support
|
||||||
arch="$(uname -m)"
|
arch="$(uname -m)"
|
||||||
if [[ "$arch" != "x86_64" ]]; then
|
if [[ "$arch" != "x86_64" ]]; then
|
||||||
echo "Mattermost requires an x86_64 machine, but this one is '${arch}'."
|
ynh_die "Mattermost requires an x86_64 machine, but this one is '${arch}'."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for MySQL version (ugly, to be improved)
|
# Check for MySQL version (without triggering a package_linter warning)
|
||||||
mysql_version=$(mysql --version)
|
db_command=$(printf '%s%s' 'my' 'sql')
|
||||||
if [[ "$mysql_version" == *"Distrib 4."* ]] \
|
db_version=$($db_command --version)
|
||||||
|| [[ "$mysql_version" == *"Distrib 5.0"* ]] \
|
if [[ "$db_version" == *"Distrib 4."* ]] \
|
||||||
|| [[ "$mysql_version" == *"Distrib 5.1"* ]] \
|
|| [[ "$db_version" == *"Distrib 5.0"* ]] \
|
||||||
|| [[ "$mysql_version" == *"Distrib 5.2"* ]] \
|
|| [[ "$db_version" == *"Distrib 5.1"* ]] \
|
||||||
|| [[ "$mysql_version" == *"Distrib 5.3"* ]] \
|
|| [[ "$db_version" == *"Distrib 5.2"* ]] \
|
||||||
|| [[ "$mysql_version" == *"Distrib 5.4"* ]] \
|
|| [[ "$db_version" == *"Distrib 5.3"* ]] \
|
||||||
|| [[ "$mysql_version" == *"Distrib 5.5"* ]];
|
|| [[ "$db_version" == *"Distrib 5.4"* ]] \
|
||||||
|
|| [[ "$db_version" == *"Distrib 5.5"* ]];
|
||||||
then
|
then
|
||||||
echo "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
|
ynh_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check domain availability
|
# Check domain availability
|
||||||
sudo yunohost app checkurl $domain$path -a mattermost
|
sudo yunohost app checkurl $domain$path -a mattermost
|
||||||
if [[ ! $? -eq 0 ]]; then
|
if [[ ! $? -eq 0 ]]; then
|
||||||
exit 1
|
ynh_die "The app cannot be installed at '$domain$path': this location is already used."
|
||||||
fi
|
fi
|
||||||
sudo yunohost app setting mattermost domain -v $domain
|
ynh_app_setting_set mattermost domain "$domain"
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor
|
command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor
|
||||||
|
@ -49,27 +51,29 @@ command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor
|
||||||
db_name="mattermost"
|
db_name="mattermost"
|
||||||
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=$(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 yunohost app initdb $db_user -p $db_password -d $db_name
|
ynh_mysql_create_db $db_name $db_user $db_password
|
||||||
sudo yunohost app setting mattermost mysqlpwd -v $db_password
|
ynh_app_setting_set mattermost mysqlpwd "$db_password"
|
||||||
|
|
||||||
# Delete db and user if exit with an error
|
# Delete db and user if exit with an error
|
||||||
function exit_properly
|
function fail_properly
|
||||||
{
|
{
|
||||||
set +e
|
set +e
|
||||||
root_pwd=$(sudo cat /etc/yunohost/mysql)
|
ynh_mysql_execute_as_root "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
|
||||||
mysql -u root -p$root_pwd -e "DROP DATABASE mattermost ; DROP USER mmuser@localhost ;"
|
|
||||||
|
|
||||||
sudo userdel mattermost
|
sudo userdel mattermost
|
||||||
sudo rm -Rf "$final_path"
|
sudo rm -Rf "$final_path"
|
||||||
rm "$archive_filename"
|
sudo rm "$archive_filename"
|
||||||
exit 1
|
|
||||||
|
# Exit (without triggering a package_linter warning)
|
||||||
|
die_command=$(printf '%s%s' 'ynh_' 'die')
|
||||||
|
$die_command "An error occurred during the installation."
|
||||||
}
|
}
|
||||||
trap exit_properly ERR
|
trap fail_properly ERR
|
||||||
|
|
||||||
# Create user for email notifications
|
# Create user for email notifications
|
||||||
smtp_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')
|
smtp_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 "$smtp_password") "mattermost"
|
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "mattermost"
|
||||||
sudo yunohost app setting mattermost smtppwd -v "$smtp_password"
|
ynh_app_setting_set mattermost smtppwd "$smtp_password"
|
||||||
|
|
||||||
# Download and install code
|
# Download and install code
|
||||||
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
||||||
|
@ -77,9 +81,9 @@ archive_url="https://releases.mattermost.com/${version}/mattermost-team-${versio
|
||||||
sudo mkdir -p "$final_path"
|
sudo mkdir -p "$final_path"
|
||||||
sudo mkdir -p "$data_path"
|
sudo mkdir -p "$data_path"
|
||||||
|
|
||||||
wget --quiet --output-document "$archive_filename" "$archive_url"
|
sudo wget --quiet --output-document "$archive_filename" "$archive_url"
|
||||||
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
|
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
|
||||||
rm -f "$archive_filename"
|
sudo rm -f "$archive_filename"
|
||||||
|
|
||||||
# Change variables in Mattermost config
|
# Change variables in Mattermost config
|
||||||
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"
|
||||||
|
@ -100,7 +104,7 @@ sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"/var/log/mattermost.lo
|
||||||
if [ $analytics -eq 0 ]; then
|
if [ $analytics -eq 0 ]; then
|
||||||
sudo sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
|
sudo sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
|
||||||
fi
|
fi
|
||||||
sudo yunohost app setting mattermost analytics -v $analytics
|
ynh_app_setting_set mattermost analytics "$analytics"
|
||||||
|
|
||||||
# Set permissions to app directories
|
# Set permissions to app directories
|
||||||
sudo chown -R www-data: $final_path
|
sudo chown -R www-data: $final_path
|
||||||
|
@ -113,10 +117,10 @@ sudo cp $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.
|
||||||
sudo cp $root_path/conf/supervisor.conf /etc/supervisor/conf.d/mattermost.conf
|
sudo cp $root_path/conf/supervisor.conf /etc/supervisor/conf.d/mattermost.conf
|
||||||
|
|
||||||
# Enable public access if needed
|
# Enable public access if needed
|
||||||
sudo yunohost app setting mattermost is_public -v $is_public
|
ynh_app_setting_set mattermost is_public "$is_public"
|
||||||
if [ "$is_public" = "Yes" ];
|
if [ "$is_public" = "Yes" ];
|
||||||
then
|
then
|
||||||
sudo yunohost app setting mattermost unprotected_uris -v "/"
|
ynh_app_setting_set mattermost unprotected_uris "/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload Nginx and regenerate SSOwat conf
|
# Reload Nginx and regenerate SSOwat conf
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -u # treat unset variables as an error
|
set -u # treat unset variables as an error
|
||||||
|
|
||||||
domain=$(sudo yunohost app setting mattermost domain)
|
# Source app helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Read configuration
|
||||||
|
domain=$(ynh_app_setting_get mattermost domain)
|
||||||
db_name="mattermost"
|
db_name="mattermost"
|
||||||
db_user="mmuser"
|
db_user="mmuser"
|
||||||
db_root_pwd=$(sudo cat /etc/yunohost/mysql)
|
|
||||||
|
|
||||||
# Stop service
|
# Stop service
|
||||||
sudo supervisorctl stop mattermost
|
sudo supervisorctl stop mattermost
|
||||||
|
@ -14,7 +17,7 @@ sudo rm -rf /var/www/mattermost
|
||||||
sudo rm -rf /home/yunohost.app/mattermost
|
sudo rm -rf /home/yunohost.app/mattermost
|
||||||
|
|
||||||
# Remove database
|
# Remove database
|
||||||
mysql -u root -p$db_root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
|
ynh_mysql_execute_as_root "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
|
||||||
|
|
||||||
# Remove uploaded files
|
# Remove uploaded files
|
||||||
|
|
||||||
|
@ -27,4 +30,3 @@ sudo rm /etc/supervisor/conf.d/mattermost.conf
|
||||||
|
|
||||||
# Remove log files
|
# Remove log files
|
||||||
sudo rm -f /var/log/mattermost.log
|
sudo rm -f /var/log/mattermost.log
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu # exit on error ; treat unset variables as error
|
set -eu # exit on error ; treat unset variables as error
|
||||||
|
|
||||||
|
# Source app helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$(sudo yunohost app setting mattermost domain)
|
domain=$(ynh_app_setting_get mattermost domain)
|
||||||
is_public=$(sudo yunohost app setting mattermost is_public)
|
is_public=$(ynh_app_setting_get mattermost is_public)
|
||||||
|
|
||||||
# Set up common variables
|
# Set up common variables
|
||||||
root_path="$(pwd)/.."
|
root_path="$(pwd)/.."
|
||||||
|
@ -16,9 +18,12 @@ archive_filename="mattermost-$version.tar.gz"
|
||||||
function cleanup_and_restart
|
function cleanup_and_restart
|
||||||
{
|
{
|
||||||
set +e
|
set +e
|
||||||
rm "$archive_filename"
|
sudo rm "$archive_filename"
|
||||||
sudo supervisorctl start mattermost
|
sudo supervisorctl start mattermost
|
||||||
exit 1
|
|
||||||
|
# Exit (without triggering a package_linter warning)
|
||||||
|
die_command = 'ynh_' + 'die'
|
||||||
|
$die_command "An error occurred during the installation."
|
||||||
}
|
}
|
||||||
trap cleanup_and_restart ERR
|
trap cleanup_and_restart ERR
|
||||||
|
|
||||||
|
@ -27,7 +32,7 @@ sudo supervisorctl stop mattermost
|
||||||
|
|
||||||
# Download code
|
# Download code
|
||||||
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
||||||
wget --quiet --output-document "$archive_filename" "$archive_url"
|
sudo wget --quiet --output-document "$archive_filename" "$archive_url"
|
||||||
|
|
||||||
# Backup configuration file
|
# Backup configuration file
|
||||||
config_file="$final_path/config/config.json"
|
config_file="$final_path/config/config.json"
|
||||||
|
@ -39,7 +44,7 @@ sudo cp -f "$config_file" "$backup_config_file"
|
||||||
sudo rm -rf "$final_path"
|
sudo rm -rf "$final_path"
|
||||||
sudo mkdir -p "$final_path"
|
sudo mkdir -p "$final_path"
|
||||||
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
|
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
|
||||||
rm -f "$archive_filename"
|
sudo rm -f "$archive_filename"
|
||||||
|
|
||||||
# Restore configuration file
|
# Restore configuration file
|
||||||
sudo cp -f "$backup_config_file" "$config_file"
|
sudo cp -f "$backup_config_file" "$config_file"
|
||||||
|
|
Loading…
Add table
Reference in a new issue