2014-01-14 22:57:44 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-02-15 00:21:53 +01:00
|
|
|
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
|
|
|
|
|
|
|
|
CLEAN_SETUP () {
|
|
|
|
# Nettoyage des résidus d'installation non pris en charge par le script remove.
|
|
|
|
# Pas de nettoyage supplémentaire nécessaire ici...
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
TRAP_ON # Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
|
2014-01-14 22:57:44 +01:00
|
|
|
# Retrieve arguments
|
2017-02-15 00:21:53 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
|
|
|
|
|
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Vérifie que les variables ne sont pas vides.
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
|
|
|
|
CHECK_USER "$admin" # Vérifie la validité de l'user admin
|
|
|
|
|
|
|
|
CHECK_PATH # Vérifie et corrige la syntaxe du path.
|
|
|
|
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
|
|
|
|
|
2017-02-15 00:52:06 +01:00
|
|
|
# Créer le repertoire de destination et stocke son emplacement.
|
2017-02-15 00:21:53 +01:00
|
|
|
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
2017-02-15 00:52:06 +01:00
|
|
|
sudo mkdir "$final_path"
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2017-02-15 00:21:53 +01:00
|
|
|
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app path $path
|
|
|
|
ynh_app_setting_set $app admin $admin
|
|
|
|
|
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)
|
2017-02-15 01:07:27 +01:00
|
|
|
sudo wget -nv https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz -O ../phpMyAdmin.tar.gz
|
2017-02-15 00:21:53 +01:00
|
|
|
#sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1
|
2014-03-03 00:56:13 +01:00
|
|
|
sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1
|
|
|
|
sudo cp -r ../phpMyAdmin-$version-all-languages/* $final_path
|
|
|
|
|
|
|
|
# Create db
|
2017-02-15 00:52:06 +01:00
|
|
|
#GENERATE_DB $app # Créer une base de données et un utilisateur dédié au nom de l'app.
|
2017-02-15 00:21:53 +01:00
|
|
|
#Password is stored like that in the GENERATE_DB function : ynh_app_setting_set $app mysqlpwd $db_pwd
|
|
|
|
db_user=$app
|
|
|
|
db_user=${db_user//-/_} # mariadb ne supporte pas les - dans les noms de base de données. Ils sont donc remplacé par des _
|
|
|
|
# Génère un mot de passe aléatoire.
|
|
|
|
# db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
|
|
|
|
db_pwd=$(ynh_string_random)
|
|
|
|
CHECK_VAR "$db_pwd" "db_pwd empty"
|
|
|
|
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
|
|
|
# Initialise la base de donnée et stocke le mot de passe mysql.
|
|
|
|
ynh_mysql_create_db "$db_user" "$db_user" $db_pwd
|
2017-02-15 00:52:06 +01:00
|
|
|
ynh_app_setting_set $app db_pwd $db_pwd
|
|
|
|
ynh_app_setting_set $app db_user $db_user
|
2017-02-15 01:15:41 +01:00
|
|
|
sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/create_db.sql
|
2017-02-15 00:52:06 +01:00
|
|
|
sudo mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_db.sql
|
2017-02-15 14:20:01 +01:00
|
|
|
sudo sed -i "s@phpmyadmin@$db_user@g" $final_path/sql/create_tables.sql
|
|
|
|
#sudo sed -i "s@YNH_PMA_USER@$db_user@g" $final_path/sql/create_tables.sql
|
2017-02-15 00:52:06 +01:00
|
|
|
sudo mysql -u $db_user -p$db_pwd < $final_path/sql/create_tables.sql
|
2014-01-14 22:57:44 +01:00
|
|
|
|
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
|
|
|
|
sudo cp ../conf/config.inc.php $final_path
|
2014-03-03 22:27:44 +01:00
|
|
|
|
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
|
2016-04-03 23:46:13 +02:00
|
|
|
sudo find $final_path -type f -exec chmod 644 {} \;
|
|
|
|
sudo find $final_path -type d -exec 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
|
2017-02-15 00:52:06 +01:00
|
|
|
sed -i "s@YNH_WWW_ALIAS@$final_path@g" ../conf/nginx.conf
|
2017-02-15 00:21:53 +01:00
|
|
|
sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
|
|
|
|
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
|
2014-01-14 22:57:44 +01:00
|
|
|
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
|
2017-02-15 00:21:53 +01:00
|
|
|
sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
|
|
|
|
phpfpmconf=/etc/php5/fpm/pool.d/$app.conf
|
2015-07-07 23:00:35 +02:00
|
|
|
sudo cp ../conf/php-fpm.conf $phpfpmconf
|
|
|
|
sudo chown root: $phpfpmconf
|
|
|
|
sudo chmod 644 $phpfpmconf
|
|
|
|
|
2017-02-15 01:50:32 +01:00
|
|
|
# We grant access to admin only
|
|
|
|
sudo yunohost app addaccess --users=$admin $app
|
|
|
|
|
2017-02-15 01:53:08 +01:00
|
|
|
sudo service php5-fpm restart
|
2014-01-14 22:57:44 +01:00
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|