1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh.git synced 2024-09-03 20:26:26 +02:00
ssh_chroot_dir_ynh/scripts/restore

113 lines
3.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_restore_file --origin_path="$data_dir/$ssh_user" --not_mandatory
#=================================================
# SPECIFIC RESTORATION
#=================================================
# INSTALL QUOTAS SYSTEM
#=================================================
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
(
source "$install_dir/unix_quotas/unix_quotas.sh"
quotas_install
)
fi
#=================================================
# CONFIGURE FSTAB TO SUPPORT QUOTAS
#=================================================
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
(
source "$install_dir/unix_quotas/unix_quotas.sh"
quotas_find_mount_point "$user_dir"
quotas_set_fstab "$quotas_mount_point"
# Activate quotas
quotas_activate "$quotas_mount_point"
)
fi
#=================================================
# UPDATE THE CHROOT DIRECTORY
#=================================================
ynh_script_progression --message="Update the chroot directory" --weight=3
# https://github.com/maniackcrudelis/ssh_chroot/blob/master/ssh_chroot/ssh_chroot.sh
# Build the chroot
# Set permissions
if ! IS_PACKAGE_CHECK; then
(
source "$install_dir/ssh_chroot/ssh_chroot.sh"
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" "$data_dir/chroot_manager"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $install_dir
#=================================================
# GENERIC FINALIZATION
#=================================================
# END OF SCRIPT
#=================================================
# Not really settings, but required for POST_INSTALL.md
ynh_app_setting_set --app="$app" --key="domain" --value="$(yunohost domain list --json | jq -r '.["main"]')"
ynh_app_setting_set --app="$app" --key="ssh_port" --value="$(grep "^Port " /etc/ssh/sshd_config | awk '{print $2}')"
ynh_script_progression --message="Restoration completed for $app" --last