Last active
April 2, 2024 09:28
-
-
Save shorefall/9ec05ee75cecba66a5b2b910f1966ea9 to your computer and use it in GitHub Desktop.
Mattermost & DB Setup Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Mattermost and PostgreSQL Installation Script | |
# | |
# This script automates the installation of Mattermost and PostgreSQL on an Ubuntu server. | |
# It sets up a PostgreSQL database and prepares the Mattermost environment but does not start or enable the Mattermost service. | |
# This is to ensure that Mattermost is not started before its configuration, especially database settings, is properly completed. | |
# | |
# How to Use This Script: | |
# 1. Database Password: Change 'mmuser-password' to a strong, secure password of your choice. | |
# 2. Manual Configuration: After running this script, manually configure the database settings in | |
# /opt/mattermost/config/config.json. Update the DataSource with the PostgreSQL details (user and password) you've configured. | |
# Also, set the 'SiteURL' to where your Mattermost server will be accessed. | |
# 3. Final Steps: After configuration, start and enable the Mattermost service using: | |
# sudo systemctl start mattermost | |
# sudo systemctl enable mattermost.service | |
# 4. Running the Script: Save this script to a file, e.g., setup_mattermost.sh. Make it executable with: | |
# chmod +x setup_mattermost.sh | |
# Run the script as root or with sudo: ./setup_mattermost.sh | |
# | |
# Note: This script is designed for Ubuntu servers and assumes Mattermost and PostgreSQL are installed on the same machine. | |
# Ensure the script is run as root | |
if [ "$(id -u)" -ne 0 ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
# Update system packages | |
sudo apt update | |
# Install PostgreSQL and its contrib package | |
sudo apt install postgresql postgresql-contrib -y | |
# Create Mattermost database and user | |
sudo -u postgres psql -c "CREATE DATABASE mattermost;" | |
sudo -u postgres psql -c "CREATE USER mmuser WITH PASSWORD 'mmuser-password';" | |
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE mattermost TO mmuser;" | |
# Determine PostgreSQL version directory | |
PG_VERSION_DIR=$(ls -d /etc/postgresql/* | head -n 1) | |
# Configure PostgreSQL to listen on all IP addresses | |
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" "${PG_VERSION_DIR}/main/postgresql.conf" | |
# Configure pg_hba.conf for local connections | |
echo "host all all 127.0.0.1/32 md5" | sudo tee -a "${PG_VERSION_DIR}/main/pg_hba.conf" | |
echo "host all all ::1/128 md5" | sudo tee -a "${PG_VERSION_DIR}/main/pg_hba.conf" | |
# Restart PostgreSQL to apply configuration changes | |
sudo systemctl restart postgresql | |
# Add the Mattermost Server PPA repository to install Mattermost | |
curl -o- https://deb.packages.mattermost.com/repo-setup.sh | sudo bash -s mattermost | |
# Update all repositories and install Mattermost Server | |
sudo apt update | |
sudo apt install mattermost -y | |
# Configuration of Mattermost | |
# Rename the default configuration file with correct permissions | |
sudo install -C -m 600 -o mattermost -g mattermost /opt/mattermost/config/config.defaults.json /opt/mattermost/config/config.json | |
# Reminder for manual configuration | |
echo "Reminder: Manually configure the database settings in /opt/mattermost/config/config.json and set the 'SiteURL'." | |
echo "After configuring, start and enable the Mattermost service using:" | |
echo "sudo systemctl start mattermost" | |
echo "sudo systemctl enable mattermost.service" | |
echo "Mattermost installation is complete. Remember to configure it before starting the service." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment