Able to replace sources

This commit is contained in:
yalh76 2022-10-01 17:15:21 +02:00
parent 70927d5e04
commit 37c2f941de

View file

@ -63,10 +63,11 @@ ynh_abort_if_errors() {
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
# #
# usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] [--keep="file1 file2"] # usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] [--keep="file1 file2"] [--replace]
# | arg: -d, --dest_dir= - Directory where to setup sources # | arg: -d, --dest_dir= - Directory where to setup sources
# | arg: -s, --source_id= - Name of the source, defaults to `app` # | arg: -s, --source_id= - Name of the source, defaults to `app`
# | arg: -k, --keep= - Space-separated list of files/folders that will be backup/restored in $dest_dir, such as a config file you don't want to overwrite. For example 'conf.json secrets.json logs/' # | arg: -k, --keep= - Space-separated list of files/folders that will be backup/restored in $dest_dir, such as a config file you don't want to overwrite. For example 'conf.json secrets.json logs/'
# | arg: -r, --replace= - Remove previous sources before installing new sources
# #
# This helper will read `conf/${source_id}.src`, download and install the sources. # This helper will read `conf/${source_id}.src`, download and install the sources.
# #
@ -102,14 +103,16 @@ ynh_abort_if_errors() {
ynh_setup_source() { ynh_setup_source() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=dsk local legacy_args=dsk
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep=) local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=replace=)
local dest_dir local dest_dir
local source_id local source_id
local keep local keep
local replace
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
source_id="${source_id:-app}" source_id="${source_id:-app}"
keep="${keep:-}" keep="${keep:-}"
replace="${replace:-0}"
local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src" local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src"
@ -172,6 +175,10 @@ ynh_setup_source() {
done done
fi fi
if [ "$replace" -eq 1 ]; then
ynh_secure_remove --file="$dest_dir"
fi
# Extract source into the app dir # Extract source into the app dir
mkdir --parents "$dest_dir" mkdir --parents "$dest_dir"