1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/phpmyadmin_ynh.git synced 2024-09-03 19:56:46 +02:00

Initial commit to update script to respect YEP

This commit is contained in:
polytan02 2017-02-14 23:21:53 +00:00
parent a27ae84584
commit 4e364077e8

View file

@ -1,43 +1,63 @@
#!/bin/bash #!/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 # Retrieve arguments
domain=$1 app=$YNH_APP_INSTANCE_NAME
path=$2 domain=$YNH_APP_ARG_DOMAIN
admin=$3 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 # Source app helpers
sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" source /usr/share/yunohost/helpers
if [[ ! $? -eq 0 ]]; then
echo "Error : the chosen admin user does not exist" # Vérifie que les variables ne sont pas vides.
exit 1 CHECK_VAR "$app" "app name not set"
fi
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 # Copy files to the right place
version=$(cat ../conf/upstream_version) version=$(cat ../conf/upstream_version)
final_path=/var/www/phpmyadmin sudo wget -O https://files.phpmyadmin.net/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz -O ../phpMyAdmin.tar.gz
sudo rm -rf $final_path #sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1
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 tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1
sudo cp -r ../phpMyAdmin-$version-all-languages/* $final_path sudo cp -r ../phpMyAdmin-$version-all-languages/* $final_path
# Create db # Create db
echo "Setting up database..." GENERATE_DB $app # Créer une base de données et un utilisateur dédié au nom de l'app.
db_user=phpmyadmin #Password is stored like that in the GENERATE_DB function : ynh_app_setting_set $app mysqlpwd $db_pwd
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') db_user=$app
sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/create_db.sql db_user=${db_user//-/_} # mariadb ne supporte pas les - dans les noms de base de données. Ils sont donc remplacé par des _
sudo yunohost app initdb $db_user -p $db_pwd # Génère un mot de passe aléatoire.
mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_db.sql # db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
mysql -u $db_user -p$db_pwd < $final_path/sql/create_tables.sql db_pwd=$(ynh_string_random)
sudo yunohost app setting phpmyadmin mysqlpwd -v $db_pwd 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 # Configuration
echo "Configuring application..." 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 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 cp ../conf/config.inc.php $final_path
sudo yunohost app addaccess phpmyadmin -u $admin #sudo yunohost app addaccess phpmyadmin -u $admin
sudo yunohost app setting phpmyadmin admin -v $admin #sudo yunohost app setting phpmyadmin admin -v $admin
# Files owned by root, www-data can just read # Files owned by root, www-data can just read
echo "Setting permission..." echo "Setting permission..."
@ -63,19 +83,19 @@ sudo chmod 640 $final_path/config.inc.php
echo "Setting up nginx configuration..." echo "Setting up nginx configuration..."
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf 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@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
sed -i "s@NAMETOCHANGE@phpmyadmin@g" ../conf/nginx.conf sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
nginxconf=/etc/nginx/conf.d/$domain.d/phpmyadmin.conf nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginxconf sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf sudo chown root: $nginxconf
sudo chmod 600 $nginxconf sudo chmod 600 $nginxconf
# Add dedicated php-fpm to be able to upload bigger database # Add dedicated php-fpm to be able to upload bigger database
sed -i "s@NAMETOCHANGE@phpmyadmin@g" ../conf/php-fpm.conf sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
phpfpmconf=/etc/php5/fpm/pool.d/phpmyadmin.conf phpfpmconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $phpfpmconf sudo cp ../conf/php-fpm.conf $phpfpmconf
sudo chown root: $phpfpmconf sudo chown root: $phpfpmconf
sudo chmod 644 $phpfpmconf sudo chmod 644 $phpfpmconf
sudo service php5-fpm restart sudo service php5-fpm reload
sudo service nginx reload sudo service nginx reload
sudo yunohost app ssowatconf sudo yunohost app ssowatconf