2022-02-22 13:59:54 +01:00
|
|
|
#!/bin/bash
|
2024-03-29 05:42:41 +01:00
|
|
|
# In simple cases, you don't need a config script.
|
2022-02-22 13:59:54 +01:00
|
|
|
|
2024-03-29 05:42:41 +01:00
|
|
|
# With a simple config_panel.toml, you can write in the app settings, in the
|
2022-02-22 13:59:54 +01:00
|
|
|
# upstream config file or replace complete files (logo ...) and restart services.
|
|
|
|
|
2024-03-29 05:42:41 +01:00
|
|
|
# The config scripts allows you to go further, to handle specific cases
|
2022-02-22 13:59:54 +01:00
|
|
|
# (validation of several interdependent fields, specific getter/setter for a value,
|
|
|
|
# display dynamic informations or choices, pre-loading of config type .cube... ).
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2024-03-26 19:15:31 +01:00
|
|
|
data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
|
|
|
|
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
2022-02-25 17:05:34 +01:00
|
|
|
|
2024-03-29 05:44:08 +01:00
|
|
|
#=================================================
|
|
|
|
# recreate the smb.conf from smb.conf.d
|
|
|
|
#=================================================
|
|
|
|
write_smb_conf() {
|
|
|
|
cat > $install_dir/smb.conf <<EOF
|
|
|
|
# =================================================
|
|
|
|
# DO NOT EDIT THIS FILE
|
|
|
|
# EDIT SUBPARTS IN /etc/samba/smb.conf.d
|
|
|
|
# =================================================
|
|
|
|
|
|
|
|
EOF
|
|
|
|
cat $install_dir/smb.conf.d/*.conf >> $install_dir/smb.conf
|
|
|
|
}
|
2022-02-22 13:59:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
2022-02-25 14:04:21 +01:00
|
|
|
set__directories() {
|
|
|
|
|
2024-03-26 19:15:31 +01:00
|
|
|
mkdir -p $install_dir/smb.conf.d
|
2022-02-22 13:59:54 +01:00
|
|
|
|
|
|
|
#---------------------------------------------
|
|
|
|
# IMPORTANT: setter are trigger only if a change is detected
|
|
|
|
#---------------------------------------------
|
2022-02-25 17:05:34 +01:00
|
|
|
for directory in $(echo $directories | sed "s/,/ /g"); do
|
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
# Create yunohost permission
|
2024-03-29 05:44:08 +01:00
|
|
|
if ! ynh_permission_exists --permission=$directory ; then
|
2022-02-25 17:05:34 +01:00
|
|
|
ynh_permission_create --permission="$directory" --allowed=all_users --show_tile=false
|
2022-02-25 14:04:21 +01:00
|
|
|
fi
|
2024-03-29 05:44:08 +01:00
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
# Create the directory
|
2024-03-26 19:15:31 +01:00
|
|
|
mkdir -p $data_dir/$directory
|
2022-02-25 17:05:34 +01:00
|
|
|
|
2024-03-26 19:15:31 +01:00
|
|
|
chmod 750 "$data_dir/$directory"
|
|
|
|
chmod -R o-rwx "$data_dir/$directory"
|
|
|
|
chown -R root:root "$data_dir/$directory"
|
|
|
|
setfacl -R -m g:samba.$directory:rwx,d:g:samba.$directory:rwx $data_dir/$directory
|
2022-02-25 17:05:34 +01:00
|
|
|
|
2024-03-29 20:00:29 +01:00
|
|
|
# Add the configuration in /etc/samba/smb.conf.d/ if its missing
|
|
|
|
if [ ! -f "$install_dir/smb.conf.d/$directory.conf" ]; then
|
|
|
|
cat > $install_dir/smb.conf.d/$directory.conf <<END
|
2022-02-25 17:05:34 +01:00
|
|
|
[$directory]
|
|
|
|
comment = $directory
|
2022-02-25 14:04:21 +01:00
|
|
|
read only = no
|
2024-03-26 19:15:31 +01:00
|
|
|
path = $data_dir/$directory
|
2022-02-25 14:04:21 +01:00
|
|
|
guest ok = no
|
|
|
|
browsable = yes
|
2022-02-25 17:05:34 +01:00
|
|
|
valid users = @samba.$directory
|
2022-02-25 14:04:21 +01:00
|
|
|
create mask = 0660
|
|
|
|
directory mask = 770
|
2024-08-25 15:30:00 +02:00
|
|
|
vfs objects = acl_xattr recycle
|
2022-02-25 14:04:21 +01:00
|
|
|
recycle:repository = .recycle
|
|
|
|
recycle:keeptree = yes
|
|
|
|
recycle:versions = yes
|
2022-02-25 17:05:34 +01:00
|
|
|
END
|
2024-03-29 20:00:29 +01:00
|
|
|
fi
|
2022-02-22 13:59:54 +01:00
|
|
|
|
|
|
|
done
|
2022-02-25 14:04:21 +01:00
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
# Remove configuration for unlisted directories
|
2024-03-28 23:25:40 +01:00
|
|
|
for directory in $(find $install_dir/smb.conf.d/ -maxdepth 1 -type f -not -name '0-global.conf' -exec basename {} \;); do
|
2024-03-27 02:07:22 +01:00
|
|
|
if ! [[ "${directory%.conf}" =~ $(echo "^($(echo $directories | sed 's/,\| /|/g'))$") ]]; then
|
2024-03-28 23:25:40 +01:00
|
|
|
ynh_secure_remove "$install_dir/smb.conf.d/$directory"
|
2022-02-27 21:12:30 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-03-29 05:44:08 +01:00
|
|
|
write_smb_conf
|
2022-02-25 14:04:21 +01:00
|
|
|
|
2022-02-25 17:05:34 +01:00
|
|
|
#---------------------------------------------
|
|
|
|
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
|
|
|
|
#---------------------------------------------
|
2024-03-29 05:45:14 +01:00
|
|
|
ynh_app_setting_set $app directories "$directories"
|
2022-02-22 13:59:54 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
set__readonly_dir() {
|
|
|
|
local value
|
2024-03-26 23:08:45 +01:00
|
|
|
for directory in $(echo $directories | sed "s/,/ /g"); do
|
2022-02-27 21:12:30 +01:00
|
|
|
value="no"
|
2024-03-29 05:45:14 +01:00
|
|
|
if [[ -n "$readonly_dir" && $directory =~ $(echo "^($(echo $readonly_dir | sed 's/,\| /|/g'))$") ]]; then
|
2022-02-27 21:12:30 +01:00
|
|
|
value="yes"
|
|
|
|
fi
|
2024-03-29 05:45:36 +01:00
|
|
|
ynh_write_var_in_file --file=$install_dir/smb.conf.d/$directory.conf --key=read[[:space:]]only --value="$value"
|
2022-02-27 21:12:30 +01:00
|
|
|
done
|
2024-03-29 05:45:14 +01:00
|
|
|
ynh_app_setting_set $app readonly_dir "$readonly_dir"
|
2024-03-29 05:44:08 +01:00
|
|
|
write_smb_conf
|
2022-02-27 21:12:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set__unbrowseable() {
|
|
|
|
local value
|
2024-03-26 23:08:45 +01:00
|
|
|
for directory in $(echo $directories | sed "s/,/ /g"); do
|
2022-02-27 21:12:30 +01:00
|
|
|
value="yes"
|
2024-03-29 05:45:14 +01:00
|
|
|
if [[ -n "$unbrowseable" && $directory =~ $(echo "^($(echo $unbrowseable | sed 's/,\| /|/g'))$") ]]; then
|
2022-02-27 21:12:30 +01:00
|
|
|
value="no"
|
|
|
|
fi
|
2024-03-26 19:15:31 +01:00
|
|
|
ynh_write_var_in_file --file=$install_dir/smb.conf.d/$directory.conf --key="browsable" --value="$value"
|
2022-02-27 21:12:30 +01:00
|
|
|
done
|
2024-03-29 05:45:14 +01:00
|
|
|
ynh_app_setting_set $app unbrowseable "$unbrowseable"
|
2024-03-29 05:44:08 +01:00
|
|
|
write_smb_conf
|
2022-02-27 21:12:30 +01:00
|
|
|
}
|
2024-03-29 05:45:14 +01:00
|
|
|
|
2022-02-22 13:59:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
ynh_app_config_run $1
|