From 56f37e362e53671d878302df2d31ef6761865564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 30 Apr 2016 23:03:03 +0200 Subject: [PATCH] [enh] Update scripts for YunoHost changes in multi-instances apps --- manifest.json | 5 ++++- scripts/backup | 22 +++++++++++----------- scripts/install | 43 +++++++++++++++++++++++-------------------- scripts/remove | 13 +++++++++---- scripts/restore | 20 +++++++++++--------- scripts/upgrade | 43 ++++++++++++++++++++++--------------------- 6 files changed, 80 insertions(+), 66 deletions(-) diff --git a/manifest.json b/manifest.json index 30fc784..58bcdfd 100644 --- a/manifest.json +++ b/manifest.json @@ -11,7 +11,10 @@ "name": "titoko", "email": "titoko@titoko.fr" }, - "multi_instance": "true", + "multi_instance": true, + "requirements": { + "yunohost": ">= 2.3.14" + }, "services": [ "nginx", "php5-fpm", diff --git a/scripts/backup b/scripts/backup index fa6583b..794238a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,15 +1,15 @@ #!/bin/bash -app=jappix -# The parameter $1 is the backup directory location -# which will be compressed afterward -backup_dir=$1/apps/$app -mkdir -p $backup_dir +app=${!#} -# Backup sources & data -sudo cp -a /var/www/$app/. $backup_dir/sources +# Retrieve arguments +backup_dir=$1 -# Copy Nginx and YunoHost parameters to make the script "standalone" -sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost -domain=$(sudo yunohost app setting $app domain) -sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $backup_dir/nginx.conf \ No newline at end of file +# Retrieve app settings +domain=$(sudo yunohost app setting "$app" domain) + +# Save sources & data +sudo cp -a "/var/www/${app}" ./sources + +# Copy NGINX configuration +sudo cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./nginx.conf diff --git a/scripts/install b/scripts/install index e97ce97..d61db8a 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,11 @@ #!/bin/bash +set -e + source ./_common.sh +app=${!#} + # Retrieve arguments domain=$1 path=$2 @@ -9,7 +13,7 @@ name=$3 language=$4 # Check domain/path availability -sudo yunohost app checkurl $domain$path -a jappix +sudo yunohost app checkurl "${domain}${path}" -a "$app" if [[ ! $? -eq 0 ]]; then exit 1 fi @@ -21,16 +25,16 @@ path=${path%/} wget -nv -O jappix.tar.gz https://github.com/jappix/jappix/archive/${VERSION}.tar.gz # Copy files to the right place -final_path=/var/www/jappix -sudo mkdir -p $final_path -sudo tar -C $final_path -xf jappix.tar.gz --strip-components 1 -sudo cp ../conf/*.xml $final_path/store/conf/ +final_path="/var/www/${app}" +sudo mkdir -p "${final_path}/store/conf" +sudo tar -C "$final_path" -xf jappix.tar.gz --strip-components 1 +sudo cp ../conf/*.xml "${final_path}/store/conf/" # Set permissions to jappix directory -sudo chown -R www-data: $final_path +sudo chown -R www-data: "$final_path" # Modify Nginx configuration file and copy it to Nginx conf directory -sudo sed -i "s@PATHTOCHANGE2@$path@g" ../conf/nginx.conf +sudo sed -i "s@PATHTOCHANGE2@${path}@g" ../conf/nginx.conf if [ -z "$path" ]; then path="/" @@ -42,19 +46,18 @@ then language="en" fi -sudo yunohost app setting jappix name -v $name -sudo yunohost app setting jappix language -v $language +sudo yunohost app setting "$app" name -v "$name" +sudo yunohost app setting "$app" language -v "$language" -sudo sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf -sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/jappix.conf -sudo sed -i "s@PATHTOCHANGE@$path@g" $final_path/store/conf/main.xml -sudo sed -i "s@PATHTOCHANGE@$path@g" $final_path/store/conf/hosts.xml -sudo sed -i "s@DOMAINTOCHANGE@$domain@g" $final_path/store/conf/main.xml -sudo sed -i "s@CHANGELANG@$language@g" $final_path/store/conf/main.xml -sudo sed -i "s@CHANGENAME@$name@g" $final_path/store/conf/main.xml -sudo sed -i "s@DOMAINTOCHANGE@$domain@g" $final_path/store/conf/hosts.xml +sudo sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf +sudo sed -i "s@ALIASTOCHANGE@${final_path}/@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/hosts.xml" +sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@CHANGELANG@${language}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@CHANGENAME@${name}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/hosts.xml" -# Reload Nginx and regenerate SSOwat conf +# Reload services sudo service nginx reload -sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index e4d284f..a3cb6a6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,8 +1,13 @@ #!/bin/bash -domain=$(sudo yunohost app setting jappix domain) -sudo rm -rf /var/www/jappix -sudo rm -f /etc/nginx/conf.d/$domain.d/jappix.conf +app=${!#} +# Retrieve arguments +domain=$(sudo yunohost app setting "$app" domain) + +# Remove sources and configuration +sudo rm -rf "/var/www/${app}" +sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" + +# Reload services sudo service nginx reload -sudo yunohost app ssowatconf diff --git a/scripts/restore b/scripts/restore index c5ff657..660458a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,16 +1,18 @@ #!/bin/bash -app=jappix -# The parameter $1 is the uncompressed restore directory location -backup_dir=$1/apps/$app +app=${!#} + +# Retrieve arguments +backup_dir=$1 + +# Retrieve old app settings +domain=$(sudo yunohost app setting "$app" domain) # Restore sources & data -sudo cp -a $backup_dir/sources/. /var/www/$app +sudo cp -a ./sources "/var/www/${app}" # Restore Nginx and YunoHost parameters -sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app -domain=$(sudo yunohost app setting $app domain) -sudo cp -a $backup_dir/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" -# Restart webserver -sudo service nginx reload \ No newline at end of file +# Reload services +sudo service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade index 184e93e..12c3c95 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -2,11 +2,13 @@ source ./_common.sh +app=${!#} + # Retrieve arguments -domain=$(sudo yunohost app setting jappix domain) -path=$(sudo yunohost app setting jappix path) -name=$(sudo yunohost app setting jappix name) -language=$(sudo yunohost app setting jappix language) +domain=$(sudo yunohost app setting "$app" domain) +path=$(sudo yunohost app setting "$app" path) +name=$(sudo yunohost app setting "$app" name) +language=$(sudo yunohost app setting "$app" language) if [[ "$name" = "" ]]; then @@ -24,31 +26,30 @@ path=${path%/} wget -nv -O jappix.tar.gz https://github.com/jappix/jappix/archive/${VERSION}.tar.gz # Copy files to the right place -final_path=/var/www/jappix -sudo mkdir -p $final_path -sudo tar -C $final_path -xf jappix.tar.gz --strip-components 1 -sudo cp ../conf/*.xml $final_path/store/conf/ +final_path="/var/www/${app}" +sudo mkdir -p "$final_path" +sudo tar -C "$final_path" -xf jappix.tar.gz --strip-components 1 +sudo cp ../conf/*.xml "${final_path}/store/conf/" # Set permissions to jappix directory -sudo chown -R www-data: $final_path +sudo chown -R www-data: "$final_path" # Modify Nginx configuration file and copy it to Nginx conf directory -sudo sed -i "s@PATHTOCHANGE2@$path@g" ../conf/nginx.conf +sudo sed -i "s@PATHTOCHANGE2@${path}@g" ../conf/nginx.conf if [ -z "$path" ]; then path="/" fi -sudo sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf -sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/jappix.conf -sudo sed -i "s@PATHTOCHANGE@$path@g" $final_path/store/conf/main.xml -sudo sed -i "s@PATHTOCHANGE@$path@g" $final_path/store/conf/hosts.xml -sudo sed -i "s@DOMAINTOCHANGE@$domain@g" $final_path/store/conf/main.xml -sudo sed -i "s@CHANGELANG@$language@g" $final_path/store/conf/main.xml -sudo sed -i "s@CHANGENAME@$name@g" $final_path/store/conf/main.xml -sudo sed -i "s@DOMAINTOCHANGE@$domain@g" $final_path/store/conf/hosts.xml +sudo sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf +sudo sed -i "s@ALIASTOCHANGE@${final_path}/@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/hosts.xml" +sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@CHANGELANG@${language}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@CHANGENAME@${name}@g" "${final_path}/store/conf/main.xml" +sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/hosts.xml" -# Reload Nginx and regenerate SSOwat conf +# Reload services sudo service nginx reload -sudo yunohost app ssowatconf