summarylogtreecommitdiffstats
path: root/hylafax.install
blob: de9937652a7fcb5374c2e41bbb1c6cc9378d2cbb (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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
_hyhome='/var/spool/hylafax'
_hyfax='/usr/lib/fax'
#_hyuser='fax'
_hyuser='uucp'
_hygroup='uucp'

_print_install() {
  echo -e '\n'
  echo 'Run faxsetup to configure and be sure to set...'
  echo '  The device to configure is usually ttyS0, ttyUSB0, or ttyACM0'
  echo '  The number of pages to accept to more than 25'
  echo '  The country code and area code'
  echo '  The Fax Class to 1 or 1.0' # I can find no modem reliable at Class 2*
  echo '  Most other defaults are OK'
  echo -e '\n'
}

_print_remove() {
  echo -e '\n\n'
  echo "You may manually remove ${_hyhome} and ${_hyfax} if you do not need anything."
  echo 'You may also remove any aliases added to /etc/mail/aliases.'
  echo -e '\n'
}

post_install() {
  set -u
  #groupadd -g 14 "${_hygroup}" &>/dev/null
  useradd -u 10 -g "${_hygroup}" -d "${_hyhome}" -s '/bin/false' "${_hyuser}" &>/dev/null
  #useradd -u 69 -g 'daemon' -d '/' -s '/bin/false' 'fax' &>/dev/null
  post_upgrade
  #usermod -d '/' "${_hyuser}" &>/dev/null
  _print_install
  mandb -q
  set +u
}

# define _clean_or_copy_doit() to tell this what to do
_clean_or_copy() {
  for _outfile in 'archive' 'faxrcvd' 'notify' 'pollrcvd'; do
    _clean_or_copy_doit "${_hyhome}/bin/${_outfile}.hylafaxplus.default" "${_hyhome}/bin/${_outfile}"
  done
  for _outfile in ${_hyhome}/etc/*.default; do
    _clean_or_copy_doit "${_outfile}" "$(expr "${_outfile}" : '^\(.\+\).default$')"
  done
}

post_upgrade() {
  set -u
  /usr/bin/sh "${_hyhome}/bin/_install_chown.sh"
  # Only some of the files and folders are chown
  chown "${_hyuser}:${_hygroup}" "${_hyhome}"/{,archive,bin,client,config,dev,docq,doneq,etc}
  chown "${_hyuser}:${_hygroup}" "${_hyhome}"/{info,log,pollq,recvq,sendq,status,tmp}
  chown "${_hyuser}:${_hygroup}" "${_hyhome}/FIFO" "${_hyhome}"/FIFO.* 2> /dev/null
  # Don't overwrite existing configuration files.
  _clean_or_copy_doit() {
    cp -np "$1" "$2"
    chmod 'u+w' "$2"
  }
  _clean_or_copy

  cp -n /dev/null "${_hyhome}/etc/xferfaxlog" # This doesn't modify the timestamp of an existing file
  chown "${_hyuser}:${_hygroup}" "${_hyhome}/etc"/{hosts.hfaxd,lutRS18.pcf,xferfaxlog}
  # chown -R "${_hyuser}:${_hygroup}"\ "${_hyhome}/etc/templates"
  systemctl daemon-reload
  systemctl enable 'hylafax.timer'
  systemctl start 'hylafax.timer'
  # Now done by pacman hook
  #if [ ! -z "$(command -v 'avantfaxsetup.sh')" ]; then
  #  avantfaxsetup.sh 2 'install'
  #fi
  set +u
}

_pre_upgrade_fix_faxcover() {
  # Two fax covers in different places causes problems. Since I didn't notice this before I can't trash the covers
  if [ ! -L "${_hyfax}/faxcover.ps" ]; then
    if [ "$(md5sum < "${_hyfax}/faxcover.ps" | cut -d' ' -f1)" != '756ff1ce327f89d5651cdb99f02efc25' ]; then
      if [ "$(md5sum < "${_hyhome}/etc/cover.templ")" = "$(md5sum < "${_hyhome}/etc/cover.templ.default")" ]; then
        mv "${_hyfax}/faxcover.ps" "${_hyhome}/etc/cover.templ"
      else
        mv "${_hyfax}/faxcover.ps"{,.pacsave}
        echo "Modified faxcover.ps has been saved as ${_hyfax}/faxcover.ps.pacsave"
      fi
    fi
  fi
}

pre_upgrade() {
  set -u
  _pre_upgrade_fix_faxcover
  _clean_or_copy_doit() {
    # Delete unmodified files
    if [ "$(md5sum < "$1")" = "$(md5sum < "$2")" ]; then
      rm -f "$2"
    fi
  }
  _clean_or_copy
  set +u
}

pre_remove() {
  set -u
  pre_upgrade
  userdel "${_hyuser}" &>/dev/null
  ##groupdel "${_hygroup}" &>/dev/null
  # we could put this into pre_upgrade() but I'd rather let the admin restart when convenient.
  systemctl stop 'hfaxd.service'
  systemctl disable 'hfaxd.service'
  systemctl stop 'faxq.service'
  systemctl disable 'faxq.service'
  systemctl stop 'faxgetty@*.service'
  rm -f '/etc/systemd/system/multi-user.target.wants'/faxgetty@*.service # systemctl disable doesn't accept wildcards/PATTERN
  systemctl stop 'hylafax.timer'
  systemctl disable 'hylafax.timer'
  #rm -f "${_hyhome}/bin"/{pdf2fax,ps2fax} "${_hyhome}/dev/null"
  _print_remove
  set +u
}

post_remove() {
  set -u
  systemctl daemon-reload
  mandb -q
  set +u
}