diff --git a/VERSION b/VERSION index 1defe53..7ec1d6d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.1.0 +2.1.0 diff --git a/scripts/install b/scripts/install index 650b1d7..7db3d8a 100644 --- a/scripts/install +++ b/scripts/install @@ -6,6 +6,13 @@ domain=$1 is_public=$2 path="" +# Set up common variables +root_path="$(pwd)/.." +final_path=/var/www/mattermost +data_path=/home/yunohost.app/mattermost +version=$(cat "$root_path/VERSION") +archive_filename="mattermost-$version.tar.gz" + # Check for 64 bits support arch="$(uname -m)" if [[ "$arch" != "x86_64" ]]; then @@ -52,8 +59,8 @@ function exit_properly 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" + sudo rm -Rf "$final_path" + rm "$archive_filename" exit 1 } trap exit_properly ERR @@ -61,25 +68,23 @@ 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 - +sudo yunohost app setting mattermost smtppwd -v "$smtp_password" +/ # Download and install code -root_path=$(pwd)/.. -final_path=/var/www/mattermost -data_path=/home/yunohost.app/mattermost -sudo mkdir -p $final_path -sudo mkdir -p $data_path +archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz" -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" +sudo mkdir -p "$final_path" +sudo mkdir -p "$data_path" + +wget --quiet --output-document "$archive_filename" "$archive_url" +sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1 +rm -f "$archive_filename" # 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 -sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json +sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json 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 diff --git a/scripts/upgrade b/scripts/upgrade index 13f0e93..06f7ac1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -5,11 +5,17 @@ set -e # Exit on error domain=$(sudo yunohost app setting mattermost domain) is_public=$(sudo yunohost app setting mattermost is_public) +# Set up common variables +root_path="$(pwd)/.." +final_path=/var/www/mattermost +version=$(cat "$root_path/VERSION") +archive_filename="mattermost-$version.tar.gz" + # Cleanup and restart if exit with an error function cleanup_and_restart { set +e - rm "mattermost.tar.gz" + rm "$archive_filename" sudo supervisorctl start mattermost exit 1 } @@ -19,28 +25,26 @@ trap cleanup_and_restart ERR sudo supervisorctl stop mattermost # Download code -root_path=$(pwd)/.. -final_path=/var/www/mattermost -config_file=$final_path/config/config.json -backup_config_file=/tmp/config.json - -version=$(cat $root_path/VERSION) -wget -q "https://github.com/mattermost/platform/releases/download/${version}/mattermost.tar.gz" +archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz" +wget --quiet --output-document "$archive_filename" "$archive_url" # Backup configuration file -sudo cp -f $config_file $backup_config_file +config_file="$final_path/config/config.json" +backup_config_file="/tmp/config.json" + +sudo cp -f "$config_file" "$backup_config_file" # Copy new code -sudo rm -rf $final_path -sudo mkdir -p $final_path -sudo tar -xvz --file "mattermost.tar.gz" --directory $final_path --strip-components 1 -rm -f "mattermost.tar.gz" +sudo rm -rf "$final_path" +sudo mkdir -p "$final_path" +sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1 +rm -f "$archive_filename" # Restore configuration file -sudo cp -f $backup_config_file $config_file +sudo cp -f "$backup_config_file" "$config_file" # Restore file permissions -sudo chown -R www-data: $final_path +sudo chown -R www-data: "$final_path" # Start server sudo supervisorctl start mattermost