summary refs log tree commit diff
path: root/nixos/modules/services/networking/hylafax/spool.sh
blob: 31e930e8c5976de962203488b24f98ae60c64bef (plain) (blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! @shell@ -e

# The following lines create/update the HylaFAX spool directory:
# Subdirectories/files with persistent data are kept,
# other directories/files are removed/recreated,
# mostly from the template spool
# directory in the HylaFAX package.

# This block explains how the spool area is
# derived from the spool template in the HylaFAX package:
#
#                  + capital letter: directory; file otherwise
#                  + P/p: persistent directory
#                  + F/f: directory with symlinks per entry
#                  + T/t: temporary data
#                  + S/s: single symlink into package
#                  |
#                  | + u: change ownership to uucp:uucp
#                  | + U: ..also change access mode to user-only
#                  | |
# archive          P U
# bin              S
# client           T u  (client connection info)
# config           S
# COPYRIGHT        s
# dev              T u  (maybe some FIFOs)
# docq             P U
# doneq            P U
# etc              F    contains customized config files!
# etc/hosts.hfaxd  f
# etc/xferfaxlog   f
# info             P u  (database of called devices)
# log              P u  (communication logs)
# pollq            P U
# recvq            P u
# sendq            P U
# status           T u  (modem status info files)
# tmp              T U


shopt -s dotglob  # if bash sees "*", it also includes dot files
lnsym () { ln --symbol "$@" ; }
lnsymfrc () { ln --symbolic --force "$@" ; }
cprd () { cp --remove-destination "$@" ; }
update () { install --owner=@faxuser@ --group=@faxgroup@ "$@" ; }


## create/update spooling area

update --mode=0750 -d "@spoolAreaPath@"
cd "@spoolAreaPath@"

persist=(archive docq doneq info log pollq recvq sendq)

# remove entries that don't belong here
touch dummy  # ensure "*" resolves to something
for k in *
do
  keep=0
  for j in "${persist[@]}" xferfaxlog clientlog faxcron.lastrun
  do
    if test "$k" == "$j"
    then
      keep=1
      break
    fi
  done
  if test "$keep" == "0"
  then
    rm --recursive "$k"
  fi
done

# create persistent data directories (unless they exist already)
update --mode=0700 -d "${persist[@]}"
chmod 0755 info log recvq

# create ``xferfaxlog``, ``faxcron.lastrun``, ``clientlog``
touch clientlog faxcron.lastrun xferfaxlog
chown @faxuser@:@faxgroup@ clientlog faxcron.lastrun xferfaxlog

# create symlinks for frozen directories/files
lnsym --target-directory=. "@hylafax@"/spool/{COPYRIGHT,bin,config}

# create empty temporary directories
update --mode=0700 -d client dev status
update -d tmp


## create and fill etc

install -d "@spoolAreaPath@/etc"
cd "@spoolAreaPath@/etc"

# create symlinks to all files in template's etc
lnsym --target-directory=. "@hylafax@/spool/etc"/*

# set LOCKDIR in setup.cache
sed --regexp-extended 's|^(UUCP_LOCKDIR=).*$|\1'"'@lockPath@'|g" --in-place setup.cache

# etc/{xferfaxlog,lastrun} are stored in the spool root
lnsymfrc --target-directory=. ../xferfaxlog
lnsymfrc --no-target-directory ../faxcron.lastrun lastrun

# etc/hosts.hfaxd is provided by the NixOS configuration
lnsymfrc --no-target-directory "@userAccessFile@" hosts.hfaxd

# etc/config and etc/config.${DEVID} must be copied:
# hfaxd reads these file after locking itself up in a chroot
cprd --no-target-directory "@globalConfigPath@" config
cprd --target-directory=. "@modemConfigPath@"/*