mirror of
https://github.com/YunoHost-Apps/samba_ynh.git
synced 2024-09-03 20:16:27 +02:00
Untested config panel
This commit is contained in:
parent
da7a1994dc
commit
a2ec9f4d26
1 changed files with 66 additions and 14 deletions
|
@ -19,10 +19,28 @@ source /usr/share/yunohost/helpers
|
|||
ynh_abort_if_errors
|
||||
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||
#=================================================
|
||||
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
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||
|
@ -33,33 +51,33 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
|||
#=================================================
|
||||
set__directories() {
|
||||
|
||||
mkdir -p /etc/samba/smb.conf.d
|
||||
mkdir -p $final_path/smb.conf.d
|
||||
|
||||
#---------------------------------------------
|
||||
# IMPORTANT: setter are trigger only if a change is detected
|
||||
#---------------------------------------------
|
||||
for directory in $(echo $directories | sed "s/,/ /g"); do
|
||||
|
||||
# Create yunohost permission
|
||||
# Create yunohost permission
|
||||
if ! ynh_permission_exists --permission=$directory ; then
|
||||
ynh_permission_create --permission="$directory" --allowed=all_users --show_tile=false
|
||||
fi
|
||||
|
||||
# Create the directory
|
||||
mkdir -p $datadir/$directory
|
||||
# Create the directory
|
||||
mkdir -p $datadir/$directory
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
# Add the configuration in /etc/samba/smb.conf if needed
|
||||
cat > /etc/samba/smb.conf.d/$directory.conf <<END
|
||||
# Add the configuration in /etc/samba/smb.conf if needed
|
||||
cat > $final_path/smb.conf.d/$directory.conf <<END
|
||||
[$directory]
|
||||
comment = $directory
|
||||
read only = no
|
||||
path = /home/yunohost.app/samba/$directory
|
||||
path = $datadir/$directory
|
||||
guest ok = no
|
||||
browsable = yes
|
||||
valid users = @samba.$directory
|
||||
|
@ -73,14 +91,24 @@ END
|
|||
|
||||
done
|
||||
|
||||
cat > /etc/samba/smb.conf <<EOF
|
||||
# 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
|
||||
# =================================================
|
||||
# DO NOT EDIT THIS FILE
|
||||
# EDIT SUBPARTS IN /etc/samba/smb.conf.d
|
||||
# =================================================
|
||||
|
||||
EOF
|
||||
cat /etc/samba/smb.conf.d/*.conf >> /etc/samba/smb.conf
|
||||
cat $final_path/smb.conf.d/*.conf >> $final_path/smb.conf
|
||||
|
||||
#---------------------------------------------
|
||||
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
|
||||
|
@ -88,6 +116,30 @@ EOF
|
|||
ynh_app_setting_set $app directories $directories
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue