2014-01-14 22:57:44 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
2014-04-03 12:22:53 +02:00
|
|
|
admin=$3
|
2014-01-14 22:57:44 +01:00
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a phpmyadmin
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that admin user is an existing account
|
2014-05-29 12:03:52 +02:00
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
2014-01-14 22:57:44 +01:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
echo "Error : the chosen admin user does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-03-03 00:56:13 +01:00
|
|
|
# Copy files to the right place
|
2015-07-07 23:02:26 +02:00
|
|
|
version=$(cat ../conf/upstream_version)
|
2014-03-03 00:56:13 +01:00
|
|
|
final_path=/var/www/phpmyadmin
|
|
|
|
sudo rm -rf $final_path
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
echo "Downloading phpMyAdmin $version..."
|
2015-07-04 22:29:11 +02:00
|
|
|
sudo wget -O ../phpMyAdmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz > /dev/null 2>&1
|
2014-03-03 00:56:13 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
# Create db
|
|
|
|
echo "Setting up database..."
|
2014-01-14 22:57:44 +01:00
|
|
|
db_user=phpmyadmin
|
|
|
|
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
2015-01-05 20:05:47 +01:00
|
|
|
cookie_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
2014-01-14 22:57:44 +01:00
|
|
|
sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/create_db.sql
|
|
|
|
sudo yunohost app initdb $db_user -p $db_pwd
|
|
|
|
mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_db.sql
|
2016-03-02 11:39:08 +01:00
|
|
|
mysql -u $db_user -p$db_pwd < $final_path/sql/create_tables.sql
|
2014-01-14 22:57:44 +01:00
|
|
|
sudo yunohost app setting phpmyadmin mysqlpwd -v $db_pwd
|
|
|
|
|
2014-03-03 00:56:13 +01:00
|
|
|
# Configuration
|
|
|
|
echo "Configuring application..."
|
2014-01-14 22:57:44 +01:00
|
|
|
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
|
2015-01-05 20:06:15 +01:00
|
|
|
sed -i "s@YNH_COOKIE_PASSWD@$cookie_pwd@g" ../conf/config.inc.php
|
2014-01-14 22:57:44 +01:00
|
|
|
sudo cp ../conf/config.inc.php $final_path
|
2014-03-03 22:27:44 +01:00
|
|
|
|
2014-04-03 12:22:53 +02:00
|
|
|
sudo yunohost app addaccess phpmyadmin -u $admin
|
|
|
|
sudo yunohost app setting phpmyadmin admin -v $admin
|
2014-01-14 22:57:44 +01:00
|
|
|
|
|
|
|
# Files owned by root, www-data can just read
|
2014-03-03 00:56:13 +01:00
|
|
|
echo "Setting permission..."
|
2014-01-14 22:57:44 +01:00
|
|
|
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
|
2014-07-22 15:58:29 +02:00
|
|
|
# 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
|
2014-01-14 22:57:44 +01:00
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2014-03-03 00:56:13 +01:00
|
|
|
echo "Setting up nginx configuration..."
|
2014-01-14 22:57:44 +01:00
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
|
2015-07-14 09:26:47 +02:00
|
|
|
sed -i "s@NAMETOCHANGE@phpmyadmin@g" ../conf/nginx.conf
|
2014-01-14 22:57:44 +01:00
|
|
|
nginxconf=/etc/nginx/conf.d/$domain.d/phpmyadmin.conf
|
|
|
|
sudo cp ../conf/nginx.conf $nginxconf
|
|
|
|
sudo chown root: $nginxconf
|
|
|
|
sudo chmod 600 $nginxconf
|
|
|
|
|
2015-07-07 23:00:35 +02:00
|
|
|
# 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
|
2014-01-14 22:57:44 +01:00
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|