2022-02-22 13:59:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# In simple cases, you don't need a config script.
|
|
|
|
|
|
|
|
# With a simple config_panel.toml, you can write in the app settings, in the
|
|
|
|
# upstream config file or replace complete files (logo ...) and restart services.
|
|
|
|
|
|
|
|
# The config scripts allows you to go further, to handle specific cases
|
|
|
|
# (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
|
|
|
|
|
2022-02-25 17:05:34 +01:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2022-02-27 21:12:30 +01:00
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2022-02-25 17:05:34 +01:00
|
|
|
|
2022-02-22 13:59:54 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
|
|
|
#=================================================
|
2022-02-27 21:12:30 +01:00
|
|
|
get__readonly_dir() {
|
|
|
|
local directories=$(ynh_app_setting_get $app directories)
|
|
|
|
if [[ "$directories" == "" ]]
|
|
|
|
then
|
|
|
|
echo "choices: []"
|
|
|
|
else
|
|
|
|
echo "choices:"
|
|
|
|
for directory in $(echo $directories | sed "s/,/ /g")
|
|
|
|
do
|
|
|
|
echo " $directory: $directory"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get__unbrowseable() {
|
|
|
|
get__readonly_dir
|
|
|
|
}
|
2022-02-22 13:59:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
2022-02-25 14:04:21 +01:00
|
|
|
set__directories() {
|
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
mkdir -p $final_path/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
|
2022-02-25 17:05:34 +01:00
|
|
|
if ! ynh_permission_exists --permission=$directory ; then
|
|
|
|
ynh_permission_create --permission="$directory" --allowed=all_users --show_tile=false
|
2022-02-25 14:04:21 +01:00
|
|
|
fi
|
2022-02-27 21:12:30 +01:00
|
|
|
|
|
|
|
# Create the directory
|
|
|
|
mkdir -p $datadir/$directory
|
2022-02-25 17:05:34 +01:00
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
chmod 750 "$datadir/$directory"
|
|
|
|
chmod -R o-rwx "$datadir/$directory"
|
|
|
|
chown -R root:root "$datadir/$directory"
|
|
|
|
setfacl -R -m g:samba.$directory:rwx,d:g:samba.$directory:rwx $datadir/$directory
|
2022-02-25 17:05:34 +01:00
|
|
|
|
2022-02-25 14:04:21 +01:00
|
|
|
|
2022-02-27 21:12:30 +01:00
|
|
|
# Add the configuration in /etc/samba/smb.conf if needed
|
|
|
|
cat > $final_path/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
|
2022-02-27 21:12:30 +01:00
|
|
|
path = $datadir/$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
|
|
|
|
vfs objects = dfs_samba4 acl_xattr recycle
|
|
|
|
recycle:repository = .recycle
|
|
|
|
recycle:keeptree = yes
|
|
|
|
recycle:versions = yes
|
2022-02-25 17:05:34 +01:00
|
|
|
END
|
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
|
|
|
|
pushd $final_path/smb.conf.d
|
|
|
|
for $directory in $(ls !(0-global).conf)
|
|
|
|
do
|
|
|
|
if ! [[ "${directory%.conf}" =~ $(echo "^($(echo $directories | sed s/ /|/g))$") ]]; then
|
|
|
|
ynh_secure_remove "$final_path/smb.conf.d/"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
|
|
|
|
cat > $final_path/smb.conf <<EOF
|
2022-02-25 14:04:21 +01:00
|
|
|
# =================================================
|
|
|
|
# DO NOT EDIT THIS FILE
|
|
|
|
# EDIT SUBPARTS IN /etc/samba/smb.conf.d
|
|
|
|
# =================================================
|
|
|
|
|
|
|
|
EOF
|
2022-02-27 21:12:30 +01:00
|
|
|
cat $final_path/smb.conf.d/*.conf >> $final_path/smb.conf
|
2022-02-22 13:59:54 +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
|
|
|
|
#---------------------------------------------
|
2022-02-25 14:04:21 +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
|
|
|
|
for directory in $directories; do
|
|
|
|
value="no"
|
|
|
|
if [[ $directory =~ $(echo "^($(echo $readonly_dir | sed s/ /|/g))$") ]]; then
|
|
|
|
value="yes"
|
|
|
|
fi
|
|
|
|
ynh_write_var_in_file --file=$final_path/smb.conf.d/$directory.conf --key="read only" --value="$value"
|
|
|
|
done
|
|
|
|
ynh_app_setting_set $app readonly_dir $readonly_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
set__unbrowseable() {
|
|
|
|
local value
|
|
|
|
for directory in $directories; do
|
|
|
|
value="yes"
|
|
|
|
if [[ $directory =~ $(echo "^($(echo $unbrowseable | sed s/ /|/g))$") ]]; then
|
|
|
|
value="no"
|
|
|
|
fi
|
|
|
|
ynh_write_var_in_file --file=$final_path/smb.conf.d/$directory.conf --key="browsable" --value="$value"
|
|
|
|
done
|
|
|
|
ynh_app_setting_set $app unbrowseable $unbrowseable
|
|
|
|
|
|
|
|
}
|
2022-02-22 13:59:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
ynh_app_config_run $1
|