#!/bin/bash source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script TRAP_ON # Active trap pour arrêter le script si une erreur est détectée. # Retrieve arguments 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. # Créer le repertoire de destination et stocke son emplacement. CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. sudo mkdir "$final_path" ynh_app_setting_set $app final_path $final_path # 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 # Copy files to the right place version=$(cat ../sources/upstream_version) sudo wget -nv https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz -O phpMyAdmin-$version-all-languages.tar.gz sudo wget -nv https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz.sha256 -O phpMyAdmin-$version-all-languages.tar.gz.sha256 sudo sha256sum -c phpMyAdmin-$version-all-languages.tar.gz.sha256 --status || (echo "Corrupt source" >&2 && false) sudo tar xzf phpMyAdmin-$version-all-languages.tar.gz -C ../sources/ > /dev/null 2>&1 sudo cp -r ../sources/phpMyAdmin-$version-all-languages/* $final_path # Create db 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=$(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 ynh_app_setting_set $app db_pwd $db_pwd ynh_app_setting_set $app db_user $db_user sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/create_db.sql sudo mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_db.sql 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 sudo 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 # Files owned by root, www-data can just read echo "Setting permission..." sudo chown -R root: $final_path sudo find $final_path -type f -exec chmod 644 {} \; sudo find $final_path -type d -exec 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@$app@g" ../conf/nginx.conf nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf sudo cp ../conf/nginx.conf $nginxconf sudo chown root: $nginxconf sudo chmod 644 $nginxconf # Add dedicated php-fpm to be able to upload bigger database sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf phpfpmconf=/etc/php5/fpm/pool.d/$app.conf sudo cp ../conf/php-fpm.conf $phpfpmconf sudo chown root: $phpfpmconf sudo chmod 644 $phpfpmconf # We grant access to admin only sudo yunohost app addaccess --users=$admin $app sudo service php5-fpm reload sudo service nginx reload sudo yunohost app ssowatconf