summarylogtreecommitdiffstats
path: root/mx-samba-config-lib.sh
blob: f6fc1cd8d70d178d12a5c9b7314d29ada0caf30e (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash

# Root level functions requiring password for mx-samba-config

enablesamba() {
  systemctl unmask smb
  systemctl unmask nmb
  systemctl enable smb
  systemctl enable nmb
}

disablesamba() {
  systemctl disable smb
  systemctl disable nmb
  systemctl mask smb
  systemctl mask nmb
}

addsambauser() {
  echo -ne "$pass\n$pass" | smbpasswd -as "$user"
  exit $?
}

removesambauser() {
  pdbedit --delete "$user"
  exit $?
}

changesambapasswd() {
  echo -ne "$pass\n$pass" | smbpasswd -U "$user"
  exit $?
}

startsamba() {
  systemctl unmask smb
  systemctl unmask nmb

  systemctl start smb
  systemctl start nmb

  exit $?
}

stopsamba() {
  systemctl stop smb
  systemctl stop nmb
  exit $?
}


main() {
  case $1 in
    startsamba)
      startsamba
      ;;
    stopsamba)
      stopsamba
      ;;
    enablesamba)
      enablesamba
      ;;
    disablesamba)
      disablesamba
      ;;
    addsambauser)
      user="$3"
      pass="$2"
      addsambauser
      ;;
    removesambauser)
      user="$2"
      removesambauser
      ;;
    changesambapasswd)
      user="$3"
      pass="$2"
      changesambapasswd
      ;;
  esac
}

main "$@"