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]
name = "shared directory"
services = ["samba"]
services = ["smbd"]
[main.main]
name = ""

View file

@ -18,40 +18,30 @@ 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)
data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
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() {
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
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
}
get__unbrowseable() {
get__readonly_dir
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
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
@ -64,20 +54,20 @@ set__directories() {
fi
# Create the directory
mkdir -p $datadir/$directory
mkdir -p $data_dir/$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 "$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
# Add the configuration in /etc/samba/smb.conf if needed
cat > $final_path/smb.conf.d/$directory.conf <<END
# 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
[$directory]
comment = $directory
read only = no
path = $datadir/$directory
path = $data_dir/$directory
guest ok = no
browsable = yes
valid users = @samba.$directory
@ -88,58 +78,51 @@ set__directories() {
recycle:keeptree = yes
recycle:versions = yes
END
fi
done
# 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/"
for directory in $(find $install_dir/smb.conf.d/ -maxdepth 1 -type f -not -name '0-global.conf' -exec basename {} \;); do
if ! [[ "${directory%.conf}" =~ $(echo "^($(echo $directories | sed 's/,\| /|/g'))$") ]]; then
ynh_secure_remove "$install_dir/smb.conf.d/$directory"
fi
done
popd
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
write_smb_conf
#---------------------------------------------
# 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() {
local value
for directory in $directories; do
for directory in $(echo $directories | sed "s/,/ /g"); do
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"
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
ynh_app_setting_set $app readonly_dir $readonly_dir
ynh_app_setting_set $app readonly_dir "$readonly_dir"
write_smb_conf
}
set__unbrowseable() {
local value
for directory in $directories; do
for directory in $(echo $directories | sed "s/,/ /g"); do
value="yes"
if [[ $directory =~ $(echo "^($(echo $unbrowseable | sed s/ /|/g))$") ]]; then
if [[ -n "$unbrowseable" && $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"
ynh_write_var_in_file --file=$install_dir/smb.conf.d/$directory.conf --key="browsable" --value="$value"
done
ynh_app_setting_set $app unbrowseable $unbrowseable
ynh_app_setting_set $app unbrowseable "$unbrowseable"
write_smb_conf
}
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#=================================================
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=readonly_dir --value=''
ynh_app_setting_set --app=$app --key=unbrowseable --value=''