From f237ed38ac0fea27c31f3aaffc465d19875d7417 Mon Sep 17 00:00:00 2001 From: oiseauroch Date: Sun, 30 Jul 2023 14:51:43 +0200 Subject: [PATCH] change virtualisation helper --- manifest.toml | 6 ++++-- scripts/_common.sh | 26 -------------------------- scripts/install | 13 ------------- scripts/restore | 4 ---- scripts/upgrade | 38 ++++++++++++++------------------------ 5 files changed, 18 insertions(+), 69 deletions(-) diff --git a/manifest.toml b/manifest.toml index 443bb48..fd13edd 100644 --- a/manifest.toml +++ b/manifest.toml @@ -48,7 +48,7 @@ ram.runtime = "50M" [install.weight] ask.en = "number of G to allow" ask.fr = "nombre de G à allouer" - type = "string" + type = "number" [resources] @@ -80,4 +80,6 @@ ram.runtime = "50M" main.url = "/" [resources.apt] - packages = "qemu-utils e2fsprogs" + packages_from_raw_bash = """ + systemd-detect-virt -q -c && apt install qemu-utils e2fsprogs + """ diff --git a/scripts/_common.sh b/scripts/_common.sh index ec9aa5c..668cfa3 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -26,32 +26,6 @@ fi GARAGE_VERSION="0.8.2" -# inspired by restic helper -install_garage () { - architecture=$(uname -m) - arch='' - case $architecture in - i386|i686) - arch="i686" - ;; - x86_64) - arch=x86_64 - ;; - armv*) - arch=armv6l - ;; - aarch64) - arch=aarch64 - ;; - *) - echo - ynh_die --message="Unsupported architecture \"$architecture\"" - ;; - esac - wget https://garagehq.deuxfleurs.fr/_releases/v$GARAGE_VERSION/$arch-unknown-linux-musl/garage -O garage 2>&1 >/dev/null - chmod +x garage -} - garage_connect() { local command="$1" local peer="$2" diff --git a/scripts/install b/scripts/install index 99247b2..955446f 100755 --- a/scripts/install +++ b/scripts/install @@ -33,25 +33,12 @@ ynh_app_setting_set --app=$app --key=rpc_secret --value=$rpc_secret ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers ynh_app_setting_set --app=$app --key=weight --value=$weight -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 - -if [ "$virtualisation" = "true" ] -then - ynh_install_app_dependencies $pkg_dependencies_virtualisation -fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -ynh_setup_source --dest_dir="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" chmod +x $install_dir/garage #================================================= diff --git a/scripts/restore b/scripts/restore index 809871e..84f975b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -17,8 +17,6 @@ ynh_script_progression --message="Restoring the app main directory..." --weight ynh_restore_file --origin_path="$install_dir" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" #================================================= @@ -31,8 +29,6 @@ mkdir -p "$data_dir/data" if [ "$virtualisation" = "true" ] then export VIRTUALISATION=true - # Define and install dependencies - ynh_install_app_dependencies $pkg_dependencies_virtualisation # to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size. qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G $install_dir/mount_disk.sh true diff --git a/scripts/upgrade b/scripts/upgrade index bd32ef9..1943280 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,13 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -if [ "$virtualisation" = "true" ] ; -then - virt_protection="" -else - virt_protection="#" -fi - #================================================= # CHECK VERSION #================================================= @@ -31,16 +24,6 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 - -if [ "$virtualisation" = "true" ] -then - ynh_install_app_dependencies $pkg_dependencies_virtualisation -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -48,15 +31,10 @@ fi if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=1 - - # Download, check integrity, uncompress and patch the source from app.src - pushd $install_dir - install_garage - popd + ynh_setup_source --dest_dir="$install_dir" fi -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" +chmod +x $install_dir/garage chown -R $app:$app "$install_dir" #================================================= @@ -85,6 +63,18 @@ ynh_script_progression --message="Upgrading logrotate configuration..." --weigh # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +#================================================= +# UPDATE A CONFIG FILE +#================================================= +### Same as during install +### +### The file will automatically be backed-up if it's found to be manually modified (because +### ynh_add_config keeps track of the file's checksum) +ynh_add_config --template="garage.toml" --destination="$install_dir/garage.toml" + + #================================================= # INTEGRATE SERVICE IN YUNOHOST #=================================================