1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/samba_ynh.git synced 2024-09-03 20:16:27 +02:00
samba_ynh/scripts/install
2022-02-27 20:07:04 +01:00

115 lines
3.9 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path="/etc/samba"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=1
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=1
ynh_app_setting_set --app=$app --key=directories --value=shared
ynh_app_setting_set --app=$app --key=advanced --value=0
ynh_app_setting_set --app=$app --key=readonly_dir --value=''
ynh_app_setting_set --app=$app --key=unbrowseable --value=''
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_exec_warn_less yunohost firewall allow Both 445 --no-upnp
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SETUP SSOWAT
#=================================================
ynh_permission_create --permission="share" --allowed=all_users
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..." --time --weight=1
datadir=/home/yunohost.app/samba
ynh_app_setting_set --app=samba --key=datadir --value=$datadir
mkdir -p $datadir/share
chmod 750 "$datadir/share"
chmod -R o-rwx "$datadir/share"
chown -R root:root "$datadir/share"
setfacl -R -m g:samba.share:rwx,d:g:samba.share:rwx $datadir/share
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --time --weight=1
mkdir -p $final_path/smb.conf.d
ynh_add_config --template="global-smb.conf" --destination="$final_path/smb.conf.d/0-global.conf"
ynh_add_config --template="share-smb.conf" --destination="$final_path/smb.conf.d/share.conf"
cat > $final_path/smb.conf <<EOF
# =================================================
# DO NOT EDIT THIS FILE
# EDIT SUBPARTS IN /etc/samba/smb.conf.d
# =================================================
EOF
cat $final_path/smb.conf.d/*.conf >> $final_path/smb.conf
#================================================
# INTEGRATE SERVICE IN YUNOHOST
#================================================
yunohost service add smbd --description="Samba service" --log="/var/log/smbd/smbd.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
# Start a systemd service
ynh_systemd_action --service_name=smbd --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last