From fb61948453498ece99a310e2a4cf52c5b15201ec Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 6 Jan 2024 19:40:17 +0100 Subject: [PATCH] Simplify the mess about seting up sources, install dir, data dir, plugin dirs ... --- manifest.toml | 1 - scripts/_common.sh | 48 ------------------------------------- scripts/install | 59 +++++++++++++--------------------------------- scripts/upgrade | 50 ++++++++++++++++----------------------- 4 files changed, 37 insertions(+), 121 deletions(-) diff --git a/manifest.toml b/manifest.toml index c17eb2a..0ac2ea9 100644 --- a/manifest.toml +++ b/manifest.toml @@ -78,7 +78,6 @@ ram.runtime = "50M" [resources.install_dir] [resources.data_dir] - subdirs = [ "_data", "upload", "galleries" ] [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index ee67723..05a7907 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,50 +1,2 @@ #!/bin/bash -#================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -# Check available space before creating a temp directory. -# -# usage: ynh_smart_mktemp --min_size="Min size" -# -# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb -ynh_smart_mktemp () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=min_size= ) - local min_size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - min_size="${min_size:-300}" - # Transform the minimum size from megabytes to kilobytes - min_size=$(( $min_size * 1024 )) - - # Check if there's enough free space in a directory - is_there_enough_space () { - local free_space=$(df --output=avail "$1" | sed 1d) - test $free_space -ge $min_size - } - - if is_there_enough_space /tmp; then - local tmpdir=/tmp - elif is_there_enough_space /var; then - local tmpdir=/var - elif is_there_enough_space /; then - local tmpdir=/ - elif is_there_enough_space /home; then - local tmpdir=/home - else - ynh_die "Insufficient free space to continue..." - fi - - echo "$(mktemp --directory --tmpdir="$tmpdir")" -} diff --git a/scripts/install b/scripts/install index 6393436..171929e 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -14,27 +8,29 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Setting up source files..." --weight=5 -# Create tmp directory and fetch app inside -tmpdir="$(ynh_smart_mktemp --min_size=300)" -ynh_setup_source --dest_dir="$tmpdir" - -# Fetch needed plugins -mkdir -p $tmpdir/plugins/Ldap_Login -ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin -ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin - -# sets extended pattern matching options in the bash shell -shopt -s extglob - -# Install files and set permissions -cp -a $tmpdir/!(upload|_data|galleries) $install_dir +ynh_setup_source --dest_dir="$install_dir" +ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin +ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= -# PHP-FPM CONFIGURATION +# CONFIGURE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Initializing data directory..." --weight=1 + +mv $install_dir/_data $data_dir/_data +mv $install_dir/upload $data_dir/upload +mv $install_dir/galleries $data_dir/galleries + +chmod 750 "$data_dir" +chmod -R o-rwx "$data_dir" +chown -R $app:www-data "$data_dir" + +#================================================= +# SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 @@ -42,27 +38,6 @@ ynh_add_fpm_config ynh_add_nginx_config -#================================================= -# SPECIFIC SETUP -#================================================= -# CREATE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Creating a data directory..." --weight=1 - -ln -sd $data_dir/_data $install_dir/_data -ln -sd $data_dir/upload $install_dir/upload -ln -sd $data_dir/galleries $install_dir/galleries - -cp -Rp $tmpdir/_data/. $install_dir/_data -cp -Rp $tmpdir/upload/. $install_dir/upload -cp -Rp $tmpdir/galleries/. $install_dir/galleries - -ynh_secure_remove --file="$tmpdir" - -chmod 750 "$data_dir" -chmod -R o-rwx "$data_dir" -chown -R $app:www-data "$data_dir" - #================================================= # SETUP APPLICATION WITH CURL #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6387fcd..f2e320c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,7 +10,6 @@ else language="en_UK" fi - #================================================= # CHECK VERSION #================================================= @@ -21,42 +20,33 @@ upgrade_type=$(ynh_check_app_version_changed) # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -# sets extended pattern matching options in the bash shell -shopt -s extglob +# Get rid of legacy symlinks +[ -L "$install_dir/_data" ] && ynh_secure_remove "$install_dir/_data" || true +[ -L "$install_dir/galleries" ] && ynh_secure_remove "$install_dir/galleries" || true +[ -L "$install_dir/upload" ] && ynh_secure_remove "$install_dir/upload" || true if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=3 - # Create tmp directory and fetch app inside - tmpdir="$(ynh_smart_mktemp --min_size=300)" - ynh_setup_source --dest_dir="$tmpdir" + ynh_setup_source --dest_dir="$install_dir" + ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin + ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin - # Fetch needed plugins - mkdir -p $tmpdir/plugins/Ldap_Login - ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin - ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin + # We don't want to keep those in the install dir, they already are in $data_dir + if [ -d "$install_dir/_data" ] && [ ! -L "$install_dir/_data" ] + then + ynh_secure_remove "$install_dir/_data" + fi + if [ -d "$install_dir/galleries" ] && [ ! -L "$install_dir/galleries" ] + then + ynh_secure_remove "$install_dir/galleries" + fi + if [ -d "$install_dir/upload" ] && [ ! -L "$install_dir/upload" ] + then + ynh_secure_remove "$install_dir/upload" + fi - # Install files and set permissions - cp -a $tmpdir/!(upload|_data|galleries) $install_dir - - # Backward compatibility: - # If the _data subdirectory wasn't already moved to /home/yunohost.app/$app, - # then move it there - if [ ! -h $install_dir/_data ] ; then - mv $install_dir/_data $data_dir - ln -sd $data_dir/_data $install_dir/_data - fi - - # Backward compatibility: - # If the galleries subdirectory wasn't already moved to /home/yunohost.app/$app, - # then move it there - if [ ! -h $install_dir/galleries ] ; then - mv $install_dir/galleries $data_dir - ln -sd $data_dir/galleries $install_dir/galleries - fi - - ynh_secure_remove --file="$tmpdir" fi chmod 750 "$data_dir"