From 4e364077e8bbd9742f21e69eb59306c000d9ae42 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Tue, 14 Feb 2017 23:21:53 +0000 Subject: [PATCH] Initial commit to update script to respect YEP --- scripts/install | 90 ++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/scripts/install b/scripts/install index 31cba03..d5cecbf 100644 --- a/scripts/install +++ b/scripts/install @@ -1,43 +1,63 @@ #!/bin/bash +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. + # Retrieve arguments -domain=$1 -path=$2 -admin=$3 +app=$YNH_APP_INSTANCE_NAME +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN -# 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 -sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" -if [[ ! $? -eq 0 ]]; then - echo "Error : the chosen admin user does not exist" - exit 1 -fi +# 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. + +CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. + +# 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 + +# Créer le repertoire de destination et stocke son emplacement. +sudo mkdir "$final_path" +ynh_app_setting_set $app final_path $final_path # Copy files to the right place version=$(cat ../conf/upstream_version) -final_path=/var/www/phpmyadmin -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 wget -O https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz -O ../phpMyAdmin.tar.gz +#sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1 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..." -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') -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 -mysql -u $db_user -p$db_pwd < $final_path/sql/create_tables.sql -sudo yunohost app setting phpmyadmin mysqlpwd -v $db_pwd +GENERATE_DB $app # Créer une base de données et un utilisateur dédié au nom de l'app. +#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 +ynh_app_setting_set $app mysqlpwd $db_pwd # Configuration echo "Configuring application..." @@ -47,8 +67,8 @@ 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 +#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..." @@ -63,19 +83,19 @@ sudo chmod 640 $final_path/config.inc.php 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 +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 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 +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 -sudo service php5-fpm restart +sudo service php5-fpm reload sudo service nginx reload sudo yunohost app ssowatconf