mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
parent
41f591ccb2
commit
370684f92d
5 changed files with 338 additions and 357 deletions
|
@ -1,227 +0,0 @@
|
||||||
#!/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.
|
|
||||||
ynh_webpath_register $app $domain $path
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
|
@ -1,38 +1,79 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# See comments in install script
|
if [ ! -e _common.sh ]; then
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
# Get the _common.sh file if it's not in the current directory
|
||||||
|
cp ../settings/scripts/_common.sh ./_common.sh
|
||||||
# Source YunoHost helpers
|
chmod a+rx _common.sh
|
||||||
|
fi
|
||||||
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Backup sources & data
|
#=================================================
|
||||||
# Note: the last argument is where to save this path, see the restore script.
|
# MANAGE SCRIPT FAILURE
|
||||||
ynh_backup "/var/www/${app}" "sources"
|
#=================================================
|
||||||
|
|
||||||
# Backup of composer
|
# Exit if an error occurs during the execution of the script
|
||||||
#
|
ynh_abort_if_errors
|
||||||
# TO BE VALIDATED AND TESTED
|
|
||||||
ynh_backup "/opt/${app}_composer" "flarum_composer"
|
|
||||||
|
|
||||||
### MySQL ###
|
#=================================================
|
||||||
# If a MySQL database is used:
|
# LOAD SETTINGS
|
||||||
# # Dump the database
|
#=================================================
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
|
||||||
### MySQL end ###
|
|
||||||
|
|
||||||
# Copy NGINX configuration
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
|
||||||
|
|
||||||
### PHP (remove if not used) ###
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
# If a dedicated php-fpm process is used:
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
# # Copy PHP-FPM pool configuration
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
|
|
||||||
### PHP end ###
|
#=================================================
|
||||||
|
# STANDARD BACKUP STEPS
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
|
||||||
|
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_mysql_dump_db "$db_name" > db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC BACKUP
|
||||||
|
#=================================================
|
||||||
|
# BACKUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/systemd/system/$app.service"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/cron.d/$app"
|
||||||
|
|
|
@ -67,6 +67,7 @@ ynh_app_setting_set $app path $path_url
|
||||||
ynh_app_setting_set $app admin $admin
|
ynh_app_setting_set $app admin $admin
|
||||||
ynh_app_setting_set $app is_public $is_public
|
ynh_app_setting_set $app is_public $is_public
|
||||||
ynh_app_setting_set $app final_path $final_path
|
ynh_app_setting_set $app final_path $final_path
|
||||||
|
ynh_app_setting_set $app flarum_version $flarum_version
|
||||||
|
|
||||||
#===================================================
|
#===================================================
|
||||||
# CREATE DEDICATED USER
|
# CREATE DEDICATED USER
|
||||||
|
|
156
scripts/restore
156
scripts/restore
|
@ -1,59 +1,123 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Note: each files and directories you've saved using the ynh_backup helper
|
#=================================================
|
||||||
# will be located in the current directory, regarding the last argument.
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
source _common.sh
|
||||||
set -eu
|
|
||||||
|
|
||||||
# See comments in install script
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
|
|
||||||
# Source YunoHost helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Retrieve old app settings
|
#=================================================
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
# MANAGE SCRIPT FAILURE
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
#=================================================
|
||||||
|
|
||||||
# Check domain/path availability
|
# Exit if an error occurs during the execution of the script
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
ynh_abort_if_errors
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|
||||||
|
|
||||||
# Restore sources & data
|
#=================================================
|
||||||
src_path="/var/www/${app}"
|
# LOAD SETTINGS
|
||||||
sudo cp -a ./sources "$src_path"
|
#=================================================
|
||||||
|
|
||||||
# Restore composer
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
#
|
|
||||||
# TO BE TESTED AND VALIDATED
|
|
||||||
#
|
|
||||||
cp -a ./flarum_composer /opt/${app}_composer
|
|
||||||
#cp -a ./local_composer /usr/local/bin/composer
|
|
||||||
|
|
||||||
# Restore permissions to app files
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
sudo chown -R root: "$src_path"
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
### MySQL ###
|
#=================================================
|
||||||
# If a MySQL database is used:
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
# # Create and restore the database
|
#=================================================
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
||||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
|
||||||
### MySQL end ###
|
|
||||||
|
|
||||||
# Restore NGINX configuration
|
ynh_webpath_available $domain $path_url \
|
||||||
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
|
test ! -d $final_path \
|
||||||
|
|| ynh_die "There is already a directory: $final_path "
|
||||||
|
|
||||||
### PHP ###
|
#=================================================
|
||||||
# If a dedicated php-fpm process is used:
|
# STANDARD RESTORATION STEPS
|
||||||
# # Copy PHP-FPM pool configuration and reload the service
|
#=================================================
|
||||||
sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf"
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
sudo service php5-fpm reload
|
#=================================================
|
||||||
### PHP end ###
|
|
||||||
|
|
||||||
# Restart webserver
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
sudo service nginx reload
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||||
|
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
||||||
|
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RECREATE THE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create the dedicated user (if not existing)
|
||||||
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE USER RIGHTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Restore permissions on app files
|
||||||
|
chown -R root: $final_path
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
|
||||||
|
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC RESTORATION
|
||||||
|
#=================================================
|
||||||
|
# REINSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Define and install dependencies
|
||||||
|
ynh_install_app_dependencies deb1 deb2
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
yunohost service add $app --log "/var/log/$app/APP.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
||||||
|
systemctl enable $app.service
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX AND PHP-FPM
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload php5-fpm
|
||||||
|
systemctl reload nginx
|
||||||
|
|
212
scripts/upgrade
212
scripts/upgrade
|
@ -1,70 +1,135 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
source .functions
|
source _common.sh
|
||||||
|
|
||||||
# See comments in install script
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
|
|
||||||
# Source YunoHost helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#===================================================
|
||||||
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
|
#===================================================
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||||
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||||
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||||
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||||
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||||
|
# The app instance name is probably what you are interested the most, since this is
|
||||||
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||||
|
# db names, ...
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve app settings
|
# Retrieve app settings
|
||||||
|
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
path_url=$(ynh_app_setting_get "$app" path)
|
||||||
admin=$(ynh_app_setting_get "$app" admin)
|
admin=$(ynh_app_setting_get "$app" admin)
|
||||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||||
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
db_pwd=$(ynh_app_setting_get $app db_pwd)
|
||||||
|
old_flarum_version=$(ynh_app_setting_get "$app" flarum_version)
|
||||||
|
flarum_version="v0.1.0-beta.7"
|
||||||
|
|
||||||
# Check path and correct if required
|
#=================================================
|
||||||
CHECK_PATH
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Copy source files
|
# Fix is_public as a boolean value
|
||||||
#src_path=/var/www/$app
|
if [ "$is_public" = "Yes" ]; then
|
||||||
#sudo mkdir -p $src_path
|
ynh_app_setting_set $app is_public 1
|
||||||
#sudo cp -a ../sources/. $src_path
|
is_public=1
|
||||||
|
elif [ "$is_public" = "No" ]; then
|
||||||
# Update flarum
|
ynh_app_setting_set $app is_public 0
|
||||||
sudo su - www-data -s /bin/bash -c "cd /var/www/${app} && composer update"
|
is_public=0
|
||||||
|
|
||||||
# Set permissions to app files
|
|
||||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
|
||||||
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 ###
|
|
||||||
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
|
|
||||||
sed -i "s@YNH_WWW_ROOTPATH@$path@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@YNH_WWW_ROOTAPP@$path$path@g" ../conf/nginx.conf
|
|
||||||
fi
|
fi
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginxconf
|
|
||||||
sed -i "s@YNH_WWW_FINALPATH@$final_path@g" $nginxconf
|
|
||||||
sed -i "s@YNH_WWW_APP@$final_path@g" $nginxconf
|
|
||||||
sudo cp $nginxconf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used:
|
# If db_name doesn't exist, create it
|
||||||
#
|
if [ -z $db_name ]; then
|
||||||
sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
|
db_name=$(ynh_sanitize_dbid $app)
|
||||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
ynh_app_setting_set $app db_name $db_name
|
||||||
sudo chmod 644 /etc/nginx/conf.d/$domain.d/$app.conf
|
fi
|
||||||
|
|
||||||
### PHP ###
|
# If final_path doesn't exist, create it
|
||||||
# If a dedicated php-fpm process is used:
|
if [ -z $final_path ]; then
|
||||||
# # Modify PHP-FPM pool configuration and copy it to the pool directory
|
final_path=/var/www/$app
|
||||||
sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
|
ynh_app_setting_set $app final_path $final_path
|
||||||
sed -i "s@YNH_WWW_ALIAS@$final_path@g" ../conf/php-fpm.conf
|
fi
|
||||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
|
||||||
sudo cp ../conf/php-fpm.conf $finalphpconf
|
#=================================================
|
||||||
sudo chown root: $finalphpconf
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
sudo chmod 644 $finalphpconf
|
#=================================================
|
||||||
sudo service php5-fpm reload
|
|
||||||
### PHP end ###
|
# Backup the current version of the app
|
||||||
|
ynh_backup_before_upgrade
|
||||||
|
ynh_clean_setup () {
|
||||||
|
# restore it if the upgrade fails
|
||||||
|
ynh_restore_upgradebackup
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK THE PATH
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Normalize the URL path syntax
|
||||||
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD UPGRADE STEPS
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# COMPOSER UPGRADE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if ! type "$final_path/composer" > /dev/null; then
|
||||||
|
init_composer $app $final_path
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# FLARUM UPGRADE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Install Flarum
|
||||||
|
exec_composer $app $final_path "update --ansi"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated php-fpm config
|
||||||
|
ynh_add_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC UPGRADE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# If app is public, add url to SSOWat conf as skipped_uris
|
# If app is public, add url to SSOWat conf as skipped_uris
|
||||||
if [[ $is_public -eq 1 ]]; then
|
if [[ $is_public -eq 1 ]]; then
|
||||||
|
@ -72,5 +137,42 @@ if [[ $is_public -eq 1 ]]; then
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload nginx service
|
#=================================================
|
||||||
sudo service nginx reload
|
# SETUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Use logrotate to manage app-specific logfile(s)
|
||||||
|
ynh_use_logrotate --non-append
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Set right permissions
|
||||||
|
chown -R $app:www-data $final_path
|
||||||
|
sudo chmod -R 0775 $final_path
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if [ $is_public -eq 0 ]
|
||||||
|
then # Remove the public access
|
||||||
|
ynh_app_setting_delete $app skipped_uris
|
||||||
|
fi
|
||||||
|
# Make app public if necessary
|
||||||
|
if [ $is_public -eq 1 ]
|
||||||
|
then
|
||||||
|
# unprotected_uris allows SSO credentials to be passed anyway
|
||||||
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
|
||||||
|
ynh_app_setting_set $app flarum_version $flarum_version
|
||||||
|
|
Loading…
Add table
Reference in a new issue