1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/writefreely_ynh.git synced 2024-09-03 20:36:02 +02:00

Apply example_ynh

This commit is contained in:
yalh76 2019-05-15 14:38:19 +02:00
parent 5b90b4475c
commit db8d25da50
9 changed files with 217 additions and 245 deletions

View file

@ -45,9 +45,9 @@ If User Mode is configured Multiple users, the app be used by multiple users
#### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/writefreely%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/writefreely/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/writefreely%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/writefreely/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/writefreely%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/writefreely/)
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/writefreely%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/writefreely/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/writefreely%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/writefreely/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/writefreely%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/writefreely/)
## Limitations

View file

@ -18,7 +18,7 @@
"name": "yalh76"
}],
"requirements": {
"yunohost": ">= 3.4"
"yunohost": ">= 3.5"
},
"multi_instance": true,
"services": [

View file

@ -7,7 +7,6 @@
#=================================================
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
@ -23,48 +22,62 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_print_info "Backing up the main app directory..."
ynh_print_info --message="Backing up the main app directory..."
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backing up nginx web server configuration..."
ynh_print_info --message="Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info "Backing up the MySQL database..."
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db "$db_name" > db.sql
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_print_info "Backing up systemd configuration..."
ynh_print_info --message="Backing up systemd configuration..."
ynh_backup "/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
ynh_print_info "Retrieve arguments from the manifest"
ynh_print_info --message="Retrieve arguments from the manifest"
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
@ -25,14 +25,15 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_print_info --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
#db_name=$(ynh_app_setting_get "$app" db_name)
#db_pwd=$(ynh_app_setting_get $app db_pwd)
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#db_user=$db_name
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
@ -52,10 +53,17 @@ fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_print_info "Updating nginx web server configuration..."
ynh_print_info --message="Updating nginx web server configuration..."
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -63,7 +71,7 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path"
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
@ -75,51 +83,46 @@ fi
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path"
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_replace_string "host =.*" "host = https://$new_domain" "$final_path/config.ini"
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app
ynh_replace_string --match_string="host =.*" --replace_string="host = https://$new_domain" --target_file="$final_path/config.ini"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_backup_if_checksum_is_different "$final_path/config.ini"
ynh_backup_if_checksum_is_different --file="$final_path/config.ini"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/config.ini"
ynh_store_file_checksum --file="$final_path/config.ini"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Change of URL completed for $app"
ynh_print_info --message="Change of URL completed for $app"

View file

@ -9,6 +9,6 @@ elif [ -n "$(uname -m | grep arm)" ]; then
elif [ -n "$(uname -m | grep aarch64)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
ynh_die --message="Unable to detect your achitecture, please open a bug describing \
your hardware and the result of the command \"uname -m\"." 1
fi

View file

@ -23,7 +23,7 @@ ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
ynh_print_info "Retrieve arguments from the manifest ..."
ynh_print_info --message="Retrieve arguments from the manifest ..."
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
@ -44,10 +44,10 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_print_info "Validating installation parameters..."
ynh_print_info --message="Validating installation parameters..."
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register $app $domain $path_url
@ -55,55 +55,50 @@ ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_print_info "Storing installation settings..."
ynh_print_info --message="Storing installation settings..."
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set $app single_user $single_user
ynh_app_setting_set --app=$app --key=single_user --value=$single_user
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_print_info "Configuring firewall ..."
ynh_print_info --message="Configuring firewall ..."
# Find a free port
port=$(ynh_find_port 8095)
ynh_app_setting_set $app port $port
port=$(ynh_find_port --port=8095)
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies ..."
#ynh_install_app_dependencies deb1 deb2
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_print_info "Creating a mysql database ..."
ynh_print_info --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info "Setting up source files ..."
ynh_print_info --message="Setting up source files..."
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" $architecture
ynh_setup_source --dest_dir="$final_path" --source_id=$architecture
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Configuring nginx web server..."
ynh_print_info --message="Configuring nginx web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
@ -111,17 +106,17 @@ ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_print_info "Configuring system user ..."
ynh_print_info --message="Configuring system user..."
# Create a system user
ynh_system_user_create "$app" "$final_path"
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# SPECIFIC SETUP
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info "Configuring a systemd service ..."
ynh_print_info --message="Configuring a systemd service ..."
# Create a dedicated systemd config
ynh_add_systemd_config
@ -133,22 +128,20 @@ ynh_add_systemd_config
# setup application config
cp "../conf/config.ini" "$final_path/config.ini"
ynh_replace_string "__DBNAME__" "$db_name" "$final_path/config.ini"
ynh_replace_string "__DBUSER__" "$db_name" "$final_path/config.ini"
ynh_replace_string "__DBPWD__" "$db_pwd" "$final_path/config.ini"
ynh_replace_string "__PORT__" "$port" "$final_path/config.ini"
ynh_replace_string "__DOMAIN_URL__" "https://$domain" "$final_path/config.ini"
ynh_replace_string "__SINGLEUSER__" "$single_user" "$final_path/config.ini"
ynh_replace_string --match_string="__DBNAME__" --replace_string="$db_name" --target_file="$final_path/config.ini"
ynh_replace_string --match_string="__DBUSER__" --replace_string="$db_name" --target_file="$final_path/config.ini"
ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$final_path/config.ini"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.ini"
ynh_replace_string --match_string="__DOMAIN_URL__" --replace_string="https://$domain" --target_file="$final_path/config.ini"
ynh_replace_string --match_string="__SINGLEUSER__" --replace_string="$single_user" --target_file="$final_path/config.ini"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.ini"
ynh_store_file_checksum --file="$final_path/config.ini"
#=================================================
# SPECIFIC SETUP
#=================================================
# MAKE SETUP
#=================================================
@ -177,33 +170,33 @@ chown -R "$app":"$app" "$final_path"
# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added
yunohost service add $app --description "$app daemon for WriteFreely" --log_type systemd
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_systemd_action --service_name=$app --action=start
#=================================================
# SETUP SSOWAT
#=================================================
ynh_print_info "Configuring SSOwat ..."
ynh_print_info --message="Configuring SSOwat ..."
# 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 "/"
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"
ynh_print_info --message="Installation of $app completed"

View file

@ -12,14 +12,15 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
@ -28,16 +29,16 @@ final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status | grep -q $app
if yunohost service status $app >/dev/null 2>&1
then
ynh_print_info "Removing $app service"
ynh_print_info --message="Removing $app service..."
yunohost service remove $app
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_print_info "Stopping and removing the systemd service"
ynh_print_info --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config
ynh_remove_systemd_config
@ -45,31 +46,23 @@ ynh_remove_systemd_config
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_print_info "Removing the MySQL database"
ynh_print_info --message="Removing the MySQL database"
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_name $db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
#ynh_remove_app_dependencies
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_print_info "Removing app main directory"
ynh_print_info --message="Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_print_info "Removing nginx web server configuration"
ynh_print_info --message="Removing nginx web server configuration"
# Remove the dedicated nginx config
ynh_remove_nginx_config
@ -80,34 +73,22 @@ ynh_remove_nginx_config
if yunohost firewall list | grep -q "\- $port$"
then
ynh_print_info "Closing port $port"
ynh_script_progression --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Remove a directory securely
ynh_secure_remove "/etc/$app/"
# Remove the log files
ynh_secure_remove "/var/log/$app/"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_print_info "Removing the dedicated system user"
ynh_print_info --message="Removing the dedicated system user..."
# Delete a system user
ynh_system_user_delete $app
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Removal of $app completed"
ynh_print_info --message="Removal of $app completed"

View file

@ -23,24 +23,25 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading settings..."
ynh_print_info --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_print_info "Validating restoration parameters..."
ynh_print_info --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
@ -48,22 +49,22 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info "Restoring the app main directory..."
ynh_print_info --message="Restoring the app main directory..."
ynh_restore_file "$final_path"
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_print_info "Recreating the dedicated system user..."
ynh_print_info --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create "$app" "$final_path"
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE USER RIGHTS
@ -74,31 +75,22 @@ chown -R "$app":"$app" "$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."
# Define and install dependencies
#ynh_install_app_dependencies deb1 deb2
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_print_info "Restoring the MySQL database..."
ynh_print_info --message="Restoring 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
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_print_info "Restoring the systemd configuration..."
ynh_print_info --message="Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$app.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
systemctl daemon-reload
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
@ -106,23 +98,24 @@ systemctl daemon-reload
yunohost service add $app --description "$app daemon for WriteFreely" --log_type systemd
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Restoration completed for $app"
ynh_print_info --message="Restoration completed for $app"

View file

@ -14,18 +14,18 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get $app db_name)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK VERSION
@ -36,44 +36,51 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_print_info "Ensuring downward compatibility..."
ynh_print_info --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
# remove old variables
ynh_app_setting_delete $app site_name
ynh_app_setting_delete $app site_description
ynh_app_setting_delete $app open_registration
ynh_app_setting_delete $app max_blogs
ynh_app_setting_delete $app federation
ynh_app_setting_delete $app public_stats
ynh_app_setting_delete $app private
ynh_app_setting_delete $app local_timeline
# Remove old variables
ynh_app_setting_delete --app=$app --key=site_name
ynh_app_setting_delete --app=$app --key=site_description
ynh_app_setting_delete --app=$app --key=open_registration
ynh_app_setting_delete --app=$app --key=max_blogs
ynh_app_setting_delete --app=$app --key=federation
ynh_app_setting_delete --app=$app--key= public_stats
ynh_app_setting_delete --app=$app --key=private
ynh_app_setting_delete --app=$app --key=local_timeline
# Close a port
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port" >&2
yunohost firewall disallow TCP $port 2>&1
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..."
ynh_print_info --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
@ -85,54 +92,41 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_systemd_action --service_name=$app --action=stop
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_setup_source "$final_path" $architecture
ynh_print_info --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --source_id=$architecture
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Upgrading nginx web server configuration..."
ynh_print_info --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_print_info "Upgrading dependencies..."
#ynh_install_app_dependencies deb1 deb2
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_print_info "Making sure dedicated system user exists..."
ynh_print_info --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create "$app" "$final_path"
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# SPECIFIC UPGRADE
@ -146,24 +140,18 @@ pushd $final_path
sudo -u $app ./writefreely --migrate
popd
ynh_backup_if_checksum_is_different "$final_path/config.ini"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_backup_if_checksum_is_different --file="$final_path/config.ini"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/config.ini"
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port" >&2
yunohost firewall disallow TCP $port 2>&1
fi
ynh_store_file_checksum --file="$final_path/config.ini"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info "Upgrading systemd configuration..."
ynh_print_info --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
@ -180,30 +168,31 @@ chown -R "$app":"$app" "$final_path"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_print_info "Upgrading SSOwat configuration..."
ynh_print_info --message="Upgrading SSOwat configuration..."
# 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 "/"
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
systemctl reload nginx
#=================================================
# START SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service.."
ynh_systemd_action --action=start --service_name=$app
ynh_systemd_action --service_name=$app --action=start
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Upgrade of $app completed"
ynh_print_info --message="Upgrade of $app completed"