Nocifer

PKGBUILD

Sep 16th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.92 KB | None | 0 0
  1. # Contributor: Nocifer <apmichalopoulos at gmail dot com>
  2. # Maintainer: Mesmer <mesmer@fisica.if.uff.br>
  3. # Contributor: Troy Will <troydwill at gmail dot com>
  4. # Contributor: /dev/rs0                  </dev/rs0@secretco.de.com>
  5. # Contributor: Jacek Burghardt           <jacek@hebe.us>
  6. # Contributor: Vojtech Aschenbrenner     <v@asch.cz>
  7. # Contributor: Jason Gardner             <buhrietoe@gmail.com>
  8. # Contributor: Ross melin                <rdmelin@gmail.com>
  9. # Contributor (Parabola): Márcio Silva   <coadde@lavabit.com>
  10. # Contributor (Parabola): André Silva    <emulatorman@lavabit.com>
  11. # Contributor: Charles Spence IV         <cspence@unomaha.edu>
  12. # Contributor: Joe Julian                <me@joejulian.name>    
  13. # Orginally based on a Debian Squeeze package
  14.  
  15.  
  16. # Cleaned up the place (unneeded variables, 3-space tabs, hardcoded ZoneMinder-$pkgver references instead of $pkgname-$pkgver ones, wrong upstream URL, wrong license, missing conflict with 'zoneminder-git', etc).
  17. #
  18. # Removed sources for redundant patches as they aren't relevant anymore (source files have been altered and/or already include the patch changes).
  19. #
  20. # Replaced git clone for CakePHP and Crud sources with published precompiled packages, as follows:
  21. # - CakePHP-Enum-Behaviour is pulled from the ZoneMinder repo, because a change is needed that has not yet been merged upstream.
  22. # - Crud is pulled from its official repo, since Pull Request #582 has been merged as required by the ZoneMinder devs.
  23. #
  24. # Adjusted dependencies using as reference the control files for Ubuntu & Debian .deb packages provided by upstream, and also via trial and error (e.g. I couldn't find any mention of perl-crypt-ssleay in any of the official documents, but apparently it's needed otherwise zmupdate.pl complains that LWP::Protocol::https is not installed)
  25. #
  26. # Changed the folder structure a bit (so it would be a good idea to not blindly upgrade an older installation with this PKGBUILD, unless you want to risk being left with redundant and untracked by pacman folders and/or files).
  27. #
  28. # Replaced Apache with Nginx.
  29. #
  30. # ZoneMinder now runs at localhost:8095, instead of localhost/zm (this can be changed by editing the provided Nginx conf file).
  31. #
  32. # Completely overhauled the setup procedure:
  33. # - The install script now takes into account the instructions in the INSTALL file provided by upstream.
  34. # - All extra files (systemd service, systemd tmpfile, server configuration) have been merged into the install script.
  35. # - ZoneMinder now works "out of the box": the database is automatically created, Nginx is automatically configured, PHP-FPM as well.
  36.  
  37. pkgname=zoneminder
  38. pkgver=1.32.0
  39. pkgrel=1
  40. pkgdesc='Free, open source CCTV software which supports IP, USB and Analog cameras.'
  41. arch=('x86_64')
  42. url='http://www.zoneminder.com'
  43. license=('GPLv2')
  44. depends=('polkit' 'ffmpeg' 'libmp4v2' 'mariadb' 'nginx-mainline' 'fcgiwrap' 'php-apcu' 'php-fpm' 'php-gd'
  45.          'perl-archive-zip' 'perl-data-dump' 'perl-date-manip' 'perl-dbd-mysql' 'perl-device-serialport' 'perl-file-slurp' 'perl-image-info'
  46.          'perl-json-any' 'perl-libwww' 'perl-mime-lite' 'perl-mime-tools' 'perl-number-bytes-human' 'perl-sys-meminfo' 'perl-sys-mmap'
  47.          # Needed for ONVIF support
  48.          'perl-class-load' 'perl-data-uuid' 'perl-io-socket-multicast' 'perl-soap-wsdl' 'perl-xml-parser'
  49.          # Needed for SSL support (otherwise zmupdate.pl complains there is no HTTPS support)
  50.          #'perl-crypt-ssleay'
  51.          'perl-lwp-protocol-https'
  52.          # Apparently needed for Telemetry support (...or so says a comment by @ZZdrr on zoneminder-git's AUR page)
  53.          'perl-json-maybexs'
  54.          # Unverified dependencies. So far not installing them hasn't raised any red flags, but I can't be 100% sure whether they're leftovers from previous ZoneMinder incarnations or if they're needed for proper operation during runtime, so for the time being I'm leaving them in.
  55.          'perl-module-load-conditional' 'perl-net-sftp-foreign' 'perl-php-serialization' 'perl-sys-cpu' 'perl-uri-encode')
  56. makedepends=('cmake')
  57. optdepends=('ffmpeg-full: provides many optional features that the official package lacks (including libavresample which ZoneMinder optionally makes use of'
  58.             'vlc: alternative backend instead of ffmpeg (may provide better performance for some cameras)')
  59. conflicts=('zoneminder-git')
  60. backup=("etc/nginx/sites-available/$pkgname.conf")
  61. install=$pkgname.install
  62. source=("https://github.com/ZoneMinder/ZoneMinder/archive/$pkgver.tar.gz"
  63.         "https://github.com/FriendsOfCake/crud/archive/v3.2.0.tar.gz"
  64.         "https://github.com/ZoneMinder/CakePHP-Enum-Behavior/archive/1.0-zm.tar.gz")
  65. sha256sums=('1d5cff0be7eefecdbf8b699220b49a2539427f401da3164eabaa569522843b24'
  66.             '55be29e1eccb44d4ad0db8b23c37cec50f5341f8e498583d472ed1f0493876e3'
  67.             'dbd231e97b950c698f0f501d6a53c7291c9985e766b09e3afe00cfe69a969f44')
  68.  
  69. prepare () {
  70.     # Move extra PHP plugins into place
  71.     cp -R $srcdir/crud-3.2.0/*                          $pkgname-$pkgver/web/api/app/Plugin/Crud
  72.     cp -R $srcdir/CakePHP-Enum-Behavior-1.0-zm/*        $pkgname-$pkgver/web/api/app/Plugin/CakePHP-Enum-Behavior
  73. }
  74.  
  75. build() {
  76.    
  77.     cd $pkgname-$pkgver
  78.    
  79.    # Removed obsolete ZM_PERL_SUBPREFIX
  80.    # Added new ZM_CACHEDIR required by v1.32
  81.     cmake -DCMAKE_INSTALL_PREFIX=/usr \
  82.           -DZM_CONFIG_DIR=/etc/$pkgname \
  83.           -DZM_CONFIG_SUBDIR=/etc/$pkgname/conf.d \
  84.           -DZM_RUNDIR=/run/$pkgname \
  85.           -DZM_SOCKDIR=/run/$pkgname \
  86.           -DZM_LOGDIR=/var/log/$pkgname \
  87.           -DZM_CONTENTDIR=/var/lib/$pkgname \
  88.           -DZM_CACHEDIR=/var/lib/$pkgname/cache \
  89.           -DZM_TMPDIR=/var/lib/$pkgname/temp \
  90.           -DZM_WEBDIR=/srv/$pkgname/www \
  91.           -DZM_CGIDIR=/srv/$pkgname/cgi-bin \
  92.           -DZM_WEB_USER=http .
  93.  
  94.     make
  95. }
  96.      
  97. package() {
  98.    
  99.     cd $pkgname-$pkgver
  100.  
  101.     make DESTDIR=$pkgdir install
  102.    
  103.     # EXTREMELY HACKY solution to make the API work, because so far I haven't been able to translate the Apache .htaccess rewrites into a proper Nginx configuration (at least I *think* that's where the problem lies). This possibly breaks other things in the long run. Needs testing.
  104.     sed -i 's|../../../includes/auth.php|../includes/auth.php|g'        $pkgdir/srv/$pkgname/www/api/app/Controller/AppController.php
  105.     sed -i 's|../../../includes/config.php|../includes/config.php|g'    $pkgdir/srv/$pkgname/www/api/app/Config/bootstrap.php
  106.    
  107.     # Set Polkit directory permissions in accordance with Arch policy
  108.     chmod 750                           $pkgdir/usr/share/polkit-1/rules.d
  109.     chown root:polkitd                  $pkgdir/usr/share/polkit-1/rules.d
  110.    
  111.     # Create ZM_LOGDIR
  112.     mkdir -p                            $pkgdir/var/log/$pkgname
  113.     chown -R http:http                  $pkgdir/var/log/$pkgname
  114.     chmod -R 755                        $pkgdir/var/log/$pkgname
  115.    
  116.     # Create ZM_CONTENTDIR and its subfolders
  117.     mkdir -p                            $pkgdir/var/lib/$pkgname/{cache,events,images,temp}
  118.     chown -R http:http                  $pkgdir/var/lib/$pkgname
  119.     chmod -R 755                        $pkgdir/var/lib/$pkgname
  120.    
  121.     # Run script provided by upstream to create and/or link the needed folders with proper permissions
  122.     ./zmlinkcontent.sh -z $pkgdir/etc/$pkgname/zm.conf -w $pkgdir/srv/$pkgname/www -l $pkgdir/var/log/$pkgname -t $pkgdir/var/lib/$pkgname/temp $pkgdir/var/lib/$pkgname
  123.    
  124.     # Link ZM_CGIDIR inside ZM_WEBDIR and set correct permissions for both of them
  125.     ln -s /srv/$pkgname/cgi-bin         $pkgdir/srv/$pkgname/www
  126.     chown -Rh http:http                 $pkgdir/srv/$pkgname
  127.    
  128.     # Set correct permissions for ZM_CONFIG_DIR & ZM_CONFIG_SUBDIR
  129.     chown -R http:http                  $pkgdir/etc/$pkgname
  130.     chmod -R 755                        $pkgdir/etc/$pkgname
  131.     chmod 644                           $pkgdir/etc/$pkgname/zm.conf
  132.     chmod 644                           $pkgdir/etc/$pkgname/conf.d/*
  133.  
  134.     # Install Nginx configuration
  135.     mkdir -p                            $pkgdir/etc/nginx/sites-{available,enabled}
  136.     cat <<EOF >>                        $pkgdir/etc/nginx/sites-available/$pkgname.conf
  137. server {
  138.     listen 8095;
  139.     server_name localhost;
  140.    
  141.     root /srv/zoneminder/www;
  142.  
  143.     location /cache {
  144.         gzip off;
  145.        
  146.         root /var/lib/zoneminder;
  147.     }
  148.  
  149.     location /cgi-bin {
  150.         gzip off;
  151.        
  152.         include fastcgi_params;
  153.         fastcgi_param SCRIPT_FILENAME \$request_filename;
  154.         fastcgi_intercept_errors on;
  155.         fastcgi_pass unix:/run/fcgiwrap.sock;
  156.     }
  157.    
  158.     location / {
  159.         gzip off;
  160.        
  161.         index index.php;
  162.    
  163.         location /api {
  164.             rewrite ^/api(.+)$ /api/index.php?p=\$1 last;
  165.         }
  166.        
  167.         location ~ \.php$ {
  168.             if (!-f \$request_filename) { return 404; }
  169.            
  170.             expires epoch;
  171.            
  172.             include fastcgi_params;
  173.             fastcgi_param SCRIPT_FILENAME \$request_filename;
  174.             fastcgi_index index.php;
  175.             fastcgi_intercept_errors on;
  176.             fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
  177.         }
  178.        
  179.         location ~ \.(txt|log)$ {
  180.             deny all;
  181.         }
  182.        
  183.         location ~ \.(jpg|jpeg|gif|png|ico)$ {
  184.             access_log off;
  185.             expires 33d;
  186.         }
  187.        
  188.         location ~ \.(m4a|mp4|mov)$ {
  189.             mp4;
  190.             mp4_buffer_size 5M;
  191.             mp4_max_buffer_size 10M;
  192.         }
  193.     }
  194. }
  195. EOF
  196.  
  197.     ln -s /etc/nginx/sites-available/$pkgname.conf      $pkgdir/etc/nginx/sites-enabled/$pkgname.conf
  198.    
  199.    
  200.     # Install systemd service
  201.     # (in the future these hardcoded dependencies could be removed or, even better, a new standalone package could be created for use with remote servers)
  202.     sed -i 's|mysqld.service httpd.service|mariadb.service nginx.service|g' misc/zoneminder.service
  203.     mkdir -p                                            $pkgdir/usr/lib/systemd/system
  204.     install -D -m 644 misc/$pkgname.service             $pkgdir/usr/lib/systemd/system/$pkgname.service
  205.    
  206.    
  207.     # Install systemd tmpfile
  208.     sed -i '3d' misc/zoneminder-tmpfiles.conf
  209.     mkdir -p                                            $pkgdir/usr/lib/tmpfiles.d
  210.     install -D -m 644 misc/$pkgname-tmpfiles.conf       $pkgdir/usr/lib/tmpfiles.d/$pkgname.conf
  211.    
  212.     # Install PHP-FPM custom .ini file
  213.     mkdir -p                                            $pkgdir/etc/php/conf.d/
  214.     cat <<EOF >>                                        $pkgdir/etc/php/conf.d/$pkgname.ini
  215. extension=apcu
  216. extension=ftp
  217. extension=gd
  218. extension=gettext
  219. extension=pdo_mysql
  220. extension=sockets
  221. extension=zip
  222.  
  223. date.timezone = UTC
  224. EOF
  225.  
  226.     # Copy license and database schemas
  227.     install -D -m 644 COPYING                           $pkgdir/usr/share/license/$pkgname
  228.     install -D -m 644 db/zm*.sql                        $pkgdir/usr/share/$pkgname/db
  229. }
Add Comment
Please, Sign In to add comment