summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 7e2b1d28a88349aae2164f0e77a31e55c0bc4c66 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Category: daemons

# Note: These TODO may not be things I'm planning to fix. Some of them are just
# notes to be fixed by someone else who wants that functionality and warnings
# to those who are expecting that functionality. The HylaFAX+ and AvantFAX
# PKGBUILD have taken many days to get them functional on a modern OS.
# I can't spend a lot more time fixing things I don't use without help.

# TODO: Test receive fax functionality. I only send faxes.
# TODO: Verify timers work
# TODO: Check if Tesseract works
# TODO: Support for HylaFAX in extra (HylaFAX+ on AUR is supported)
# TODO: Less destructive remove or better cleanup.
# TODO: Even safer password storage (the current method is pretty safe)
# TODO: SendEmail or smtp-cli.pl support instead of sendmail
# TODO: We can't use hard links. They won't update as the system updates.
# See avantfaxsetup.sh for more todo

# VERIFIED: Upon remove (and cleanup) 'avantfax' isn't found in /etc /var/spool/hylafax
#  other than in the logs for faxes sent by AvantFAX.
# VERIFIED: AvantFAX integration for HylaFAX+ upgrades

# How to install:
# Setup these parameters
_opt_AUTO_START_HTTP=1 # 1 to automatically enable avantfax and restart apache, 0=manual
_opt_DEBUG_PHP=0       # 1 to show php debug messages, 0 for production
_opt_pagesize='letter' # a4, letter

# Recommended build command: makepkg -scCfi

# With a non set up MySQL or a root password the install will fail.

# sudo vi /usr/bin/avantfaxsetup.sh.password

# Add mysql root password then finish install.

# avantfaxsetup.sh install

# Check settings in /usr/share/webapps/avantfax/includes/local_config.php

# Cleanup: sudo rm -rf /usr/share/webapps/avantfax /root/avantfaxbackup
# Note: Removing the avantfax package is very destructive. It destroys all 
# avantfax files and tables.

set -u
pkgname='avantfax'
_pkgnick="${pkgname}" # 'ArchFAX' # Changing this for an upgrade leaves cruft in many files.
pkgver='3.3.5'
pkgrel='1'
pkgdesc='a web-based application for managing faxes on HylaFAX fax servers'
arch=('any') #('i686' 'x86_64')
url='http://www.avantfax.com/'
license=('GPLv2')
depends=('hylafax' 'sudo' 'ghostscript' 'gsfonts' 'dash'
         'php<6.0' 'apache' 'php-apache<6.0' 'php-pear'
         'pear-mail-mime' 'pear-mail-mime-decode' 'pear-net-smtp'
         'pear-mdb2>=2.5.0b5-1' 'pear-mdb2-mysql>=1.5.0b4-1' 'html2ps' # AUR in May 2015
         'mariadb' 'psutils' 'libtiff' 'libpng' 'imagemagick' 'netpbm' 'giflib'
         )
optdepends=('tesseract: OCR incoming faxes for document keyword searches' # not enabled in local-config, might already work
#            'AvantFAX-support: iFax Solutions can help configure your fax system'
)

# Searching config.php for 'extension_loaded' doesn't show any extensions we need at this time.
# 'php-mysql'    # included in php as 'extension=mysql.so'
# 'php-mbstring' # included in the Arch Linux PKGBUILD configure --enable-mbstring
# 'php-fileinfo' # built in as of php 5.3
# 'libungif'     # no longer supported, seems to be replaced with giflib
# 'vixie-cron'   # replaced with systemd timers. I use cronie.
# 'rsync'        # used only in the manual upgrade scripts. rsync is not used in the package.
#makedepends=('smtp-server') # sendmail isn't required. It can be used on another server.
install='avantfax.install'
_verwatch=("${url}/changelog.php" 'AvantFAX\s\([0-9\.]\+\)\s*' 'f')
source=("http://downloads.sourceforge.net/project/${pkgname}/${pkgname}-${pkgver}.tgz"
        'avantfaxsetup.sh'
        'avantfax.cron.service'
        'avantfax.cron.timer'
        'avantfax.phb.service'
        'avantfax.phb.timer')

sha256sums=('7dc6cfbaea9e27d6ef696611dad79f50cbaa61be6e3b59ce25fa124af0cf1269'
            '615fcba915da20c10614c618dfc6a4d55ed526d2b689947c104102e3cc37e18c'
            '2c633cd03dd234cfbcf6d0530be573e9eaa2b1e92876faa946895bf99bfb3ebc'
            '057be12012e2bd10c8400cac9a2612b9d66ea1535476671f28dbf633c8eb6972'
            '51b4bcf2e26418f8392f765c7d0f363fe3c842ddfbefb8c950f484f4ce4a179a'
            '8a0baba7cfeea3b5e20353677335b923c9333a4d1ab6143b41ca4b2d47449bbd')

