From e5a150e077eb9120d9e41a3bad6404c63d33f2fe Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 3 Dec 2017 19:24:03 +0100 Subject: [PATCH] Minor linter fixes --- manifest.json | 2 +- scripts/_common.sh | 57 +++++++--------------------------------------- scripts/backup | 23 +++++++++++++++++-- scripts/install | 25 +++++++++++++++----- scripts/remove | 14 ++++++++++-- scripts/restore | 24 +++++++++++++++++-- scripts/upgrade | 12 ++++++++++ 7 files changed, 95 insertions(+), 62 deletions(-) diff --git a/manifest.json b/manifest.json index af62381..b0cc629 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "" }, "requirements": { - "yunohost": ">> 2.4.0" + "yunohost": ">= 2.7.2" }, "multi_instance": false, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 6a452df..e58bfc8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -57,7 +57,7 @@ install_dependencies() { # Install packages # We install them as dependencies as they may already be installed and used for other purposes - ynh_app_dependencies influxdb, grafana \ + ynh_install_app_dependencies influxdb, grafana \ || { # Remove apt repositories if they were added [[ -n "$influxdb_repository_present" ]] && sudo rm $INFLUXDB_REPOSITORY @@ -66,56 +66,15 @@ install_dependencies() { } } - # ======== Future YunoHost helpers ======== -# Install dependencies with a equivs control file -# -# usage: ynh_app_dependencies dep [dep [...]] -# | arg: dep - the package name to install in dependence -ynh_app_dependencies () { - dependencies=$@ - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file. - dep_app=${app//_/-} # Replace all '_' by '-' - cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build -Section: misc -Priority: optional -Package: ${dep_app}-ynh-deps -Version: ${version} -Depends: ${dependencies// /, } -Architecture: all -Description: Fake package for ${app} (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \ - || ynh_die "Unable to install dependencies" # Install the fake package and its dependencies -} -# Remove fake package and its dependencies +# Delete a file checksum from the app settings # -# Dependencies will removed only if no other package need them. +# $app should be defined when calling this helper # -# usage: ynh_remove_app_dependencies -ynh_remove_app_dependencies () { - dep_app=${app//_/-} # Replace all '_' by '-' - ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used. -} - -# Find a free port and return it -# -# example: port=$(ynh_find_port 8080) -# -# usage: ynh_find_port begin_port -# | arg: begin_port - port to start to search -ynh_find_port () { - port=$1 - test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port." - while netcat -z 127.0.0.1 $port # Check if the port is free - do - port=$((port+1)) # Else, pass to next port - done - echo $port +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name } diff --git a/scripts/backup b/scripts/backup index 9b4b31f..99b3b5a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,8 +1,27 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +if [ ! -e _common.sh ]; then + # Fetch helpers file if not in current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= app=$YNH_APP_INSTANCE_NAME # Source YunoHost helpers diff --git a/scripts/install b/scripts/install index bd57f5a..5f4477b 100644 --- a/scripts/install +++ b/scripts/install @@ -1,14 +1,27 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu - shopt -s extglob # sets extended pattern matching options in the bash shell -app=$YNH_APP_INSTANCE_NAME +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source local helpers -source ./_common.sh +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_abort_if_errors # Stop script if an error is detected + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN diff --git a/scripts/remove b/scripts/remove index 455205e..aae9a2a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,17 @@ #!/bin/bash -# Treat unset variables as an error -set -u +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= # See comments in install script app=$YNH_APP_INSTANCE_NAME diff --git a/scripts/restore b/scripts/restore index a29225d..e200df1 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,27 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Fetch helpers file if not in current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= app=$YNH_APP_INSTANCE_NAME diff --git a/scripts/upgrade b/scripts/upgrade index e5c7b33..4854988 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,6 +29,18 @@ fi # Fix path if needed path=$(fix_path $path) +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Use prior backup and restore on error only if backup feature +# exists on installed instance +ynh_backup_before_upgrade # Backup the current version of the app +ynh_clean_setup () { + ynh_restore_upgradebackup +} +ynh_abort_if_errors # Stop script if an error is detected + # There's currently nothing else to upgrade than packaging files # as InfluxDB/Grafana updates are managed through APT