#!/bin/bash -eu
# tags: net
source ~/.shell/func.d/cfgsetup

# TODO
#   https://wiki.archlinux.org/index.php/Samba/Tips_and_tricks

## Don't share samba in work network, only at home
cfgOpt f || [[ ${CURR_PROF:?} =~ ^(laptop|home|neo|fractal)$ ]] || die 0 "<Skip>"

echo "N: ATTENTION ! Generate password for samba user !"
if cfgOpt r; then
  sudo smbpasswd -a $(whoami)
fi

if cfgOpt u; then
  ### GENS ###
  ./samba.gen
  # ALT: env-subs -p smb.conf | sudo tee /etc/samba/smb.conf >/dev/null
  # SEE: samba.service -- "Wants network-online"
  svc_activate -erR smb  # MAYBE:ALSO nmbd
  # Once Samba has restarted, use this command
  # to check your smb.conf for any syntax errors
  testparm -s >/dev/null
fi

# EXPL to see errors on start
# sudo smbd -i
# ATTENTION sudo chmod 0755 /var/cache/samba/msg

## Samba >4.5.0
# BUG: crash nmbd:
#  https://bbs.archlinux.org/viewtopic.php?id=216957
#   => downgrading of package tevent 0.9.30 to version 0.9.29 had fixed a problem
# BAD: client can't connect
#  https://bbs.archlinux.org/viewtopic.php?id=217088
#   - Enable NTLMv1 in Samba
#  https://www.samba.org/samba/history/samba-4.5.0.html
