-# update file. note: duplicated in mail-setup.
-# updates $ur u result to true or false
-# updates $reload to true if file updated is in /etc/systemd/system
-u() {
- local tmp tmpdir dest="$1"
- local base="${dest##*/}"
- local dir="${dest%/*}"
- if [[ $dir != "$base" ]]; then
- # dest has a directory component
- mkdir -p "$dir"
- fi
- # shellcheck disable=SC2034 # see comment at top of function
- ur=false # u result
- tmpdir="$(mktemp -d)"
- cat >$tmpdir/"$base"
- tmp=$(rsync -ic $tmpdir/"$base" "$dest")
- if [[ $tmp ]]; then
- printf "%s\n" "$tmp"
- # shellcheck disable=SC2034 # see comment at top of function
- ur=true
- if [[ $dest == /etc/systemd/system/* ]]; then
- # shellcheck disable=SC2034 # see comment at top of function
- reload=true
- fi
- fi
- rm -rf $tmpdir
-}