prepare() {
  set -u
  cd "${srcdir}/${pkgname}-${pkgver}"
  # chmod 755 *.sh
  # All of the .php files marked as executable need to be executable.
  # find avantfax -executable -type f -name "*.php" -exec chmod 644 {} \;

  if [ "$(vercmp "${pkgver}" '3.3.4')" -le 0 ]; then
    # http://forum.joomla.org/viewtopic.php?t=618315
    # Strict Standards patch, remove & from =&
    sed -i -e 's|^\(\s\+$this->db =\)&\( MDB2::singleton\)|\1\2|g' \
           -e 's|^\(\s\+$res =\)&\( $this->db->query\)|\1\2|g' \
           -e 's|^\(\s\+$this->result =\)&\( $this->db->query\)|\1\2|g' \
           -e 's|^\(\s\+$aff =\)&\( $this->db->exec\)|\1\2|g' \
      "${pkgname}/includes/SQL.php"
    #exit 1
  fi

  if [ "$(vercmp "${pkgver}" '3.3.3')" -le 0 ]; then
    # Patch to bring avantfax into compliance with php5
    # http://sourceforge.net/p/avantfax/discussion/542402/thread/bfe70151/?limit=25
    local _file
    for _file in 'AFUserAccount.php' 'FormRules.php'; do
      sed -i -e 's:^\(\s\+\)private \(function __unset.\+\)$:\1public \2:g' \
             -e 's:^\(\s\+\)private \(function __isset.\+\)$:\1public \2:g' \
             -e 's:^\(\s\+\)private \(function __get.\+\)$:\1public \2:g' \
             -e 's:^\(\s\+\)private \(function __set.\+\)$:\1public \2:g' \
        "${pkgname}/includes/${_file}"
    done

    # This PEAR bug will never be fixed but is also unlikely to be deprecated so we'll supress it.
    # http://pear.php.net/bugs/bug.php?id=17987
    for _file in 'SQL.php' 'MDBO.php'; do
      sed -i -e 's|(\(PEAR::isError\)|(@\1|g' \
        "${pkgname}/includes/${_file}"
    done

    # I don't see a fast way to fix this one so I'll just supress the warning for now.
    sed -i -e 's|\(^\s\+$source_content = \)\(preg_replace\)|\1@\2|g' \
      "${pkgname}/includes/Smarty/Smarty_Compiler.class.php"
  fi
  set +u
}

package () {
  set -u
  local _httpdir='/usr/share/webapps'

  cd "${srcdir}"
  # systemd timer (from the HylaFAX PKGBUILD). No need to install cron.
  install -d -m755 "${pkgdir}/usr/lib/systemd/system/multi-user.target.wants"
  for _i in avantfax*.{timer,service}; do
    install -D -m644 "${_i}" "${pkgdir}/usr/lib/systemd/system/${_i}"
    case "${_i}" in
    # If you're going to do this, it's better to systemctl enable in the install.
    #*.timer) ln -s "../${_i}" "${pkgdir}/usr/lib/systemd/system/multi-user.target.wants/${_i}";;
    *.service) sed -i -e "s:/var/www/avantfax:${_httpdir}/${_pkgnick}:g" "${pkgdir}/usr/lib/systemd/system/${_i}";;
    esac
  done

  cd "${srcdir}/${pkgname}-${pkgver}"

  # Install the main advantfax folder
  install -d -m755 "${pkgdir}${_httpdir}"
  cp -pr "avantfax" "${pkgdir}${_httpdir}/${_pkgnick}"
  install -d -m755 "${pkgdir}${_httpdir}/${_pkgnick}/tmp"

  # Install the SQL scripts
  install -d -m755 "${pkgdir}/usr/lib/${_pkgnick}"
  install -D -m644 *.sql "${pkgdir}/usr/lib/${_pkgnick}"

  # Branding. Too bad this can't be better.
  sed -i -e 's/\(:: AvantFAX LOGIN\) \(::\)/\1 for Arch Linux \2/g' \
    "${pkgdir}${_httpdir}/${_pkgnick}/includes/templates/main_theme/templates/index.tpl"

  # Create our bin dir so we can adhere to open_basedir restrictions
  # The installer will place hard links in here.
  local _bindir="${_httpdir}/${_pkgnick}-bin"
  install -d -m755 "${pkgdir}${_bindir}"

  # Enable debug
  if [ "${_opt_DEBUG_PHP}" -ne 0 ]; then
    sed -i -e "s:^\(\s\+\)\(//\s\+DATABASE\sSETTINGS\$\):\1ini_set('display_errors', true); \2:g" \
      "${pkgdir}${_httpdir}/${_pkgnick}/includes/local_config-example.php"
    sed -i -e "s:^\(\s\+\)\(require_once '\.\./includes/classes\.php';\)\$:\1ini_set('display_errors', true);\n\1\2:g" \
      "${pkgdir}${_httpdir}/${_pkgnick}/index.php"
    sed -i -e "s:^\(\s\+\)\(require_once '\.\./includes/classes\.php';\)\$:\1ini_set('display_errors', true);\n\1\2:g" \
      "${pkgdir}${_httpdir}/${_pkgnick}/admin/index.php"
  fi

  # patch php scripts with our bin dir to comply with php open_basedir
  # Set page size
  sed -i -e 's:/usr/local/bin/:'"${_bindir}/:g" \
         -e 's:/usr/bin:'"${_bindir}:g" \
         -e "s:^\(\s\+\$HYLAFAX_PREFIX\s*=\s*'\)[^']\+\(';\):\1${_bindir}\2:g" \
         -e "s:^\(\s\+\$PAPERSIZE\s*=\s*'\)[^']\+\(';\):\1${_opt_pagesize}\2:g" \
    "${pkgdir}${_httpdir}/${_pkgnick}/includes/local_config-example.php"
  #exit 1

  # The original technique for HYLA being in bin and sbin is hostile to our bin folder
  # Besides, sbin must go
