From 0f47be9bbf4f5c18882e55bc53cdc44b7ed85b98 Mon Sep 17 00:00:00 2001 From: Dick Thomas Date: Wed, 19 Oct 2016 16:49:54 +0100 Subject: [PATCH 01/25] trying copying rather than move --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index fbd3f76..079950d 100644 --- a/scripts/install +++ b/scripts/install @@ -76,7 +76,7 @@ fi cwd=$(pwd) sudo su - www-data -s /bin/bash -c "mkdir -p $tmp/$app && cd $tmp/$app && php -d memory_limit=-1 /usr/local/bin/composer create-project flarum/flarum . --stability=beta" sudo mkdir $final_path -sudo mv $tmp/$app $final_path/.. +sudo cp -Rfv $tmp/$app $final_path/ sudo chown -R www-data:www-data $final_path cd $cwd sudo rm -rf $tmp From 3de168d103c2b82b53c2be25212fd8977d7b3053 Mon Sep 17 00:00:00 2001 From: TitusPiJean Date: Wed, 18 Jan 2017 20:45:45 +0100 Subject: [PATCH 02/25] Removing api key creation and adding password length requirement --- manifest.json | 8 ++++---- scripts/install | 12 +++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/manifest.json b/manifest.json index 7d85065..d87b3fc 100644 --- a/manifest.json +++ b/manifest.json @@ -61,11 +61,11 @@ "name": "adminpass", "type": "password", "ask": { - "en": "Put your password", - "fr": "Insérez votre mot de passe", - "de": "Einfügen eure Passwort" + "en": "Put your password (8 characters minimum)", + "fr": "Insérez votre mot de passe (8 caractères minimum)", + "de": "Einfügen eure Passwort (mindestens 8 Zeichen)" }, - "example": "******", + "example": "********", "optional": true }, { diff --git a/scripts/install b/scripts/install index 7808858..066a2a7 100644 --- a/scripts/install +++ b/scripts/install @@ -22,7 +22,8 @@ admin=$YNH_APP_ARG_ADMIN adminpass=$YNH_APP_ARG_ADMINPASS title=$YNH_APP_ARG_TITLE is_public=$YNH_APP_ARG_IS_PUBLIC -final_path=/var/www/$app +www_path=/var/www +final_path=$www_path/$app # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -75,8 +76,7 @@ fi ### Install flarum cwd=$(pwd) sudo su - www-data -s /bin/bash -c "mkdir -p $tmp/$app && cd $tmp/$app && php -d memory_limit=-1 /usr/local/bin/composer create-project flarum/flarum . --stability=beta" -sudo mkdir $final_path -sudo cp -Rfv $tmp/$app $final_path/ +sudo cp -Rf $tmp/$app $www_path/ sudo chown -R www-data:www-data $final_path cd $cwd sudo rm -rf $tmp @@ -131,10 +131,4 @@ sed -i "s@YNH_FORUM_TITLE@$title@g" ../sources/configuration.yml sudo cp ../sources/configuration.yml $final_path sudo su - www-data -s /bin/bash -c "cd $final_path && php -d memory_limit=-1 flarum install -f configuration.yml" sudo rm $final_path/configuration.yml - -# Generate and add root token for user creation and deletion -roottoken=$(ynh_string_random 40) -rootsql="INSERT INTO api_keys VALUES ('"$roottoken"')" -ynh_mysql_execute_as_root "$rootsql" $dbname -ynh_app_setting_set "$app" root_token "$roottoken" fi From 98d664c45d856ac9743f65ea080df3f4196460f3 Mon Sep 17 00:00:00 2001 From: TitusPiJean Date: Thu, 19 Jan 2017 19:39:02 +0100 Subject: [PATCH 03/25] Create root key for api during post-installation --- scripts/install | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/install b/scripts/install index 066a2a7..e1b7684 100644 --- a/scripts/install +++ b/scripts/install @@ -131,4 +131,13 @@ sed -i "s@YNH_FORUM_TITLE@$title@g" ../sources/configuration.yml sudo cp ../sources/configuration.yml $final_path sudo su - www-data -s /bin/bash -c "cd $final_path && php -d memory_limit=-1 flarum install -f configuration.yml" sudo rm $final_path/configuration.yml + +# Generate and add root token for user creation and deletion +roottoken=$(ynh_string_random 40) +apitablesql="CREATE TABLE IF NOT EXISTS api_keys (api_key TEXT(40) NOT NULL UNIQUE)" +rootsql="INSERT INTO api_keys VALUES ('"$roottoken"')" +ynh_mysql_execute_as_root "$apitablesql" $dbname +ynh_mysql_execute_as_root "$rootsql" $dbname +ynh_app_setting_set "$app" root_token "$roottoken" fi + From ff45b2c39b2ad09b5200666897132270e56f81a4 Mon Sep 17 00:00:00 2001 From: TitusPiJean Date: Tue, 21 Feb 2017 21:11:23 +0100 Subject: [PATCH 04/25] SSOwat integration and other improvements Closes #5, closes #12, closes #19 and closes #21 Breaks /folder nginx configuration ? --- conf/nginx.conf | 2 +- conf/nginx_root.conf | 2 +- hooks/post_user_create | 30 ++++++++++++++++++++ manifest.json | 15 ++-------- scripts/install | 64 ++++++++++++++++++++++++++++++++++++++---- 5 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 hooks/post_user_create diff --git a/conf/nginx.conf b/conf/nginx.conf index 53cc3d9..e934ffe 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -56,5 +56,5 @@ location ^~ YNH_WWW_PATH { # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/nginx_root.conf b/conf/nginx_root.conf index 15ab619..23411f6 100644 --- a/conf/nginx_root.conf +++ b/conf/nginx_root.conf @@ -56,5 +56,5 @@ location ^~ / { # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # include conf.d/yunohost_panel.conf.inc; } diff --git a/hooks/post_user_create b/hooks/post_user_create new file mode 100644 index 0000000..368de44 --- /dev/null +++ b/hooks/post_user_create @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Retrieve arguments +username=$1 +app=#APP# + +# Source app helpers +source /usr/share/yunohost/helpers + +domain=$( Date: Wed, 22 Feb 2017 14:28:06 +0000 Subject: [PATCH 05/25] parameter "language" doesn't exist I looked at jenkins to see why the upgrade fails and noticed this language parameter in the upgrade script. There is no trace of this paramater in other scripts so I guess it is a copy/paste from another upgrade script ? :) --- scripts/upgrade | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 4547608..506670d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,6 @@ domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) admin=$(ynh_app_setting_get "$app" admin) is_public=$(ynh_app_setting_get "$app" is_public) -language=$(ynh_app_setting_get "$app" language) # Remove trailing "/" for next commands path=${path%/} From 089da0f41039852beec9f66ed46b49c14d996510 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 14:29:34 +0000 Subject: [PATCH 06/25] Use php-fpm reload instead of restart --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 4547608..dc85e65 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -46,7 +46,7 @@ finalphpconf=/etc/php5/fpm/pool.d/$app.conf sudo cp ../conf/php-fpm.conf $finalphpconf sudo chown root: $finalphpconf sudo chmod 644 $finalphpconf -sudo service php5-fpm restart +sudo service php5-fpm reload ### PHP end ### # If app is public, add url to SSOWat conf as skipped_uris From 3b11c21df49aff73e546661f9c8c109e537e15f5 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 14:33:05 +0000 Subject: [PATCH 07/25] Adjustments on access permissions --- scripts/upgrade | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 4547608..eeb9ba5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,7 +26,8 @@ sudo cp -a ../sources/. $src_path # Set permissions to app files # you may need to make some file and/or directory writeable by www-data (nginx user) -sudo chown -R root: $src_path +sudo chown -R www-data:www-data $src_path +sudo chmod -R 755 $src_path # Modify Nginx configuration file and copy it to Nginx conf directory nginx_conf=../conf/nginx.conf @@ -36,6 +37,7 @@ sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf # sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +sudo chmod 644 /etc/nginx/conf.d/$domain.d/$app.conf ### PHP ### # If a dedicated php-fpm process is used: From 12de58d4a22a73b3a728a90ba4a598f6b38571a7 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 14:41:46 +0000 Subject: [PATCH 08/25] Create .functions --- scripts/.functions | 248 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 scripts/.functions diff --git a/scripts/.functions b/scripts/.functions new file mode 100644 index 0000000..a701564 --- /dev/null +++ b/scripts/.functions @@ -0,0 +1,248 @@ +Skip to content +This repository +Search +Pull requests +Issues +Gist + @polytan02 + Sign out + Unwatch 1 + Star 0 + Fork 6 polytan02/phpmyadmin_ynh +forked from YunoHost-Apps/phpmyadmin_ynh + Code Pull requests 0 Projects 0 Wiki Pulse Graphs Settings +Branch: master Find file Copy pathphpmyadmin_ynh/scripts/.fonctions +1a1a940 8 days ago +@polytan02 polytan02 Update on .fonctions file +1 contributor +RawBlameHistory +Executable File 228 lines (201 sloc) 8.08 KB +#!/bin/bash + +CHECK_VAR () { # Vérifie que la variable n'est pas vide. +# $1 = Variable à vérifier +# $2 = Texte à afficher en cas d'erreur + test -n "$1" || (echo "$2" >&2 && false) +} + +EXIT_PROPERLY () { # Provoque l'arrêt du script en cas d'erreur. Et nettoye les résidus. + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 # Quitte sans erreur si le script se termine correctement. + fi + trap '' EXIT + set +eu + echo -e "\e[91m \e[1m" # Shell in light red bold + echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2 + + if type -t CLEAN_SETUP > /dev/null; then # Vérifie l'existance de la fonction avant de l'exécuter. + CLEAN_SETUP # Appel la fonction de nettoyage spécifique du script install. + fi + + # Compense le bug de ssowat qui ne supprime pas l'entrée de l'app en cas d'erreur d'installation. + sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json + + ynh_die +} + +TRAP_ON () { # Activate signal capture + set -eu # Exit if a command fail, and if a variable is used unset. + trap EXIT_PROPERLY EXIT # Capturing exit signals on shell script +} + +# Ignore the yunohost-cli log to prevent errors with conditionals commands +# usage: NO_LOG COMMAND +# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command +# It's a very badly hack... +# Petite copie perso à mon usage ;) +NO_LOG() { + ynh_cli_log=/var/log/yunohost/yunohost-cli.log + sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move + eval $@ + exit_code=$? + sudo mv ${ynh_cli_log}-move ${ynh_cli_log} + return $? +} + +CHECK_USER () { # Vérifie la validité de l'user admin +# $1 = Variable de l'user admin. + ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false) +} + +CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin. + if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un / + path="/$path" # Ajoute un / en début de path + fi + if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère. + path="${path:0:${#path}-1}" # Supprime le dernier caractère + fi +} + +CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine. + sudo yunohost app checkurl $domain$path -a $app +} + +CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé. + final_path=/var/www/$app + if [ -e "$final_path" ] + then + echo "This path already contains a folder" >&2 + false + fi +} + +GENERATE_DB () { # Créer une base de données et un utilisateur dédié au nom de l'app. +# $1 = Nom de la base de donnée + db_user=$1 + 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 +} + +SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path +# $1 = Nom de l'archive téléchargée. + wget -nv -i ../sources/source_url -O $1 + # Vérifie la somme de contrôle de la source téléchargée. + md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false) + # Décompresse la source + if [ "$(echo ${1##*.})" == "gz" ]; then + tar -x -f $1 + elif [ "$(echo ${1##*.})" == "zip" ]; then + unzip -q $1 + else + false # Format d'archive non pris en charge. + fi + # Copie les fichiers sources + sudo cp -a $(cat ../sources/source_dir)/. "$final_path" + # Copie les fichiers additionnels ou modifiés. + if test -e "../sources/ajouts"; then + sudo cp -a ../sources/ajouts/. "$final_path" + fi +} + +ADD_SYS_USER () { # Créer un utilisateur système dédié à l'app + if ! ynh_system_user_exists "$app" # Test l'existence de l'utilisateur + then + sudo useradd -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin || (echo "Unable to create $app system account" >&2 && false) + fi +} + +POOL_FPM () { # Créer le fichier de configuration du pool php-fpm et le configure. + sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf + sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf + sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf + finalphpconf=/etc/php5/fpm/pool.d/$app.conf + sudo cp ../conf/php-fpm.conf $finalphpconf + sudo chown root: $finalphpconf + finalphpini=/etc/php5/fpm/conf.d/20-$app.ini + sudo cp ../conf/php-fpm.ini $finalphpini + sudo chown root: $finalphpini + sudo service php5-fpm reload +} + +STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config +# $1 = Nom du fichier de conf pour le stockage dans settings.yml +# $2 = Nom complet et chemin du fichier de conf. + ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1) +} + +CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié. +# $1 = Nom du fichier de conf pour le stockage dans settings.yml +# $2 = Nom complet et chemin du fichier de conf. + if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then + sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup. + fi +} + +FIND_PORT () { # Cherche un port libre. +# $1 = Numéro de port pour débuter la recherche. + port=$1 + while ! sudo yunohost app checkport $port ; do + port=$((port+1)) + done + CHECK_VAR "$port" "port empty" +} + + +### REMOVE SCRIPT + +REMOVE_NGINX_CONF () { # Suppression de la configuration nginx + if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config + echo "Delete nginx config" + sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" +# sudo service nginx reload + fi +} + +REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm + if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config + echo "Delete fpm config" + sudo rm "/etc/php5/fpm/pool.d/$app.conf" + fi + if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config + echo "Delete php config" + sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" + fi +# sudo service php5-fpm reload +} + +REMOVE_LOGROTATE_CONF () { # Suppression de la configuration de logrotate + if [ -e "/etc/logrotate.d/$app" ]; then + echo "Delete logrotate config" + sudo rm "/etc/logrotate.d/$app" + fi +} + +SECURE_REMOVE () { # Suppression de dossier avec vérification des variables + chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables. + no_var=0 + while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine + do + no_var=1 + global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée. + only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière. + real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable. + if test -z "$real_var" || [ "$real_var" = "/" ]; then + echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2 + return 1 + fi + chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine. + done + if [ "$no_var" -eq 1 ] + then + if [ -e "$chaine" ]; then + echo "Delete directory $chaine" + sudo rm -r "$chaine" + fi + return 0 + else + echo "No detected variable." >&2 + return 1 + fi +} + +REMOVE_BDD () { # Suppression de la base de donnée et de l'utilisateur associé. +# $1 = Nom de la base de donnée + # Utilise '$app' comme nom d'utilisateur et de base de donnée + db_user=$1 + if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then + echo "Delete db" + ynh_mysql_drop_db $db_user + ynh_mysql_drop_user $db_user + fi +} + +REMOVE_SYS_USER () { # Supprime l'utilisateur système dédié à l'app + if ynh_system_user_exists "$app" # Test l'existence de l'utilisateur + then + sudo userdel $app + fi +} +Contact GitHub API Training Shop Blog About +© 2017 GitHub, Inc. Terms Privacy Security Status Help From a3707289af6ed248bb0fc1ac92c1c13a0e7a9f6f Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 14:47:46 +0000 Subject: [PATCH 09/25] Use of extra helpers Make sure $path is correct (the {YNH_PATH%/} doesn't work in every cases --- scripts/install | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 837b0fd..eb8f389 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,10 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +# Load extra functions +source .fonctions + +# Activate TRAP to stop the script if an error is detected +TRAP_ON # This is a multi-instance app, meaning it can be installed several times independently # The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -17,7 +20,7 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=${YNH_APP_ARG_PATH%/} +path=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN title=$YNH_APP_ARG_TITLE is_public=$YNH_APP_ARG_IS_PUBLIC @@ -27,14 +30,27 @@ final_path=$www_path/$app # Source YunoHost helpers$ source /usr/share/yunohost/helpers +# Check variables are not empty +CHECK_VAR "$app" "app name not set" + +# Check validity of admin user +CHECK_USER "$admin" + +# Check and correct path syntax +CHECK_PATH + +# Check availibility of path and domain +CHECK_DOMAINPATH + # Save app settings ynh_app_setting_set "$app" admin "$admin" ynh_app_setting_set "$app" is_public "$is_public" ynh_app_setting_set "$app" path "$path" -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" + +# Check final_path availibility. Installation stops if it already exists +CHECK_FINALPATH +sudo mkdir "$final_path" tmp=/tmp/flaruminstall sudo rm -rf $tmp From 08a6dfc92abe0fa8cea7ed3b69fa1db00049c202 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 14:56:18 +0000 Subject: [PATCH 10/25] Store composer in /opt No need to "hide" composer in /var/www/.composer ==> You can place it in /opt for example Easier to remember and to clean afterwards. Other adjustments may be required in your script ! --- scripts/install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 837b0fd..94680c8 100644 --- a/scripts/install +++ b/scripts/install @@ -43,9 +43,9 @@ sudo chown -R www-data:www-data $tmp sudo chmod -R 755 $tmp # Prepare composer and cache directories -sudo mkdir -p /var/www/.composer/cache -sudo chown -R www-data:www-data /var/www/.composer -sudo chmod -R 755 /var/www/.composer +sudo mkdir -p /opt/flarum_composer/cache +sudo chown -R www-data:www-data /opt/flarum_composer +sudo chmod -R 755 /opt/flarum_composer ### composer ### if ! type "composer" > /dev/null; then @@ -55,7 +55,7 @@ if ! type "composer" > /dev/null; then ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', '$tmp/composer-setup.php');") if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ] then - sudo su - root -c "grep -q -F 'env[COMPOSER_HOME]= /var/www/.composer' /etc/php5/fpm/php-fpm.conf || sudo echo 'env[COMPOSER_HOME]= /var/www/.composer' >> /etc/php5/fpm/php-fpm.conf" + sudo su - root -c "grep -q -F 'env[COMPOSER_HOME]= /opt/flarum_composer' /etc/php5/fpm/php-fpm.conf || sudo echo 'env[COMPOSER_HOME]= /opt/flarum_composer' >> /etc/php5/fpm/php-fpm.conf" sudo service php5-fpm reload sudo su - www-data -s /bin/bash -c "php $tmp/composer-setup.php --install-dir=$tmp --filename=composer" sudo mv $tmp/composer /usr/local/bin From b093b2e1b5ce42da25713023af3e9ddd77143c93 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 14:57:58 +0000 Subject: [PATCH 11/25] Remove composer as well --- scripts/remove | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/remove b/scripts/remove index e073f51..aae75d6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,8 @@ domain=$(ynh_app_setting_get "$app" domain) # Remove sources sudo rm -rf /tmp/composerinstall sudo rm -rf /var/www/$app +sudo rm -rf /opt/flarum_composer +sudo rm -rf /usr/local/bin/composer # Remove nginx configuration file sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf From 676fac82f3c88754c948f407a06a86adfa9e15aa Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 15:21:27 +0000 Subject: [PATCH 12/25] Update backup --- scripts/backup | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/backup b/scripts/backup index 575a599..f162882 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,6 +13,12 @@ source /usr/share/yunohost/helpers # Note: the last argument is where to save this path, see the restore script. ynh_backup "/var/www/${app}" "sources" +# Backup of composer +# +# TO BE VALIDATED AND TESTED +ynh_backup "/opt/flarum_composer" "flarum_composer" +ynh_backup "/usr/local/bin/composerr" "local_composer" + ### MySQL ### # If a MySQL database is used: # # Dump the database From f12a568a3179511ebf6244f8a5a49d474676c60f Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 15:23:34 +0000 Subject: [PATCH 13/25] Update restore --- scripts/restore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/restore b/scripts/restore index 2f532ee..23c300f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -24,6 +24,13 @@ sudo yunohost app checkurl "${domain}${path}" -a "$app" \ src_path="/var/www/${app}" sudo cp -a ./sources "$src_path" +# Restore composer +# +# TO BE TESTED AND VALIDATED +# +cp -a ./flarum_composer /opt/flarum_composer +cp -a ./local_composer /usr/local/bin/composer + # Restore permissions to app files # you may need to make some file and/or directory writeable by www-data (nginx user) sudo chown -R root: "$src_path" From ee9bcedbe02869da07e97f9ce70bec8bfabf4c96 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 15:24:00 +0000 Subject: [PATCH 14/25] Typo --- scripts/backup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup b/scripts/backup index f162882..5c5bc81 100644 --- a/scripts/backup +++ b/scripts/backup @@ -17,7 +17,7 @@ ynh_backup "/var/www/${app}" "sources" # # TO BE VALIDATED AND TESTED ynh_backup "/opt/flarum_composer" "flarum_composer" -ynh_backup "/usr/local/bin/composerr" "local_composer" +ynh_backup "/usr/local/bin/composer" "local_composer" ### MySQL ### # If a MySQL database is used: From bb025b1255f40cf96494e6eb5aca652686c2c9e6 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 15:50:16 +0000 Subject: [PATCH 15/25] path is / for root --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index eb8f389..c4ca3bf 100644 --- a/scripts/install +++ b/scripts/install @@ -105,7 +105,7 @@ ynh_app_setting_set "$app" mysqlpwd "$dbpass" ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ### Nginx ### -if [ $path = "" ]; then +if [ $path = "/" ]; then nginx_conf=../conf/nginx_root.conf else nginx_conf=../conf/nginx.conf From 4a5717daa3254735ce5fad96fe8fa0512ecd9eae Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 15:51:47 +0000 Subject: [PATCH 16/25] Adjust upgrade to path variable --- scripts/upgrade | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 4547608..b6c6395 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -3,6 +3,8 @@ # Exit on command errors and treat unset variables as an error set -eu +source .functions + # See comments in install script app=$YNH_APP_INSTANCE_NAME @@ -16,8 +18,8 @@ admin=$(ynh_app_setting_get "$app" admin) is_public=$(ynh_app_setting_get "$app" is_public) language=$(ynh_app_setting_get "$app" language) -# Remove trailing "/" for next commands -path=${path%/} +# Check path and correct if required +CHECK_PATH # Copy source files src_path=/var/www/$app @@ -29,9 +31,17 @@ sudo cp -a ../sources/. $src_path sudo chown -R root: $src_path # Modify Nginx configuration file and copy it to Nginx conf directory +### Nginx ### +if [ $path = "/" ]; then +nginx_conf=../conf/nginx_root.conf +else nginx_conf=../conf/nginx.conf +fi sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf -sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf +sed -i "s@YNH_WWW_ALIAS@$app/@g" $nginx_conf +sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf +sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf + # If a dedicated php-fpm process is used: # sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf From 3e4bbc7de65177eccd75827943731d45b52887b6 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 17:05:27 +0000 Subject: [PATCH 17/25] Update nginx.conf to have only one file --- conf/nginx.conf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index e934ffe..612163b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,13 +1,13 @@ location ^~ YNH_WWW_PATH { - root /var/www; - try_files $uri $uri/ /YNH_WWW_APP/index.php?$query_string; - index /YNH_WWW_APP/index.php; + alias YNH_WWW_FINALPATH/ ; + try_files $uri $uri/ /YNH_WWW_ROOTAPP/index.php?$query_string; + index /YNH_WWW_ROOTAPP/index.php; - location YNH_WWW_PATH/ { try_files $uri $uri/ /YNH_WWW_APP/index.php?$query_string; } - location YNH_WWW_PATH/api { try_files $uri $uri/ /YNH_WWW_APP/api.php?$query_string; } - location YNH_WWW_PATH/admin { try_files $uri $uri/ /YNH_WWW_APP/admin.php?$query_string; } + location YNH_WWW_ROOTPATH/ { try_files $uri $uri/ /YNH_WWW_ROOTAPP/index.php?$query_string; } + location YNH_WWW_ROOTPATH/api { try_files $uri $uri/ /YNH_WWW_ROOTAPP/api.php?$query_string; } + location YNH_WWW_ROOTPATH/admin { try_files $uri $uri/ /YNH_WWW_ROOTAPP/admin.php?$query_string; } - location YNH_WWW_PATH/flarum { + location YNH_WWW_ROOTPATH/flarum { deny all; return 404; } From b1ae7f973e17116d3f1261824b08f3d6d50bf565 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 17:07:41 +0000 Subject: [PATCH 18/25] Delete nginx_root.conf --- conf/nginx_root.conf | 60 -------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 conf/nginx_root.conf diff --git a/conf/nginx_root.conf b/conf/nginx_root.conf deleted file mode 100644 index 23411f6..0000000 --- a/conf/nginx_root.conf +++ /dev/null @@ -1,60 +0,0 @@ -root /var/www/YNH_WWW_APP; -location ^~ / { - try_files $uri $uri/ /index.php?$query_string; - index /index.php; - - location / { try_files $uri $uri/ /index.php?$query_string; } - location /api { try_files $uri $uri/ /api.php?$query_string; } - location /admin { try_files $uri $uri/ /admin.php?$query_string; } - - location /flarum { - deny all; - return 404; - } - - location ~* \.php$ { - fastcgi_split_path_info ^(.+.php)(/.+)$; - fastcgi_pass unix:/var/run/php5-fpm-YNH_WWW_APP.sock; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability - fastcgi_index index.php; - fastcgi_read_timeout 600; - } - - location ~* \.html$ { - expires -1; - } - - location ~* \.(css|js|gif|jpe?g|png)$ { - expires 1M; - add_header Pragma public; - add_header Cache-Control "public, must-revalidate, proxy-revalidate"; - } - - gzip on; - gzip_http_version 1.1; - gzip_vary on; - gzip_comp_level 6; - gzip_proxied any; - gzip_types application/atom+xml - application/javascript - application/json - application/vnd.ms-fontobject - application/x-font-ttf - application/x-web-app-manifest+json - application/xhtml+xml - application/xml - font/opentype - image/svg+xml - image/x-icon - text/css - text/plain - text/xml; - gzip_buffers 16 8k; - gzip_disable "MSIE [1-6]\.(?!.*SV1)"; - - - # Include SSOWAT user panel. - # include conf.d/yunohost_panel.conf.inc; -} From 0c751243d93456323278ddbd712bd95d9e57cba4 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Wed, 22 Feb 2017 17:08:55 +0000 Subject: [PATCH 19/25] Update to nginx section --- scripts/install | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/install b/scripts/install index 837b0fd..eed6289 100644 --- a/scripts/install +++ b/scripts/install @@ -89,14 +89,16 @@ ynh_app_setting_set "$app" mysqlpwd "$dbpass" ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ### Nginx ### -if [ $path = "" ]; then -nginx_conf=../conf/nginx_root.conf +nginxconf="../conf/nginx.conf" +if [ $path = "/" ]; then + sed -i "s@YNH_WWW_ROOTPATH@@g" ../conf/nginx.conf + sed -i "s@/YNH_WWW_ROOTAPP@@g" ../conf/nginx.conf else -nginx_conf=../conf/nginx.conf + sed -i "s@YNH_WWW_ROOTPATH@$path@g" ../conf/nginx.conf + sed -i "s@YNH_WWW_ROOTAPP@$app@g" ../conf/nginx.conf fi sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf -sed -i "s@YNH_WWW_ALIAS@$app/@g" $nginx_conf -sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf +sed -i "s@YNH_WWW_FINALPATH@$final_path@g" $nginx_conf sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf ### PHP ### From 3b632a12264ff7bd68ba22f46c39c28002da7550 Mon Sep 17 00:00:00 2001 From: Titus PiJean Date: Wed, 22 Feb 2017 18:21:36 +0100 Subject: [PATCH 20/25] Update .functions Copy/paste clean up --- scripts/.functions | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/scripts/.functions b/scripts/.functions index a701564..2eaaa56 100644 --- a/scripts/.functions +++ b/scripts/.functions @@ -1,22 +1,3 @@ -Skip to content -This repository -Search -Pull requests -Issues -Gist - @polytan02 - Sign out - Unwatch 1 - Star 0 - Fork 6 polytan02/phpmyadmin_ynh -forked from YunoHost-Apps/phpmyadmin_ynh - Code Pull requests 0 Projects 0 Wiki Pulse Graphs Settings -Branch: master Find file Copy pathphpmyadmin_ynh/scripts/.fonctions -1a1a940 8 days ago -@polytan02 polytan02 Update on .fonctions file -1 contributor -RawBlameHistory -Executable File 228 lines (201 sloc) 8.08 KB #!/bin/bash CHECK_VAR () { # Vérifie que la variable n'est pas vide. @@ -244,5 +225,3 @@ REMOVE_SYS_USER () { # Supprime l'utilisateur système dédié à l'app sudo userdel $app fi } -Contact GitHub API Training Shop Blog About -© 2017 GitHub, Inc. Terms Privacy Security Status Help From a7d162ca06acb498f32a0c3fb22e1875a3b158db Mon Sep 17 00:00:00 2001 From: Titus PiJean Date: Wed, 22 Feb 2017 18:24:42 +0100 Subject: [PATCH 21/25] Update install Frenchie typo --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c4ca3bf..67a6de5 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,7 @@ #!/bin/bash # Load extra functions -source .fonctions +source .functions # Activate TRAP to stop the script if an error is detected TRAP_ON From 07a8120a386b88911dfe909f154ae3118c68cf7d Mon Sep 17 00:00:00 2001 From: Titus PiJean Date: Wed, 22 Feb 2017 18:33:07 +0100 Subject: [PATCH 22/25] Fix $nginx_conf -> $nginxconf --- scripts/install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index eed6289..bcecbce 100644 --- a/scripts/install +++ b/scripts/install @@ -97,9 +97,9 @@ else sed -i "s@YNH_WWW_ROOTPATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_WWW_ROOTAPP@$app@g" ../conf/nginx.conf fi -sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf -sed -i "s@YNH_WWW_FINALPATH@$final_path@g" $nginx_conf -sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +sed -i "s@YNH_WWW_PATH@$path@g" $nginxconf +sed -i "s@YNH_WWW_FINALPATH@$final_path@g" $nginxconf +sudo cp $nginxconf /etc/nginx/conf.d/$domain.d/$app.conf ### PHP ### sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf From dd43f8e27a13d7c5062192abb64f187e36f14787 Mon Sep 17 00:00:00 2001 From: Titus PiJean Date: Wed, 22 Feb 2017 18:40:55 +0100 Subject: [PATCH 23/25] Fix socket dummy variable name --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 612163b..7114064 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -14,7 +14,7 @@ location ^~ YNH_WWW_PATH { location ~* \.php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; - fastcgi_pass unix:/var/run/php5-fpm-YNH_WWW_APP.sock; + fastcgi_pass unix:/var/run/php5-fpm-YNH_WWW_ROOTAPP.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability From 3492031818963fc3439cc1a8a65ab3898b6180cf Mon Sep 17 00:00:00 2001 From: Titus PiJean Date: Wed, 22 Feb 2017 18:53:47 +0100 Subject: [PATCH 24/25] Fix PHP SCRIPT_FILENAME --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 7114064..87ee77e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,7 +16,7 @@ location ^~ YNH_WWW_PATH { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm-YNH_WWW_ROOTAPP.sock; include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability fastcgi_index index.php; fastcgi_read_timeout 600; From 429aa6182a952134d8ad785b7e39454176e9f5e6 Mon Sep 17 00:00:00 2001 From: Titus PiJean Date: Wed, 22 Feb 2017 19:06:03 +0100 Subject: [PATCH 25/25] Update nginx conf in upgrade After #30 --- scripts/upgrade | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 27057af..f7b8fbb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -33,14 +33,17 @@ sudo chmod -R 755 $src_path # Modify Nginx configuration file and copy it to Nginx conf directory ### Nginx ### if [ $path = "/" ]; then -nginx_conf=../conf/nginx_root.conf +nginxconf="../conf/nginx.conf" +if [ $path = "/" ]; then + sed -i "s@YNH_WWW_ROOTPATH@@g" ../conf/nginx.conf + sed -i "s@/YNH_WWW_ROOTAPP@@g" ../conf/nginx.conf else -nginx_conf=../conf/nginx.conf + sed -i "s@YNH_WWW_ROOTPATH@$path@g" ../conf/nginx.conf + sed -i "s@YNH_WWW_ROOTAPP@$app@g" ../conf/nginx.conf fi -sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf -sed -i "s@YNH_WWW_ALIAS@$app/@g" $nginx_conf -sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf -sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +sed -i "s@YNH_WWW_PATH@$path@g" $nginxconf +sed -i "s@YNH_WWW_FINALPATH@$final_path@g" $nginxconf +sudo cp $nginxconf /etc/nginx/conf.d/$domain.d/$app.conf # If a dedicated php-fpm process is used: #