1#! @runtimeShell@ -e
2
3# The following lines create/update the HylaFAX spool directory:
4# Subdirectories/files with persistent data are kept,
5# other directories/files are removed/recreated,
6# mostly from the template spool
7# directory in the HylaFAX package.
8
9# This block explains how the spool area is
10# derived from the spool template in the HylaFAX package:
11#
12# + capital letter: directory; file otherwise
13# + P/p: persistent directory
14# + F/f: directory with symlinks per entry
15# + T/t: temporary data
16# + S/s: single symlink into package
17# |
18# | + u: change ownership to uucp:uucp
19# | + U: ..also change access mode to user-only
20# | |
21# archive P U
22# bin S
23# client T u (client connection info)
24# config S
25# COPYRIGHT s
26# dev T u (maybe some FIFOs)
27# docq P U
28# doneq P U
29# etc F contains customized config files!
30# etc/hosts.hfaxd f
31# etc/xferfaxlog f
32# info P u (database of called devices)
33# log P u (communication logs)
34# pollq P U
35# recvq P u
36# sendq P U
37# status T u (modem status info files)
38# tmp T U
39
40
41shopt -s dotglob # if bash sees "*", it also includes dot files
42lnsym () { ln --symbol "$@" ; }
43lnsymfrc () { ln --symbolic --force "$@" ; }
44cprd () { cp --remove-destination "$@" ; }
45update () { install --owner=@faxuser@ --group=@faxgroup@ "$@" ; }
46
47
48## create/update spooling area
49
50update --mode=0750 -d "@spoolAreaPath@"
51cd "@spoolAreaPath@"
52
53persist=(archive docq doneq info log pollq recvq sendq)
54
55# remove entries that don't belong here
56touch dummy # ensure "*" resolves to something
57for k in *
58do
59 keep=0
60 for j in "${persist[@]}" xferfaxlog clientlog faxcron.lastrun
61 do
62 if test "$k" == "$j"
63 then
64 keep=1
65 break
66 fi
67 done
68 if test "$keep" == "0"
69 then
70 rm --recursive "$k"
71 fi
72done
73
74# create persistent data directories (unless they exist already)
75update --mode=0700 -d "${persist[@]}"
76chmod 0755 info log recvq
77
78# create ``xferfaxlog``, ``faxcron.lastrun``, ``clientlog``
79touch clientlog faxcron.lastrun xferfaxlog
80chown @faxuser@:@faxgroup@ clientlog faxcron.lastrun xferfaxlog
81
82# create symlinks for frozen directories/files
83lnsym --target-directory=. "@hylafaxplus@"/spool/{COPYRIGHT,bin,config}
84
85# create empty temporary directories
86update --mode=0700 -d client dev status
87update -d tmp
88
89
90## create and fill etc
91
92install -d "@spoolAreaPath@/etc"
93cd "@spoolAreaPath@/etc"
94
95# create symlinks to all files in template's etc
96lnsym --target-directory=. "@hylafaxplus@/spool/etc"/*
97
98# set LOCKDIR in setup.cache
99sed --regexp-extended 's|^(UUCP_LOCKDIR=).*$|\1'"'@lockPath@'|g" --in-place setup.cache
100
101# etc/{xferfaxlog,lastrun} are stored in the spool root
102lnsymfrc --target-directory=. ../xferfaxlog
103lnsymfrc --no-target-directory ../faxcron.lastrun lastrun
104
105# etc/hosts.hfaxd is provided by the NixOS configuration
106lnsymfrc --no-target-directory "@userAccessFile@" hosts.hfaxd
107
108# etc/config and etc/config.${DEVID} must be copied:
109# hfaxd reads these file after locking itself up in a chroot
110cprd --no-target-directory "@globalConfigPath@" config
111cprd --target-directory=. "@modemConfigPath@"/*