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

Merge pull request #19 from Hemi03/fix_config

Fix the buged config site
This commit is contained in:
eric_G 2024-05-19 21:43:17 +02:00 committed by GitHub
commit f8bef699da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 63 deletions

View file

@ -2,7 +2,7 @@ version = "1.0"
[main] [main]
name = "shared directory" name = "shared directory"
services = ["samba"] services = ["smbd"]
[main.main] [main.main]
name = "" name = ""

View file

@ -18,40 +18,30 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
datadir=$(ynh_app_setting_get --app=$app --key=datadir) data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#================================================= #=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY # recreate the smb.conf from smb.conf.d
#================================================= #=================================================
get__readonly_dir() { write_smb_conf() {
local directories=$(ynh_app_setting_get $app directories) cat > $install_dir/smb.conf <<EOF
if [[ "$directories" == "" ]] # =================================================
then # DO NOT EDIT THIS FILE
echo "choices: []" # EDIT SUBPARTS IN /etc/samba/smb.conf.d
else # =================================================
echo "choices:"
for directory in $(echo $directories | sed "s/,/ /g") EOF
do cat $install_dir/smb.conf.d/*.conf >> $install_dir/smb.conf
echo " $directory: $directory"
done
fi
} }
get__unbrowseable() {
get__readonly_dir
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
#================================================= #=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS # SPECIFIC SETTERS FOR TOML SHORT KEYS
#================================================= #=================================================
set__directories() { set__directories() {
mkdir -p $final_path/smb.conf.d mkdir -p $install_dir/smb.conf.d
#--------------------------------------------- #---------------------------------------------
# IMPORTANT: setter are trigger only if a change is detected # IMPORTANT: setter are trigger only if a change is detected
@ -64,20 +54,20 @@ set__directories() {
fi fi
# Create the directory # Create the directory
mkdir -p $datadir/$directory mkdir -p $data_dir/$directory
chmod 750 "$datadir/$directory" chmod 750 "$data_dir/$directory"
chmod -R o-rwx "$datadir/$directory" chmod -R o-rwx "$data_dir/$directory"
chown -R root:root "$datadir/$directory" chown -R root:root "$data_dir/$directory"
setfacl -R -m g:samba.$directory:rwx,d:g:samba.$directory:rwx $datadir/$directory setfacl -R -m g:samba.$directory:rwx,d:g:samba.$directory:rwx $data_dir/$directory
# Add the configuration in /etc/samba/smb.conf.d/ if its missing
# Add the configuration in /etc/samba/smb.conf if needed if [ ! -f "$install_dir/smb.conf.d/$directory.conf" ]; then
cat > $final_path/smb.conf.d/$directory.conf <<END cat > $install_dir/smb.conf.d/$directory.conf <<END
[$directory] [$directory]
comment = $directory comment = $directory
read only = no read only = no
path = $datadir/$directory path = $data_dir/$directory
guest ok = no guest ok = no
browsable = yes browsable = yes
valid users = @samba.$directory valid users = @samba.$directory
@ -88,58 +78,51 @@ set__directories() {
recycle:keeptree = yes recycle:keeptree = yes
recycle:versions = yes recycle:versions = yes
END END
fi
done done
# Remove configuration for unlisted directories # Remove configuration for unlisted directories
pushd $final_path/smb.conf.d for directory in $(find $install_dir/smb.conf.d/ -maxdepth 1 -type f -not -name '0-global.conf' -exec basename {} \;); do
for $directory in $(ls !(0-global).conf) if ! [[ "${directory%.conf}" =~ $(echo "^($(echo $directories | sed 's/,\| /|/g'))$") ]]; then
do ynh_secure_remove "$install_dir/smb.conf.d/$directory"
if ! [[ "${directory%.conf}" =~ $(echo "^($(echo $directories | sed s/ /|/g))$") ]]; then
ynh_secure_remove "$final_path/smb.conf.d/"
fi fi
done done
popd
cat > $final_path/smb.conf <<EOF write_smb_conf
# =================================================
# 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
#--------------------------------------------- #---------------------------------------------
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
#--------------------------------------------- #---------------------------------------------
ynh_app_setting_set $app directories $directories ynh_app_setting_set $app directories "$directories"
} }
set__readonly_dir() { set__readonly_dir() {
local value local value
for directory in $directories; do for directory in $(echo $directories | sed "s/,/ /g"); do
value="no" value="no"
if [[ $directory =~ $(echo "^($(echo $readonly_dir | sed s/ /|/g))$") ]]; then if [[ -n "$readonly_dir" && $directory =~ $(echo "^($(echo $readonly_dir | sed 's/,\| /|/g'))$") ]]; then
value="yes" value="yes"
fi fi
ynh_write_var_in_file --file=$final_path/smb.conf.d/$directory.conf --key="read only" --value="$value" ynh_write_var_in_file --file=$install_dir/smb.conf.d/$directory.conf --key=read[[:space:]]only --value="$value"
done done
ynh_app_setting_set $app readonly_dir $readonly_dir ynh_app_setting_set $app readonly_dir "$readonly_dir"
write_smb_conf
} }
set__unbrowseable() { set__unbrowseable() {
local value local value
for directory in $directories; do for directory in $(echo $directories | sed "s/,/ /g"); do
value="yes" value="yes"
if [[ $directory =~ $(echo "^($(echo $unbrowseable | sed s/ /|/g))$") ]]; then if [[ -n "$unbrowseable" && $directory =~ $(echo "^($(echo $unbrowseable | sed 's/,\| /|/g'))$") ]]; then
value="no" value="no"
fi fi
ynh_write_var_in_file --file=$final_path/smb.conf.d/$directory.conf --key="browsable" --value="$value" ynh_write_var_in_file --file=$install_dir/smb.conf.d/$directory.conf --key="browsable" --value="$value"
done done
ynh_app_setting_set $app unbrowseable $unbrowseable ynh_app_setting_set $app unbrowseable "$unbrowseable"
write_smb_conf
} }
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=directories --value=shared ynh_app_setting_set --app=$app --key=directories --value=share
ynh_app_setting_set --app=$app --key=advanced --value=0 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=readonly_dir --value=''
ynh_app_setting_set --app=$app --key=unbrowseable --value='' ynh_app_setting_set --app=$app --key=unbrowseable --value=''