#         -e 's:^\(\s\+error_reporting(E_ALL\)\();\)$:\1 \& ~E_DEPRECATED\2:g' 
  sed -i -e "s:'sbin':'bin':g" \
         -e 's:\($HYLAFAX_PREFIX.DIRECTORY_SEPARATOR.\)'"'bin'.DIRECTORY_SEPARATOR.:\1:g" \
    "${pkgdir}${_httpdir}/${_pkgnick}/includes/config.php"

  # Install Apache vhosts file. It's similar to phpMyAdmin and Adminer.
  install -d -m755 "${pkgdir}/etc/webapps/${_pkgnick}"
  cat > "${pkgdir}/etc/webapps/${_pkgnick}/apache.example.conf" <<EOF
# Installed by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# http://aur.archlinux.org/
Alias /${_pkgnick} "${_httpdir}/${_pkgnick}"
<Directory "${_httpdir}/${_pkgnick}">
  AllowOverride All
  Options FollowSymlinks
  Require all granted
    php_admin_value open_basedir "/tmp/:/usr/share/pear/:${_httpdir}/${_pkgnick}/:${_httpdir}/${_pkgnick}-bin/"
# The AvantFAX installer avantfaxsetup.sh will tack the HylaFAX+ spool folder onto the end
</Directory>
EOF
  install -d -m755 "${pkgdir}/etc/httpd/conf/extra"
  cp -p "${pkgdir}/etc/webapps/${_pkgnick}/apache.example.conf" "${pkgdir}/etc/httpd/conf/extra/httpd-${_pkgnick}.conf"

  # Install, patch, source, and run our setup script
  local _shellfile="${pkgdir}/usr/bin/avantfaxsetup.sh"
  install -d -m755 "${pkgdir}/usr/bin"
  install -D -m755 "${srcdir}/avantfaxsetup.sh" "${_shellfile}"
  # Arch Linux uses bash as sh which allows bashishms through. For strict POSIX shell compliance we use dash.
  sed -i -e 's:^\(_opt_HTTP_DIR\)=.*$'":\1='${_httpdir}':g" \
         -e 's:^\(_opt_VHOSTS\)=.*$'":\1=0:g" \
         -e 's:^\(_opt_AUTO_START_HTTP\)=.*$'":\1=${_opt_AUTO_START_HTTP}:g" \
         -e 's:^\(_opt_AVANTFAX_SERVERNAME\)=.*$'":\1='${_pkgnick}':g" \
         -e 's:^#!/bin/sh$:#!/usr/bin/dash:g' \
    "${_shellfile}"

  # Install php mysql extension
  _opt_SOURCEONLY=1; . "${_shellfile}"; unset _opt_SOURCEONLY
  install -d -m755 "${pkgdir}/etc/php/conf.d"
  cat >> "${pkgdir}/etc/php/conf.d/${_pkgnick}.ini" << EOF
; Installed by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
; http://aur.archlinux.org/
extension=mysql.so
EOF
  chmod 755 "${pkgdir}/etc/php/conf.d"

  # Fix timers to run as user
  local _i
  for _i in "${pkgdir}/usr/lib/systemd/system/"*.service; do
    sed -i -e 's:^#\(User\)=.*$'":\1=${_opt_WWWUSER}:g" \
           -e 's:^#\(Group\)=.*$'":\1=${_opt_WWWGROUP}:g" \
      "${_i}"
  done

  # Install sudo config
  install -d -m750 "${pkgdir}/etc/sudoers.d"
  cat >> "${pkgdir}/etc/sudoers.d/${_pkgnick}.sudo" << EOF
# Installed by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# http://aur.archlinux.org/
${_opt_SUDO_LINE} -u * -p * *  ${_opt_AVANT_CMTTAG}
EOF

  # We run the *modified* shell script
  export _opt_DESTDIR="${pkgdir}"
  "${_shellfile}" 0 'package' # package ignores the flag
  set +u
}

set +u