summarylogtreecommitdiffstats
path: root/samba-support.install
blob: 4223edc8dca8b9f6c281501145f4df5f7c07d290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
add_users() {
    _l="/etc/login.defs"
    _p="/etc/passwd"
 
    ## get mini UID limit ##
    l=$(grep "^UID_MIN" $_l)
 
    ## get max UID limit ##
    l1=$(grep "^UID_MAX" $_l)
 
    ## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin   ##
    users=$(awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max  && $7 != "/sbin/nologin" ) print $0 }' "$_p" | cut -d: -f1)
    for i in $users; do
        echo "Adding user '$i' to user-group 'sambashare'"
        usermod -a -G sambashare $i
    done
}

add_group() {
    getent group "sambashare" &>/dev/null || groupadd -r sambashare
    add_users
    chgrp sambashare var/lib/samba/usershare
}

post_upgrade() {
    add_group
}

post_install() {
    systemctl is-active smb >/dev/null || systemctl enable smb
    systemctl is-active nmb >/dev/null || systemctl enable nmb
    systemctl is-active avahi-daemon >/dev/null || systemctl enable avahi-daemon
    add_group
}

post_remove() {
    ! systemctl is-enabled smb >/dev/null || systemctl disable smb
    ! systemctl is-enabled nmb >/dev/null || systemctl disable nmb
    ! getent group sambashare || groupdel sambashare
}