1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/phpmyadmin_ynh.git synced 2024-09-03 19:56:46 +02:00
phpmyadmin_ynh/scripts/upgrade
2015-08-27 00:16:53 +02:00

77 lines
2.8 KiB
Bash

#!/bin/bash
# Retrieve arguments
domain=$(sudo yunohost app setting phpmyadmin domain)
path=$(sudo yunohost app setting phpmyadmin path)
admin=$(sudo yunohost app setting phpmyadmin admin)
# Remove trailing "/" for next commands
path=${path%/}
# In older version, the admin setting was admin_user
if [[ -z "$admin" ]]; then
admin=$(sudo yunohost app setting phpmyadmin admin_user)
sudo yunohost app setting phpmyadmin admin_user -d
sudo yunohost app setting phpmyadmin admin -v $admin
fi
# Copy files to the right place
final_path=/var/www/phpmyadmin
version=$(cat ../conf/upstream_version)
sudo rm -rf $final_path
sudo mkdir -p $final_path
echo "Downloading phpMyAdmin $version..."
sudo wget -O ../phpMyAdmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz > /dev/null 2>&1
echo "Extracting to $final_path..."
sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1
sudo cp -r ../phpMyAdmin-$version-all-languages/* $final_path
# Database settings
echo "Setting up database..."
db_user=phpmyadmin
db_pwd=$(sudo yunohost app setting phpmyadmin mysqlpwd)
# Update tables
mysql -u $db_user -p$db_pwd < $final_path/sql/upgrade_column_info_4_3_0+.sql
mysql -u $db_user -p$db_pwd < $final_path/sql/create_tables.sql
# Configuration
echo "Configuring application..."
sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.inc.php
sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/config.inc.php
sed -i "s@YNH_PMA_PASSWORD@$db_pwd@g" ../conf/config.inc.php
sed -i "s@YNH_MYSQL_ROOT_PASSWORD@$(sudo cat /etc/yunohost/mysql)@g" ../conf/config.inc.php
sudo cp ../conf/config.inc.php $final_path
sudo yunohost app addaccess phpmyadmin -u $admin
sudo yunohost app setting phpmyadmin admin -v $admin
# Files owned by root, www-data can just read
echo "Setting permission..."
sudo chown -R root: $final_path
sudo find $final_path -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755
# config.inc.php contains sensitive data, restrict its access
sudo chown root:www-data $final_path/config.inc.php
sudo chmod 640 $final_path/config.inc.php
# Modify Nginx configuration file and copy it to Nginx conf directory
echo "Setting up nginx configuration..."
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
sed -i "s@NAMETOCHANGE@phpmyadmin@g" ../conf/nginx.conf
nginxconf=/etc/nginx/conf.d/$domain.d/phpmyadmin.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
# Add dedicated php-fpm to be able to upload bigger database
sed -i "s@NAMETOCHANGE@phpmyadmin@g" ../conf/php-fpm.conf
phpfpmconf=/etc/php5/fpm/pool.d/phpmyadmin.conf
sudo cp ../conf/php-fpm.conf $phpfpmconf
sudo chown root: $phpfpmconf
sudo chmod 644 $phpfpmconf
sudo service php5-fpm restart
sudo service nginx reload
sudo yunohost app ssowatconf