diff --git a/check_process b/check_process new file mode 100644 index 0000000..4388983 --- /dev/null +++ b/check_process @@ -0,0 +1,33 @@ +;; Test complet + ; Manifest + server="domain.tld:22" + ssh_user="sam" + public_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILM5TaFx9x9gXAkdRqEw39tpBLW/jXFzcBe9diuPlEfP" + quota="5G" + ; Checks + pkg_linter=1 + setup_sub_dir=0 + setup_root=0 + setup_nourl=0 + setup_private=0 + setup_public=0 + upgrade=1 + backup_restore=1 + multi_instance=1 + incorrect_path=0 + port_already_use=0 + change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + Level 4=1 + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email=ljf+borgserver_ynh@reflexlibre.net +Notification=down diff --git a/manifest.json b/manifest.json index b102291..395997e 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Offer backup storage to a friend.", "fr": "Offrez un espace de stockage à un⋅e ami⋅e." }, - "version": "1.0", + "version": "1.0.1", "url": "https://borgbackup.readthedocs.io", "license": "BSD-3-Clause", "maintainer": { @@ -15,7 +15,7 @@ "url": "https://reflexlibre.net" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.1" }, "multi_instance": true, "services": [], diff --git a/scripts/_common.sh b/scripts/_common.sh index 3a461a3..215e0ee 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -58,3 +58,57 @@ ynh_configure () { ynh_render_template "${PKG_DIR}/conf/$1.j2" $2 ynh_store_file_checksum $2 } + +# Checks the app version to upgrade with the existing app version and returns: +# - UPGRADE_APP if the upstream app version has changed +# - UPGRADE_PACKAGE if only the YunoHost package has changed +# +## It stops the current script without error if the package is up-to-date +# +# This helper should be used to avoid an upgrade of an app, or the upstream part +# of it, when it's not needed +# +# To force an upgrade, even if the package is up to date, +# you have to set the variable YNH_FORCE_UPGRADE before. +# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp + +# usage: ynh_check_app_version_changed +ynh_check_app_version_changed () { + local force_upgrade=${YNH_FORCE_UPGRADE:-0} + local package_check=${PACKAGE_CHECK_EXEC:-0} + + # By default, upstream app version has changed + local return_value="UPGRADE_APP" + + local current_version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + local current_upstream_version="${current_version/~ynh*/}" + local update_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) + local update_upstream_version="${update_version/~ynh*/}" + + if [ "$current_version" == "$update_version" ] ; then + # Complete versions are the same + if [ "$force_upgrade" != "0" ] + then + echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 + unset YNH_FORCE_UPGRADE + elif [ "$package_check" != "0" ] + then + echo "Upgrade forced for package check." >&2 + else + ynh_die "Up-to-date, nothing to do" 0 + fi + elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then + # Upstream versions are the same, only YunoHost package versions differ + return_value="UPGRADE_PACKAGE" + fi + echo $return_value +} + + +ynh_install_backports () { + echo "deb http://httpredir.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/$app-stretch-backports.list +} + +ynh_remove_backports () { + rm /etc/apt/sources.list.d/$app-stretch-backports.list +} diff --git a/scripts/install b/scripts/install index 0cc1099..4d4bd66 100755 --- a/scripts/install +++ b/scripts/install @@ -29,12 +29,17 @@ ynh_export ssh_user public_key quota #================================================= ynh_save_args ssh_user public_key quota +#================================================= +# CONFIGURE BACKPORTS +#================================================= +# We need borg 1.1+ available only in backports +ynh_install_backports + #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_install_app_dependencies $pkg_dependencies -pip3 install setuptools --upgrade -pip3 install borgbackup +ynh_package_install -t stretch-backports borgbackup #================================================= # CREATE SSH USER USED BY BORG diff --git a/scripts/remove b/scripts/remove index 3125ed6..2ee3cba 100755 --- a/scripts/remove +++ b/scripts/remove @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -20,6 +21,11 @@ ssh_user=$(ynh_app_setting_get $app ssh_user) #================================================= ynh_remove_app_dependencies +#================================================= +# REMOVE BACKPORTS +#================================================= +ynh_remove_backports + #================================================= # REMOVE FILES #================================================= diff --git a/scripts/restore b/scripts/restore index 0b84591..629eddd 100755 --- a/scripts/restore +++ b/scripts/restore @@ -32,11 +32,16 @@ export public_key=$(ynh_app_setting_get $app public_key) export quota=$(ynh_app_setting_get $app quota) #================================================= -# STORE SETTINGS FROM MANIFEST +# CONFIGURE BACKPORTS +#================================================= +# We need borg 1.1+ available only in backports +ynh_install_backports + +#================================================= +# INSTALL DEPENDENCIES #================================================= ynh_install_app_dependencies $pkg_dependencies -pip3 install setuptools --upgrade -pip3 install borgbackup +ynh_package_install -t stretch-backports borgbackup #================================================= # CREATE SSH USER USED BY BORG diff --git a/scripts/upgrade b/scripts/upgrade index 35d72d2..a2f1c92 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,11 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME +#================================================= +# CHECK IF AN UPGRADE IS NEEDED +#================================================= +ynh_check_app_version_changed + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #=================================================