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

118 lines
4.5 KiB
Text
Raw Normal View History

2015-10-21 13:03:49 +02:00
#!/bin/bash
set -e # Exit on error
# Retrieve arguments
domain=$1
is_public=$2
path=""
2015-10-21 16:24:51 +02:00
# Check for 64 bits support
arch="$(uname -m)"
if [[ "$arch" != "x86_64" ]]; then
echo "Mattermost requires an x86_64 machine, but this one is '${arch}'."
exit 1
fi
# Check for MySQL version (ugly, to be improved)
mysql_version=$(mysql --version)
if [[ "$mysql_version" == *"Distrib 4."* ]] \
|| [[ "$mysql_version" == *"Distrib 5.0"* ]] \
|| [[ "$mysql_version" == *"Distrib 5.1"* ]] \
|| [[ "$mysql_version" == *"Distrib 5.2"* ]] \
|| [[ "$mysql_version" == *"Distrib 5.3"* ]] \
|| [[ "$mysql_version" == *"Distrib 5.4"* ]] \
|| [[ "$mysql_version" == *"Distrib 5.5"* ]];
then
echo "Mattermost requires MySQL 5.6 or higher."
exit 1
fi
2015-10-21 13:03:49 +02:00
# Check domain availability
sudo yunohost app checkurl $domain$path -a mattermost
if [[ ! $? -eq 0 ]]; then
exit 1
fi
2015-11-18 17:21:35 +01:00
sudo yunohost app setting mattermost domain -v $domain
2015-10-21 13:03:49 +02:00
# Install dependencies
2015-10-21 16:24:51 +02:00
command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor
2015-10-21 13:03:49 +02:00
# Initialize database and store mysql password for upgrade
2015-10-21 14:33:49 +02:00
db_name="mattermost"
2015-10-21 13:03:49 +02:00
db_user="mmuser"
2015-10-21 14:33:49 +02:00
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
sudo yunohost app setting mattermost mysqlpwd -v $db_password
2015-10-21 13:03:49 +02:00
2015-10-21 14:33:49 +02:00
# Delete db and user if exit with an error
function exit_properly
{
set +e
root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE mattermost ; DROP USER mmuser@localhost ;"
sudo userdel mattermost
sudo rm -Rf /var/www/mattermost
rm "mattermost.tar.gz"
2015-10-21 14:33:49 +02:00
exit 1
}
trap exit_properly ERR
# 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')
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "mattermost"
sudo yunohost app setting mattermost smtppwd -v $smtp_password
2015-10-21 13:03:49 +02:00
# Download and install code
2015-10-21 13:03:49 +02:00
root_path=$(pwd)/..
final_path=/var/www/mattermost
data_path=/home/yunohost.app/mattermost
2015-10-21 13:03:49 +02:00
sudo mkdir -p $final_path
sudo mkdir -p $data_path
version=$(cat $root_path/VERSION)
wget -q "https://github.com/mattermost/platform/releases/download/${version}/mattermost.tar.gz"
sudo tar -xvz --file "mattermost.tar.gz" --directory $final_path --strip-components 1
rm -f "mattermost.tar.gz"
2015-10-21 14:33:49 +02:00
# Change variables in Mattermost config
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
2015-10-21 14:46:47 +02:00
sudo sed -i "s|\"Directory\": \"./data/\"|\"DataSource\": \"${data_path}/\"|g" $final_path/config/config.json
2015-10-21 14:33:49 +02:00
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\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${smtp_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
2015-10-21 13:03:49 +02:00
2015-10-21 14:46:47 +02:00
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"/var/log/mattermost.log\"|g" $final_path/config/config.json
# Set permissions to app directories
2015-10-21 13:03:49 +02:00
sudo chown -R www-data: $final_path
sudo chown -R www-data: $data_path
2015-10-21 13:03:49 +02:00
# Modify Nginx configuration file and copy it to Nginx conf directory
sudo cp $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf
# Copy supervisor script
sudo cp $root_path/conf/supervisor.conf /etc/supervisor/conf.d/mattermost.conf
2015-10-21 14:33:49 +02:00
# Enable public access if needed
sudo yunohost app setting mattermost is_public -v $is_public
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting mattermost unprotected_uris -v "/"
fi
2015-10-21 13:03:49 +02:00
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app ssowatconf
# Start app
2015-10-21 16:24:51 +02:00
sudo supervisorctl reload