diff --git a/scripts/_common.sh b/scripts/_common.sh index 7945129..5f535d8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,16 +1,17 @@ #!/bin/bash +user_dir="$data_dir/$ssh_user" + #================================================= # PACKAGE CHECK BYPASSING... #================================================= IS_PACKAGE_CHECK () { - if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ] - then - return 0 - else - return 1 - fi + if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then + return 0 + else + return 1 + fi } #================================================= diff --git a/scripts/backup b/scripts/backup index 74685e9..e6f51da 100644 --- a/scripts/backup +++ b/scripts/backup @@ -25,7 +25,7 @@ ynh_backup --src_path="$install_dir" # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="/home/yunohost.app/ssh_chroot_directories/$ssh_user" --is_big +ynh_backup --src_path="$data_dir/$ssh_user" --is_big #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index b54f2ce..4ccbd1a 100755 --- a/scripts/install +++ b/scripts/install @@ -37,21 +37,10 @@ ynh_script_progression --message="Setting up source files..." --weight=1 ynh_setup_source --dest_dir="$install_dir" +mkdir -p "$data_dir/$ssh_user" + #================================================= # SPECIFIC SETUP -#================================================= -# SOURCE LIBRARIES -#================================================= - -# Load functions quotas_xxx -source "$install_dir/unix_quotas/unix_quotas.sh" - -#================================================= -# CREATE DIRECTORY FOR THIS USER -#================================================= - -mkdir "$data_dir/$ssh_user" - #================================================= # INSTALL QUOTAS SYSTEM #================================================= @@ -59,7 +48,10 @@ ynh_script_progression --message="Install quotas system" --weight=3 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh if ! IS_PACKAGE_CHECK; then - quotas_install + ( + source "$install_dir/unix_quotas/unix_quotas.sh" + quotas_install + ) fi #================================================= @@ -70,11 +62,15 @@ ynh_script_progression --message="Configure fstab to support quotas" --weight=3 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh # Set fstab if ! IS_PACKAGE_CHECK; then - quotas_find_mount_point "$user_dir" - quotas_set_fstab "$quotas_mount_point" + ( + source "$install_dir/unix_quotas/unix_quotas.sh" - # Activate quotas - quotas_activate "$quotas_mount_point" + quotas_find_mount_point "$user_dir" + quotas_set_fstab "$quotas_mount_point" + + # Activate quotas + quotas_activate "$quotas_mount_point" + ) fi #================================================= @@ -101,7 +97,7 @@ fi # ADD A LINK TO CHROOT_MANAGER #================================================= -ln -sf "$install_dir/chroot_manager.sh" /home/yunohost.app/ssh_chroot_directories/chroot_manager +ln -sf "$install_dir/chroot_manager.sh" "$data_dir/chroot_manager" #================================================= # GENERIC FINALIZATION diff --git a/scripts/remove b/scripts/remove index a79ab82..625822a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -11,27 +11,22 @@ source /usr/share/yunohost/helpers #================================================= # SPECIFIC REMOVE -#================================================= -# SOURCE LIBRARIES -#================================================= - -# Load functions quotas_xxx -source "$install_dir/unix_quotas/unix_quotas.sh" - #================================================= # REMOVE QUOTAS OPTIONS IN FSTAB #================================================= ynh_script_progression --message="Remove quotas options in fstab" --weight=3 -user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user" - # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh if ! IS_PACKAGE_CHECK; then - quotas_find_mount_point "$user_dir" - quotas_clean_fstab "$quotas_mount_point" + ( + source "$install_dir/unix_quotas/unix_quotas.sh" - # Deactivate quotas - quotas_deactivate "$quotas_mount_point" + quotas_find_mount_point "$user_dir" + quotas_clean_fstab "$quotas_mount_point" + + # Deactivate quotas + quotas_deactivate "$quotas_mount_point" + ) fi #================================================= @@ -40,7 +35,7 @@ fi ynh_script_progression --message="Remove the user with Chroot_manager" --weight=3 if ! IS_PACKAGE_CHECK; then - "$install_dir/chroot_manager.sh" deluser --name $ssh_user + "$install_dir/chroot_manager.sh" deluser --name "$ssh_user" fi #================================================= @@ -49,7 +44,7 @@ fi # DISCLAIMER #================================================= -ynh_print_info --message="The directory /home/yunohost.app/ssh_chroot_directories hasn't been removed." +ynh_print_info --message="The directory $data_dir hasn't been removed." #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 1a62876..1aeb0cc 100644 --- a/scripts/restore +++ b/scripts/restore @@ -24,17 +24,10 @@ ynh_restore_file --origin_path="$install_dir" #================================================= ynh_script_progression --message="Restoring the data directory..." --weight=1 -ynh_restore_file --origin_path="/home/yunohost.app/ssh_chroot_directories/$ssh_user" --not_mandatory +ynh_restore_file --origin_path="$data_dir/$ssh_user" --not_mandatory #================================================= # SPECIFIC RESTORATION -#================================================= -# SOURCE LIBRARIES -#================================================= - -# Load functions ssh_chroot_xxx -source "$install_dir/ssh_chroot/ssh_chroot.sh" - #================================================= # INSTALL QUOTAS SYSTEM #================================================= @@ -42,7 +35,11 @@ ynh_script_progression --message="Install quotas system" --weight=3 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh if ! IS_PACKAGE_CHECK; then - quotas_install + ( + source "$install_dir/unix_quotas/unix_quotas.sh" + + quotas_install + ) fi #================================================= @@ -53,11 +50,15 @@ ynh_script_progression --message="Configure fstab to support quotas" --weight=3 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh # Set fstab if ! IS_PACKAGE_CHECK; then - quotas_find_mount_point "$user_dir" - quotas_set_fstab "$quotas_mount_point" + ( + source "$install_dir/unix_quotas/unix_quotas.sh" - # Activate quotas - quotas_activate "$quotas_mount_point" + quotas_find_mount_point "$user_dir" + quotas_set_fstab "$quotas_mount_point" + + # Activate quotas + quotas_activate "$quotas_mount_point" + ) fi #================================================= @@ -65,29 +66,31 @@ fi #================================================= ynh_script_progression --message="Update the chroot directory" --weight=3 -user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user" - # https://github.com/maniackcrudelis/ssh_chroot/blob/master/ssh_chroot/ssh_chroot.sh # Build the chroot -ssh_chroot_set_directory "$user_dir" - -# Copy some binaries in the chroot -ssh_chroot_standard_binaries "$user_dir" -ssh_chroot_copy_binary rsync "$user_dir" # Set permissions if ! IS_PACKAGE_CHECK; then - ssh_chroot_set_permissions "$user_dir" $ssh_user + ( + source "$install_dir/ssh_chroot/ssh_chroot.sh" - # Allow the user to use ssh - adduser $ssh_user ssh.app + ssh_chroot_set_directory "$user_dir" + + # Copy some binaries in the chroot + ssh_chroot_standard_binaries "$user_dir" + ssh_chroot_copy_binary rsync "$user_dir" + ssh_chroot_set_permissions "$user_dir" $ssh_user + + # Allow the user to use ssh + adduser $ssh_user ssh.app + ) fi #================================================= # UPDATE THE LINK TO CHROOT_MANAGER #================================================= -ln -sf $install_dir/chroot_manager.sh /home/yunohost.app/ssh_chroot_directories/chroot_manager +ln -sf "$install_dir/chroot_manager.sh" "$data_dir/chroot_manager" #================================================= # SECURE FILES AND DIRECTORIES diff --git a/scripts/upgrade b/scripts/upgrade index 3065ca0..3f8e346 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -44,8 +44,6 @@ source "$install_dir/ssh_chroot/ssh_chroot.sh" #================================================= ynh_script_progression --message="Update the chroot directory" --weight=3 -user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user" - # https://github.com/maniackcrudelis/ssh_chroot/blob/master/ssh_chroot/ssh_chroot.sh # Build the chroot ssh_chroot_set_directory "$user_dir" @@ -67,7 +65,7 @@ fi # UPDATE THE LINK TO CHROOT_MANAGER #================================================= -ln -sf $install_dir/chroot_manager.sh /home/yunohost.app/ssh_chroot_directories/chroot_manager +ln -sf $install_dir/chroot_manager.sh "$data_dir/chroot_manager" # Set permissions to app files chown -R root: $install_dir