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:
commit
f8bef699da
3 changed files with 46 additions and 63 deletions
|
@ -2,7 +2,7 @@ version = "1.0"
|
|||
|
||||
[main]
|
||||
name = "shared directory"
|
||||
services = ["samba"]
|
||||
services = ["smbd"]
|
||||
|
||||
[main.main]
|
||||
name = ""
|
||||
|
|
105
scripts/config
105
scripts/config
|
@ -1,10 +1,10 @@
|
|||
#!/bin/bash
|
||||
# In simple cases, you don't need a config script.
|
||||
# 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
|
||||
# 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
|
||||
# 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... ).
|
||||
|
||||
|
@ -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
|
||||
|
@ -59,25 +49,25 @@ set__directories() {
|
|||
for directory in $(echo $directories | sed "s/,/ /g"); do
|
||||
|
||||
# Create yunohost permission
|
||||
if ! ynh_permission_exists --permission=$directory ; then
|
||||
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
|
||||
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
|
||||
# =================================================
|
||||
write_smb_conf
|
||||
|
||||
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
|
||||
#---------------------------------------------
|
||||
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
|
||||
#=================================================
|
||||
|
|
|
@ -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=''
|
||||
|
|
Loading…
Reference in a new issue