Advertisement
Guest User

PKGBUILD

a guest
Sep 16th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.86 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.
  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="Record, analyze and monitor CCTV cameras"
  41. arch=('x86_64')
  42. url="http://www.zoneminder.com"
  43. license=('GPL2')
  44. depends=('gnutls' 'polkit' 'ffmpeg' 'libmp4v2' 'fcgiwrap' 'mariadb' 'nginx-mainline' 'php-apcu' 'php-fpm' 'php-gd'
  45.          'perl-date-manip' 'perl-mime-lite' 'perl-mime-tools' 'perl-dbd-mysql' 'perl-archive-zip' 'perl-device-serialport' 'perl-image-info' 'perl-json-any'
  46.          'perl-libwww' 'perl-data-dump' 'perl-number-bytes-human' 'perl-file-slurp' 'perl-sys-meminfo' 'perl-sys-mmap'
  47.          'perl-class-load' 'perl-data-uuid' 'perl-io-socket-multicast' 'perl-soap-wsdl' 'perl-xml-parser'
  48.          # Possible dependencies. They have not raised any red flags so far but I'm not 100% sure whether they're leftovers from previous ZoneMinder incarnations or if they're needed for proper runtime operation. For the time being I'm leaving them in.
  49.          'perl-php-serialization' 'perl-module-load-conditional' 'perl-net-sftp-foreign' 'perl-json-maybexs' 'perl-uri-encode' 'perl-sys-cpu')
  50. makedepends=('cmake')
  51. conflict=('zoneminder-git')
  52. install=$pkgname.install
  53. source=("https://github.com/ZoneMinder/ZoneMinder/archive/$pkgver.tar.gz"
  54.         "https://github.com/ZoneMinder/CakePHP-Enum-Behavior/archive/1.0-zm.tar.gz"
  55.         "https://github.com/FriendsOfCake/crud/archive/v3.2.0.tar.gz")
  56. sha256sums=('1d5cff0be7eefecdbf8b699220b49a2539427f401da3164eabaa569522843b24'
  57.             'dbd231e97b950c698f0f501d6a53c7291c9985e766b09e3afe00cfe69a969f44'
  58.             '55be29e1eccb44d4ad0db8b23c37cec50f5341f8e498583d472ed1f0493876e3')
  59.  
  60. prepare () {
  61.     tar -zx -C $srcdir/$pkgname-$pkgver/web/api/app/Plugin/CakePHP-Enum-Behavior -f 1.0-zm.tar.gz --strip 1
  62.     tar -zx -C $srcdir/$pkgname-$pkgver/web/api/app/Plugin/Crud -f v3.2.0.tar.gz --strip 1
  63. }
  64.  
  65. build() {
  66.    
  67.     cd $pkgname-$pkgver
  68.    
  69.     # Added new ZM_CACHEDIR as required for v1.32.0
  70.     cmake -DCMAKE_INSTALL_PREFIX=/usr \
  71.           -DZM_CONFIG_DIR=/etc/$pkgname \
  72.           -DZM_CONFIG_SUBDIR=/etc/$pkgname/conf.d \
  73.           -DZM_RUNDIR=/run/$pkgname \
  74.           -DZM_SOCKDIR=/run/$pkgname \
  75.           -DZM_LOGDIR=/var/log/$pkgname \
  76.           -DZM_CONTENTDIR=/var/lib/$pkgname \
  77.           -DZM_CACHEDIR=/var/lib/$pkgname/cache \
  78.           -DZM_TMPDIR=/var/lib/$pkgname/temp \
  79.           -DZM_WEBDIR=/srv/$pkgname/www \
  80.           -DZM_CGIDIR=/srv/$pkgname/cgi-bin \
  81.           -DZM_WEB_USER=http .
  82.        
  83.     make
  84. }
  85.      
  86. package() {
  87.    
  88.     cd $pkgname-$pkgver
  89.  
  90.     make DESTDIR=$pkgdir install
  91.    
  92.     # 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.
  93.     sed -i 's|../../../includes/auth.php|../includes/auth.php|g'        $pkgdir/srv/$pkgname/www/api/app/Controller/AppController.php
  94.     sed -i 's|../../../includes/config.php|../includes/config.php|g'    $pkgdir/srv/$pkgname/www/api/app/Config/bootstrap.php
  95.    
  96.     # Set Polkit directory permissions in accordance with Arch policy
  97.     chmod 750                           $pkgdir/usr/share/polkit-1/rules.d
  98.     chown root:polkitd                  $pkgdir/usr/share/polkit-1/rules.d
  99.    
  100.     # Create ZM_LOGDIR
  101.     mkdir -p                            $pkgdir/var/log/$pkgname
  102.     chown -R http:http                  $pkgdir/var/log/$pkgname
  103.     chmod -R 755                        $pkgdir/var/log/$pkgname
  104.    
  105.     # Create ZM_CONTENTDIR and its subfolders
  106.     mkdir -p                            $pkgdir/var/lib/$pkgname/{cache,events,images,temp}
  107.     chown -R http:http                  $pkgdir/var/lib/$pkgname
  108.     chmod -R 755                        $pkgdir/var/lib/$pkgname
  109.    
  110.     # Run script provided by upstream to create and/or link the needed folders with correct permissions.
  111.     ./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
  112.    
  113.     # Link ZM_CGIDIR inside ZM_WEBDIR and set correct permissions for both of them
  114.     ln -s /srv/$pkgname/cgi-bin         $pkgdir/srv/$pkgname/www
  115.     chown -Rh http:http                 $pkgdir/srv/$pkgname
  116.    
  117.     # Set correct permissions for ZM_CONFIG_DIR & ZM_CONFIG_SUBDIR
  118.     chown -R http:http                  $pkgdir/etc/$pkgname
  119.     chmod -R 755                        $pkgdir/etc/$pkgname
  120.     chmod 644                           $pkgdir/etc/$pkgname/zm.conf
  121.     chmod 644                           $pkgdir/etc/$pkgname/conf.d/*
  122.  
  123.    
  124.     # Nginx
  125.     mkdir -p                            $pkgdir/etc/nginx/sites-{available,enabled}
  126.     cat <<EOF >>                        $pkgdir/etc/nginx/sites-available/$pkgname.conf
  127. server {
  128.     listen 8095;
  129.     server_name localhost;
  130.    
  131.     root /srv/zoneminder/www;
  132.  
  133.     location /cache {
  134.         gzip off;
  135.        
  136.         root /var/lib/zoneminder;
  137.     }
  138.  
  139.     location /cgi-bin {
  140.         gzip off;
  141.        
  142.         include fastcgi_params;
  143.         fastcgi_param SCRIPT_FILENAME \$request_filename;
  144.         fastcgi_intercept_errors on;
  145.         fastcgi_pass unix:/run/fcgiwrap.sock;
  146.     }
  147.    
  148.     location / {
  149.         gzip off;
  150.        
  151.         index index.php;
  152.    
  153.         location /api {
  154.             rewrite ^/api(.+)$ /api/index.php?p=\$1 last;
  155.         }
  156.        
  157.         location ~ \.php$ {
  158.             if (!-f \$request_filename) { return 404; }
  159.            
  160.             expires epoch;
  161.            
  162.             include fastcgi_params;
  163.             fastcgi_param SCRIPT_FILENAME \$request_filename;
  164.             fastcgi_index index.php;
  165.             fastcgi_intercept_errors on;
  166.             fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
  167.         }
  168.        
  169.         location ~ \.(txt|log)$ {
  170.             deny all;
  171.         }
  172.        
  173.         location ~ \.(jpg|jpeg|gif|png|ico)$ {
  174.             access_log off;
  175.             expires 33d;
  176.         }
  177.        
  178.         location ~ \.(m4a|mp4|mov)$ {
  179.             mp4;
  180.             mp4_buffer_size 5M;
  181.             mp4_max_buffer_size 10M;
  182.         }
  183.     }
  184. }
  185. EOF
  186.  
  187.     ln -s /etc/nginx/sites-available/$pkgname.conf      $pkgdir/etc/nginx/sites-enabled/$pkgname.conf
  188.    
  189.    
  190.     # Systemd service
  191.     # (in the future these hardcoded dependencies could be removed or, even better, a new standalone package could be created for use with remote servers)
  192.     sed -i 's|mysqld.service httpd.service|mariadb.service nginx.service|g' misc/zoneminder.service
  193.     mkdir -p                                            $pkgdir/usr/lib/systemd/system
  194.     install -D -m 644 misc/$pkgname.service             $pkgdir/usr/lib/systemd/system/$pkgname.service
  195.    
  196.    
  197.     # Systemd tmpfile
  198.     sed -i '3d' misc/zoneminder-tmpfiles.conf
  199.     mkdir -p                                            $pkgdir/usr/lib/tmpfiles.d
  200.     install -D -m 644 misc/$pkgname-tmpfiles.conf       $pkgdir/usr/lib/tmpfiles.d/$pkgname.conf
  201.    
  202.     # PHP-FPM
  203.     mkdir -p                                            $pkgdir/etc/php/conf.d/
  204.     cat <<EOF >>                                        $pkgdir/etc/php/conf.d/$pkgname.ini
  205. extension=apcu
  206. extension=ftp
  207. extension=gd
  208. extension=gettext
  209. extension=pdo_mysql
  210. extension=sockets
  211. extension=zip
  212.  
  213. date.timezone = UTC
  214. EOF
  215.  
  216.     # Misc
  217.     install -D -m 644 COPYING                           $pkgdir/usr/share/license/$pkgname
  218.     install -D -m 644 db/zm*.sql                        $pkgdir/usr/share/$pkgname/db
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement