@ -13,6 +13,10 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
# MANAGE SCRIPT FAILURE
#=================================================
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_abort_if_errors
@ -25,17 +29,18 @@ path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
language=$YNH_APP_ARG_LANGUAGE
password=$YNH_APP_ARG_PASSWORD
# 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
### If it's a multi-instance app, meaning it can be installed several times independently
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
### The id of the app as stated in the manifest is available as $YNH_APP_ID
# The app instance name is available as $YNH_APP_INSTANCE_NAME
### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
### The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# The app instance name is probably what you are interested the most, since this is
### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# guaranteed to be unique. This is a good unique identifier to define installation path,
### The app instance name is probably what you are interested the most, since this is
# db names, ...
### guaranteed to be unique. This is a good unique identifier to define installation path,
### db names, ...
app=$YNH_APP_INSTANCE_NAME
app=$YNH_APP_INSTANCE_NAME
#=================================================
#=================================================
@ -69,6 +74,11 @@ ynh_app_setting_set $app language $language
# FIND AND OPEN A PORT
# FIND AND OPEN A PORT
#=================================================
#=================================================
### Use these lines if you have to open a port for the application
### `ynh_find_port` will find the first available port starting to the given port.
### If you're not using these lines:
### - Remove the section "CLOSE A PORT" in the remove script
# Find a free port
# Find a free port
port=$(ynh_find_port 8095)
port=$(ynh_find_port 8095)
# Open this port
# Open this port
@ -79,13 +89,27 @@ ynh_app_setting_set $app port $port
# INSTALL DEPENDENCIES
# INSTALL DEPENDENCIES
#=================================================
#=================================================
### `ynh_install_app_dependencies` allow you to add any "apt" dependencies to the package.
### Those deb packages will be installed as dependencies of this package.
### If you're not using this helper:
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_install_app_dependencies deb1 deb2
ynh_install_app_dependencies deb1 deb2
#=================================================
#=================================================
# CREATE A MYSQL DATABASE
# CREATE A MYSQL DATABASE
#=================================================
#=================================================
# If your app uses a MySQL database, you can use these lines to bootstrap
# a database, an associated user and save the password in app settings
### Use these lines if you need a database for the application.
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
### The password will be stored as 'mysqlpwd' into the app settings,
### and will be available as $db_pwd
### If you're not using these lines:
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
db_name=$(ynh_sanitize_dbid $app)
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_app_setting_set $app db_name $db_name
@ -95,6 +119,10 @@ ynh_mysql_setup_db $db_name $db_name
# DOWNLOAD, CHECK AND UNPACK SOURCE
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
#=================================================
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
ynh_setup_source "$final_path"
@ -103,13 +131,10 @@ ynh_setup_source "$final_path"
# NGINX CONFIGURATION
# NGINX CONFIGURATION
#=================================================
#=================================================
### `ynh_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated nginx config
# Create a dedicated nginx config
ynh_add_nginx_config
ynh_add_nginx_config
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
#=================================================
# CREATE DEDICATED USER
# CREATE DEDICATED USER
@ -122,6 +147,17 @@ ynh_system_user_create $app
# PHP-FPM CONFIGURATION
# PHP-FPM CONFIGURATION
#=================================================
#=================================================
### `ynh_add_fpm_config` is used to set up an php config.
### You can remove it if your app doesn't use php.
### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script
### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script
### With the reload at the end of the script.
### - And the section "PHP-FPM CONFIGURATION" in the upgrade script
# Create a dedicated php-fpm config
# Create a dedicated php-fpm config
ynh_add_fpm_config
ynh_add_fpm_config
@ -135,6 +171,17 @@ ynh_add_fpm_config
# SETUP SYSTEMD
# SETUP SYSTEMD
#=================================================
#=================================================
### `ynh_systemd_config` is used to configure a systemd script for an app.
### It can be used for app would use sysvinit (with adaptation) or systemd.
### Have a look to the app to be sure this app need a systemd script.
### `ynh_systemd_config` will use the file conf/systemd.service
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "BACKUP SYSTEMD" in the backup script
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
### - As well as the section "RESTORE SYSTEMD" in the restore script
### - And the section "SETUP SYSTEMD" in the upgrade script
# Create a dedicated systemd config
# Create a dedicated systemd config
ynh_systemd_config
ynh_systemd_config
@ -142,6 +189,10 @@ ynh_systemd_config
# SETUP APPLICATION WITH CURL
# SETUP APPLICATION WITH CURL
#=================================================
#=================================================
### Use those lines only if the app need to be installed by a web application
### Because, we don't want to ask the final user to it himself,
### we're going to use curl to fill the field of the application.
# Set right permissions for curl install
# Set right permissions for curl install
chown -R $app: $final_path
chown -R $app: $final_path
@ -156,16 +207,28 @@ systemctl reload nginx
# Installation with curl
# Installation with curl
ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
# Remove the public access
if [ $is_public -eq 0 ]
then
ynh_app_setting_delete $app skipped_uris
fi
#=================================================
#=================================================
# MODIFY A CONFIG FILE
# MODIFY A CONFIG FILE
#=================================================
#=================================================
### `ynh_replace_string` is used to replace string in a file.
ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
#=================================================
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
#=================================================
### `ynh_store_file_checksum` is used to store the checksum of a file.
### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`,
### you can make a backup of this file before modifying it again if the admin had modified it.
# Calculate and store the config file checksum into the app settings
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/CONFIG_FILE"
ynh_store_file_checksum "$final_path/CONFIG_FILE"
@ -175,6 +238,10 @@ ynh_store_file_checksum "$final_path/CONFIG_FILE"
# SECURE FILES AND DIRECTORIES
# SECURE FILES AND DIRECTORIES
#=================================================
#=================================================
### For security reason, any app should set the permission to root: before anything else.
### Then, if write authorisation is needed, any access should be given only to directories
### that really need such authorisations.
# Set permissions to app files
# Set permissions to app files
chown -R root: $final_path
chown -R root: $final_path
@ -182,6 +249,14 @@ chown -R root: $final_path
# SETUP LOGROTATE
# SETUP LOGROTATE
#=================================================
#=================================================
### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
### Use this helper only if there effectively a log for this app.
### If you're not using this helper:
### - Remove the section "BACKUP LOGROTATE" in the backup script
### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
### - And the section "SETUP LOGROTATE" in the upgrade script
# Use logrotate to manage application logfile(s)
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
ynh_use_logrotate
@ -189,16 +264,20 @@ ynh_use_logrotate
# ADVERTISE SERVICE IN ADMIN PANEL
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
#=================================================
### `yunohost service add` is a cli yunohost command to add a service in the admin panel.
### You'll find the service in the 'services' section of YunoHost admin panel.
### This cli command would be useless if the app does not have any services (systemd or sysvinit)
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script
### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script
yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
#=================================================
#=================================================
# SETUP SSOWAT
# 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
# Make app public if necessary
if [ $is_public -eq 1 ]
if [ $is_public -eq 1 ]
then
then