Merge pull request #440 from YunoHost/clean-helper-doc

Misc fixes in the helpers to clean the autodoc
This commit is contained in:
Alexandre Aubin 2018-03-15 00:41:55 +01:00 committed by GitHub
commit 44325ec87b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 30 deletions

View file

@ -2,7 +2,7 @@
# #
# usage: ynh_use_logrotate [logfile] [--non-append] # usage: ynh_use_logrotate [logfile] [--non-append]
# | arg: logfile - absolute path of logfile # | arg: logfile - absolute path of logfile
# | option: --non-append - Replace the config file instead of appending this new config. # | arg: --non-append - (Option) Replace the config file instead of appending this new config.
# #
# If no argument provided, a standard directory will be use. /var/log/${app} # If no argument provided, a standard directory will be use. /var/log/${app}
# You can provide a path with the directory only or with the logfile. # You can provide a path with the directory only or with the logfile.
@ -64,9 +64,9 @@ ynh_remove_logrotate () {
# Create a dedicated systemd config # Create a dedicated systemd config
# #
# usage: ynh_add_systemd_config [Service name] [Template name] # usage: ynh_add_systemd_config [service] [template]
# | arg: Service name (optionnal, $app by default) # | arg: service - Service name (optionnal, $app by default)
# | arg: Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template) # | arg: template - Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template)
# #
# This will use the template ../conf/<templatename>.service # This will use the template ../conf/<templatename>.service
# to generate a systemd config, by replacing the following keywords # to generate a systemd config, by replacing the following keywords
@ -76,7 +76,6 @@ ynh_remove_logrotate () {
# __APP__ by $app # __APP__ by $app
# __FINALPATH__ by $final_path # __FINALPATH__ by $final_path
# #
# usage: ynh_add_systemd_config
ynh_add_systemd_config () { ynh_add_systemd_config () {
local service_name="${1:-$app}" local service_name="${1:-$app}"
@ -101,10 +100,9 @@ ynh_add_systemd_config () {
# Remove the dedicated systemd config # Remove the dedicated systemd config
# #
# usage: ynh_remove_systemd_config [Service name] # usage: ynh_remove_systemd_config [service]
# | arg: Service name (optionnal, $app by default) # | arg: service - Service name (optionnal, $app by default)
# #
# usage: ynh_remove_systemd_config
ynh_remove_systemd_config () { ynh_remove_systemd_config () {
local service_name="${1:-$app}" local service_name="${1:-$app}"
@ -119,6 +117,8 @@ ynh_remove_systemd_config () {
# Create a dedicated nginx config # Create a dedicated nginx config
# #
# usage: ynh_add_nginx_config
#
# This will use a template in ../conf/nginx.conf # This will use a template in ../conf/nginx.conf
# __PATH__ by $path_url # __PATH__ by $path_url
# __DOMAIN__ by $domain # __DOMAIN__ by $domain
@ -126,7 +126,6 @@ ynh_remove_systemd_config () {
# __NAME__ by $app # __NAME__ by $app
# __FINALPATH__ by $final_path # __FINALPATH__ by $final_path
# #
# usage: ynh_add_nginx_config
ynh_add_nginx_config () { ynh_add_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalnginxconf" ynh_backup_if_checksum_is_different "$finalnginxconf"

View file

@ -136,6 +136,8 @@ ynh_restore () {
# Return the path in the archive where has been stocked the origin path # Return the path in the archive where has been stocked the origin path
# #
# [internal]
#
# usage: _get_archive_path ORIGIN_PATH # usage: _get_archive_path ORIGIN_PATH
_get_archive_path () { _get_archive_path () {
# For security reasons we use csv python library to read the CSV # For security reasons we use csv python library to read the CSV
@ -203,6 +205,9 @@ ynh_restore_file () {
} }
# Deprecated helper since it's a dangerous one! # Deprecated helper since it's a dangerous one!
#
# [internal]
#
ynh_bind_or_cp() { ynh_bind_or_cp() {
local AS_ROOT=${3:-0} local AS_ROOT=${3:-0}
local NO_ROOT=0 local NO_ROOT=0
@ -213,6 +218,8 @@ ynh_bind_or_cp() {
# Create a directory under /tmp # Create a directory under /tmp
# #
# [internal]
#
# Deprecated helper # Deprecated helper
# #
# usage: ynh_mkdir_tmp # usage: ynh_mkdir_tmp

View file

@ -1,10 +1,10 @@
# Validate an IP address # Validate an IP address
# #
# usage: ynh_validate_ip [family] [ip_address]
# | ret: 0 for valid ip addresses, 1 otherwise
#
# example: ynh_validate_ip 4 111.222.333.444 # example: ynh_validate_ip 4 111.222.333.444
# #
# usage: ynh_validate_ip <family> <ip_address>
#
# exit code : 0 for valid ip addresses, 1 otherwise
ynh_validate_ip() ynh_validate_ip()
{ {
# http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298 # http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298
@ -31,8 +31,8 @@ EOF
# example: ynh_validate_ip4 111.222.333.444 # example: ynh_validate_ip4 111.222.333.444
# #
# usage: ynh_validate_ip4 <ip_address> # usage: ynh_validate_ip4 <ip_address>
# | ret: 0 for valid ipv4 addresses, 1 otherwise
# #
# exit code : 0 for valid ipv4 addresses, 1 otherwise
ynh_validate_ip4() ynh_validate_ip4()
{ {
ynh_validate_ip 4 $1 ynh_validate_ip 4 $1
@ -44,8 +44,8 @@ ynh_validate_ip4()
# example: ynh_validate_ip6 2000:dead:beef::1 # example: ynh_validate_ip6 2000:dead:beef::1
# #
# usage: ynh_validate_ip6 <ip_address> # usage: ynh_validate_ip6 <ip_address>
# | ret: 0 for valid ipv6 addresses, 1 otherwise
# #
# exit code : 0 for valid ipv6 addresses, 1 otherwise
ynh_validate_ip6() ynh_validate_ip6()
{ {
ynh_validate_ip 6 $1 ynh_validate_ip 6 $1

View file

@ -35,6 +35,8 @@ ynh_mysql_execute_file_as_root() {
# Create a database and grant optionnaly privilegies to a user # Create a database and grant optionnaly privilegies to a user
# #
# [internal]
#
# usage: ynh_mysql_create_db db [user [pwd]] # usage: ynh_mysql_create_db db [user [pwd]]
# | arg: db - the database name to create # | arg: db - the database name to create
# | arg: user - the user to grant privilegies # | arg: user - the user to grant privilegies
@ -56,6 +58,8 @@ ynh_mysql_create_db() {
# Drop a database # Drop a database
# #
# [internal]
#
# If you intend to drop the database *and* the associated user, # If you intend to drop the database *and* the associated user,
# consider using ynh_mysql_remove_db instead. # consider using ynh_mysql_remove_db instead.
# #
@ -78,6 +82,8 @@ ynh_mysql_dump_db() {
# Create a user # Create a user
# #
# [internal]
#
# usage: ynh_mysql_create_user user pwd [host] # usage: ynh_mysql_create_user user pwd [host]
# | arg: user - the user name to create # | arg: user - the user name to create
# | arg: pwd - the password to identify user by # | arg: pwd - the password to identify user by
@ -90,7 +96,7 @@ ynh_mysql_create_user() {
# #
# usage: ynh_mysql_user_exists user # usage: ynh_mysql_user_exists user
# | arg: user - the user for which to check existence # | arg: user - the user for which to check existence
function ynh_mysql_user_exists() ynh_mysql_user_exists()
{ {
local user=$1 local user=$1
if [[ -z $(ynh_mysql_execute_as_root "SELECT User from mysql.user WHERE User = '$user';") ]] if [[ -z $(ynh_mysql_execute_as_root "SELECT User from mysql.user WHERE User = '$user';") ]]
@ -103,6 +109,8 @@ function ynh_mysql_user_exists()
# Drop a user # Drop a user
# #
# [internal]
#
# usage: ynh_mysql_drop_user user # usage: ynh_mysql_drop_user user
# | arg: user - the user name to drop # | arg: user - the user name to drop
ynh_mysql_drop_user() { ynh_mysql_drop_user() {
@ -153,7 +161,7 @@ ynh_mysql_remove_db () {
# Sanitize a string intended to be the name of a database # Sanitize a string intended to be the name of a database
# (More specifically : replace - and . by _) # (More specifically : replace - and . by _)
# #
# Exemple: dbname=$(ynh_sanitize_dbid $app) # example: dbname=$(ynh_sanitize_dbid $app)
# #
# usage: ynh_sanitize_dbid name # usage: ynh_sanitize_dbid name
# | arg: name - name to correct/sanitize # | arg: name - name to correct/sanitize

View file

@ -26,6 +26,8 @@ ynh_package_version() {
# APT wrapper for non-interactive operation # APT wrapper for non-interactive operation
# #
# [internal]
#
# usage: ynh_apt update # usage: ynh_apt update
ynh_apt() { ynh_apt() {
DEBIAN_FRONTEND=noninteractive sudo apt-get -y -qq $@ DEBIAN_FRONTEND=noninteractive sudo apt-get -y -qq $@
@ -73,6 +75,8 @@ ynh_package_autopurge() {
# Build and install a package from an equivs control file # Build and install a package from an equivs control file
# #
# [internal]
#
# example: generate an empty control file with `equivs-control`, adjust its # example: generate an empty control file with `equivs-control`, adjust its
# content and use helper to build and install the package: # content and use helper to build and install the package:
# ynh_package_install_from_equivs /path/to/controlfile # ynh_package_install_from_equivs /path/to/controlfile

View file

@ -6,7 +6,11 @@ ynh_die() {
} }
# Ignore the yunohost-cli log to prevent errors with conditionals commands # Ignore the yunohost-cli log to prevent errors with conditionals commands
#
# [internal]
#
# usage: ynh_no_log COMMAND # usage: ynh_no_log COMMAND
#
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this 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... # It's a very badly hack...
ynh_no_log() { ynh_no_log() {

View file

@ -1,18 +1,19 @@
# Manage a fail of the script # Manage a fail of the script
# #
# Print a warning to inform that the script was failed # [internal]
# Execute the ynh_clean_setup function if used in the app script
# #
# usage of ynh_clean_setup function # usage:
# This function provide a way to clean some residual of installation that not managed by remove script. # ynh_exit_properly is used only by the helper ynh_abort_if_errors.
# To use it, simply add in your script: # You should not use it directly.
# Instead, add to your script:
# ynh_clean_setup () { # ynh_clean_setup () {
# instructions... # instructions...
# } # }
# This function is optionnal.
# #
# Usage: ynh_exit_properly is used only by the helper ynh_abort_if_errors. # This function provide a way to clean some residual of installation that not managed by remove script.
# You must not use it directly. #
# It prints a warning to inform that the script was failed, and execute the ynh_clean_setup function if used in the app script
#
ynh_exit_properly () { ynh_exit_properly () {
local exit_code=$? local exit_code=$?
if [ "$exit_code" -eq 0 ]; then if [ "$exit_code" -eq 0 ]; then
@ -31,20 +32,24 @@ ynh_exit_properly () {
ynh_die # Exit with error status ynh_die # Exit with error status
} }
# Exit if an error occurs during the execution of the script. # Exits if an error occurs during the execution of the script.
# #
# Stop immediatly the execution if an error occured or if a empty variable is used. # usage: ynh_abort_if_errors
# The execution of the script is derivate to ynh_exit_properly function before exit. #
# This configure the rest of the script execution such that, if an error occurs
# or if an empty variable is used, the execution of the script stops
# immediately and a call to `ynh_clean_setup` is triggered if it has been
# defined by your script.
# #
# Usage: ynh_abort_if_errors
ynh_abort_if_errors () { ynh_abort_if_errors () {
set -eu # Exit if a command fail, and if a variable is used unset. set -eu # Exit if a command fail, and if a variable is used unset.
trap ynh_exit_properly EXIT # Capturing exit signals on shell script trap ynh_exit_properly EXIT # Capturing exit signals on shell script
} }
# Return the Debian release codename (i.e. jessie, stretch, etc.) # Fetch the Debian release codename
# #
# usage: ynh_get_debian_release # usage: ynh_get_debian_release
# | ret: The Debian release codename (i.e. jessie, stretch, ...)
ynh_get_debian_release () { ynh_get_debian_release () {
echo $(lsb_release --codename --short) echo $(lsb_release --codename --short)
} }