mirror of
https://github.com/YunoHost-Apps/samba_ynh.git
synced 2024-09-03 20:16:27 +02:00
[fix] upgrade the smb config for directories questions
This commit is contained in:
parent
14edb35381
commit
673345749a
5 changed files with 87 additions and 60 deletions
27
conf/global-smb.conf
Normal file
27
conf/global-smb.conf
Normal file
|
@ -0,0 +1,27 @@
|
|||
[global]
|
||||
|
||||
log file = /var/log/samba/log.%m
|
||||
max log size = 1000
|
||||
logging = file
|
||||
panic action = /usr/share/samba/panic-action %d
|
||||
|
||||
server role = standalone server
|
||||
|
||||
obey pam restrictions = yes
|
||||
unix password sync = yes
|
||||
passwd program = /usr/bin/passwd %u
|
||||
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
|
||||
pam password change = yes
|
||||
map to guest = bad user
|
||||
|
||||
usershare allow guests = yes
|
||||
browseable = yes
|
||||
|
||||
|
||||
[homes]
|
||||
comment = Home Directories
|
||||
browseable = no
|
||||
read only = no
|
||||
create mask = 0700
|
||||
directory mask = 0700
|
||||
valid users = %S
|
13
conf/shared-smb.conf
Normal file
13
conf/shared-smb.conf
Normal file
|
@ -0,0 +1,13 @@
|
|||
[share]
|
||||
comment = share (D)
|
||||
read only = no
|
||||
path = /home/yunohost.app/samba/share
|
||||
guest ok = no
|
||||
browsable = yes
|
||||
valid users = @samba.share
|
||||
create mask = 0660
|
||||
directory mask = 770
|
||||
vfs objects = dfs_samba4 acl_xattr recycle
|
||||
recycle:repository = .recycle
|
||||
recycle:keeptree = yes
|
||||
recycle:versions = yes
|
|
@ -2,25 +2,28 @@ version = "1.0"
|
|||
|
||||
[main]
|
||||
name = "shared directory"
|
||||
services = ["samba"]
|
||||
|
||||
[main.main]
|
||||
name = ""
|
||||
optional = true
|
||||
|
||||
[main.main.directory]
|
||||
ask = "List of share directory"
|
||||
[main.main.directories]
|
||||
ask = "List of shared directories"
|
||||
type = "tags"
|
||||
pattern.regexp = '^[a-z0-9_]+$'
|
||||
pattern.error = "Directories names can caontain lowercase alphabetic characters, numbers and underscore."
|
||||
|
||||
[main.main.advanced]
|
||||
ask = "Advanced parameter"
|
||||
type = "boolean"
|
||||
|
||||
[main.main.readonly_dir]
|
||||
ask = "List of read only directory"
|
||||
ask = "List of readonly directories"
|
||||
type = "tags"
|
||||
visible = "advanced"
|
||||
|
||||
[main.main.unbrowseable]
|
||||
ask = "List of invisible directory"
|
||||
ask = "List of invisible directories"
|
||||
type = "tags"
|
||||
visible = "advanced"
|
||||
|
|
|
@ -18,82 +18,62 @@ source /usr/share/yunohost/helpers
|
|||
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||
#=================================================
|
||||
|
||||
get__amount() {
|
||||
# Here we can imagine to have an API call to stripe to know the amount of donation during a month
|
||||
local amount = 200
|
||||
|
||||
# It's possible to change some properties of the question by overriding it:
|
||||
if [ $amount -gt 100 ]
|
||||
then
|
||||
cat << EOF
|
||||
style: success
|
||||
value: $amount
|
||||
ask:
|
||||
en: A lot of donation this month: **$amount €**
|
||||
EOF
|
||||
else
|
||||
cat << EOF
|
||||
style: danger
|
||||
value: $amount
|
||||
ask:
|
||||
en: Not so much donation this month: $amount €
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
get__prices() {
|
||||
local prices = "$(grep "DONATION\['" "$final_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
|
||||
if [ "$prices" == "," ];
|
||||
then
|
||||
# Return YNH_NULL if you prefer to not return a value at all.
|
||||
echo YNH_NULL
|
||||
else
|
||||
echo $prices
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||
#=================================================
|
||||
validate__publishable_key() {
|
||||
|
||||
# We can imagine here we test if the key is really a publisheable key
|
||||
(is_secret_key $publishable_key) &&
|
||||
echo 'This key seems to be a secret key'
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||
#=================================================
|
||||
set__prices() {
|
||||
set__directories() {
|
||||
|
||||
mkdir -p /etc/samba/smb.conf.d
|
||||
|
||||
#---------------------------------------------
|
||||
# IMPORTANT: setter are trigger only if a change is detected
|
||||
#---------------------------------------------
|
||||
for price in $(echo $prices | sed "s/,/ /"); do
|
||||
frequency=$(echo $price | cut -d/ -f1)
|
||||
currency=$(echo $price | cut -d/ -f2)
|
||||
price_id=$(echo $price | cut -d/ -f3)
|
||||
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$final_path/settings.py"
|
||||
for directory in $(echo $directories | sed "s/,/ /"); do
|
||||
# Create permission if needed
|
||||
if ! ynh_permission_exists --permission=samba.${directory} ; then
|
||||
ynh_permission_create --permission="samba.${directory}" --allowed=all_users --show_tile=false
|
||||
fi
|
||||
|
||||
# Add the configuration in /etc/samba/smb.conf if needed
|
||||
cat > /etc/samba/smb.conf.d/${directory}.conf <<EOF
|
||||
[${directory}]
|
||||
comment = ${directory}
|
||||
read only = no
|
||||
path = /home/yunohost.app/samba/${directory}
|
||||
guest ok = no
|
||||
browsable = yes
|
||||
valid users = @samba.${directory}
|
||||
create mask = 0660
|
||||
directory mask = 770
|
||||
vfs objects = dfs_samba4 acl_xattr recycle
|
||||
recycle:repository = .recycle
|
||||
recycle:keeptree = yes
|
||||
recycle:versions = yes
|
||||
EOF
|
||||
|
||||
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py"
|
||||
done
|
||||
|
||||
cat > /etc/samba/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
|
||||
|
||||
#---------------------------------------------
|
||||
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
|
||||
#---------------------------------------------
|
||||
ynh_app_setting_set $app prices $prices
|
||||
ynh_app_setting_set $app directories $directories
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -71,7 +71,11 @@ setfacl -R -m g:all_users:rwx,d:g:all_users:rwx $datadir/share
|
|||
#=================================================
|
||||
ynh_script_progression --message="Adding a configuration file..." --time --weight=1
|
||||
|
||||
ynh_add_config --template="smb.conf" --destination="/etc/samba/smb.conf"
|
||||
mkdir -p /etc/samba/smb.conf.d
|
||||
ynh_add_config --template="global-smb.conf" --destination="/etc/samba/smb.conf.d/0-global.conf"
|
||||
ynh_add_config --template="shared-smb.conf" --destination="/etc/samba/smb.conf.d/shared.conf"
|
||||
|
||||
cat /etc/samba/smb.conf.d/*.conf > /etc/samba/smb.conf
|
||||
|
||||
#================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
|
|
Loading…
Reference in a new issue