mirror of
https://github.com/YunoHost-Apps/jappix_ynh.git
synced 2024-09-03 19:26:19 +02:00
Create .fonctions
This commit is contained in:
parent
5d7c35bc89
commit
961ea8816f
1 changed files with 95 additions and 0 deletions
95
scripts/.fonctions
Normal file
95
scripts/.fonctions
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECKING
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
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.
|
||||||
|
sudo yunohost app checkurl $domain$path -a $app
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
||||||
|
final_path=/var/www/$app
|
||||||
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path
|
||||||
|
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d= -f2)
|
||||||
|
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2)
|
||||||
|
# Download sources from the upstream
|
||||||
|
wget -nv -O source.tar.gz $src_url
|
||||||
|
# Vérifie la somme de contrôle de la source téléchargée.
|
||||||
|
echo "$src_checksum source.tar.gz" | md5sum -c --status || ynh_die "Corrupt source"
|
||||||
|
# Extract source into the app dir
|
||||||
|
sudo mkdir -p $final_path
|
||||||
|
sudo tar -x -f source.tar.gz -C $final_path --strip-components 1
|
||||||
|
# Copie les fichiers additionnels ou modifiés.
|
||||||
|
if test -e "../sources/ajouts"; then
|
||||||
|
sudo cp -a ../sources/ajouts/. "$final_path"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
#=================================================
|
||||||
|
# FUTUR YNH HELPERS
|
||||||
|
#=================================================
|
||||||
|
# Importer ce fichier de fonction avant celui des helpers officiel
|
||||||
|
# Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Manage a fail of the script
|
||||||
|
#
|
||||||
|
# Print a warning to inform that the script was failed
|
||||||
|
# Execute the ynh_clean_setup function if used in the app script
|
||||||
|
#
|
||||||
|
# usage of ynh_clean_setup function
|
||||||
|
# This function provide a way to clean some residual of installation that not managed by remove script.
|
||||||
|
# To use it, simply add in your script:
|
||||||
|
# ynh_clean_setup () {
|
||||||
|
# instructions...
|
||||||
|
# }
|
||||||
|
# This function is optionnal.
|
||||||
|
#
|
||||||
|
# Usage: ynh_exit_properly is used only by the helper ynh_check_error.
|
||||||
|
# You must not use it directly.
|
||||||
|
ynh_exit_properly () {
|
||||||
|
exit_code=$?
|
||||||
|
if [ "$exit_code" -eq 0 ]; then
|
||||||
|
exit 0 # Exit without error if the script ended correctly
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap '' EXIT # Ignore new exit signals
|
||||||
|
set +eu # Do not exit anymore if a command fail or if a variable is empty
|
||||||
|
|
||||||
|
echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2
|
||||||
|
|
||||||
|
if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script.
|
||||||
|
ynh_clean_setup # Call the function to do specific cleaning for the app.
|
||||||
|
fi
|
||||||
|
|
||||||
|
ynh_die # Exit with error status
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit 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.
|
||||||
|
# The execution of the script is derivate to ynh_exit_properly function before exit.
|
||||||
|
#
|
||||||
|
# Usage: ynh_check_error
|
||||||
|
ynh_check_error () {
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue