115 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
			
		
		
	
	
			115 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
| #!/bin/bash
 | |
| # postinst script for jilo-web
 | |
| #
 | |
| # see: dh_installdeb(1)
 | |
| 
 | |
| set -e
 | |
| 
 | |
| case "$1" in
 | |
|     configure)
 | |
| 
 | |
|         # loading debconf
 | |
|         . /usr/share/debconf/confmodule
 | |
| 
 | |
|         # get the domain and web folder
 | |
|         db_get jilo-web/domain
 | |
|         if [ -z "$RET" ] ; then
 | |
|             db_get jilo-web/domain "localhost"
 | |
|             db_input critical jilo-web/domain || true
 | |
|             db_go
 | |
|             db_get jilo-web/domain
 | |
|         fi
 | |
|         DOMAIN=$(echo "$RET" | xargs echo -n)
 | |
| 
 | |
| # FIXME use this for subfolder install, if given
 | |
|         db_get jilo-web/folder
 | |
|         WEB_DIR="$RET"
 | |
| 
 | |
|         INSTALL_DIR="/usr/share/jilo-web"
 | |
| 
 | |
|         # store the info for later reconfiguration
 | |
|         db_set jilo-web/domain $DOMAIN
 | |
|         db_set jilo-web/folder $WEB_DIR
 | |
| 
 | |
|         # we need a webserver, check for Apache and Nginx
 | |
|         WEB_SERVER=""
 | |
|         if dpkg-query -W -f='${status}' apache2 2>/dev/null | grep -q "ok installed"; then
 | |
|             WEB_SERVER="apache2"
 | |
|         elif
 | |
|             WEB_SERVER="nginx"
 | |
|         else
 | |
|             echo "Nginx or Apache is needed, please install one of them first."
 | |
|             exit 1
 | |
|         fi
 | |
| 
 | |
|         # finish configuration depending on web server
 | |
|         if [ "$WEB_SERVER" = "apache2" ]; then
 | |
| 
 | |
|             # vhost file
 | |
|             VHOST_APACHE="/etc/apache2/sites-available/jilo-web.conf"
 | |
|             cat <<EOF > "$VHOST_APACHE"
 | |
| <VirtualHost *:80>
 | |
|     ServerName $DOMAIN
 | |
|     DocumentRoot $INSTALL_DIR
 | |
| 
 | |
|     CustomLog \${APACHE_LOG_DIR}/jilo-web_access.log combined
 | |
|     ErrorLog \${APACHE_LOG_DIR}/jilo-web_error.log
 | |
| </VirtualHost>
 | |
| EOF
 | |
| 
 | |
|             # enable vhost and reload
 | |
|             a2ensite jilo-web.conf
 | |
|             /etc/init.d/apache2 reload
 | |
| 
 | |
|         elif [ "$WEB_SERVER" = "nginx" ]; then
 | |
| 
 | |
|             # vhost file
 | |
|             VHOST_NGINX="/etc/nginx/sites-available/jilo-web"
 | |
|             cat <<EOF > "$VHOST_NGINX"
 | |
| server {
 | |
|     listen 80;
 | |
|     server_name $DOMAIN;
 | |
| 
 | |
|     root $INSTALL_DIR;
 | |
|     index index.php;
 | |
| 
 | |
|     location / {
 | |
|         try_files \$uri \$uri/ /index.php?\$args;
 | |
|     }
 | |
| 
 | |
|     location ~ /\.ht {
 | |
|         deny all;
 | |
|     }
 | |
| }
 | |
| EOF
 | |
| 
 | |
|             # enable vhost and reload
 | |
|             ln -s /etc/nginx/sites-available/jilo-web /etc/nginx/sites-enabled/
 | |
|             /etc/init.d/nginx reload
 | |
| 
 | |
|         fi
 | |
| 
 | |
|         # permissions for web folder
 | |
|         chown -R www-data:www-data "$INSTALL_DIR"
 | |
|         chmod -R ug+rw "$INSTALL_DIR"
 | |
| 
 | |
|         # stopping debconf
 | |
|         db_stop
 | |
|     ;;
 | |
| 
 | |
|     abort-upgrade|abort-remove|abort-deconfigure)
 | |
|     ;;
 | |
| 
 | |
|     *)
 | |
|         echo "postinst called with unknown argument \`$1'" >&2
 | |
|         exit 1
 | |
|     ;;
 | |
| esac
 | |
| 
 | |
| # dh_installdeb will replace this with shell code automatically
 | |
| # generated by other debhelper scripts.
 | |
| 
 | |
| #DEBHELPER#
 | |
| 
 | |
| exit 0
 |