From 7c077673c3ec6db87bef5e8f5e9ce5315e034dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 14 Nov 2016 13:54:04 +0100 Subject: [PATCH 1/6] supressing warnings of postinstall.sh in centos --- contrib/packager.io/postinstall.sh | 58 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index b4bc30cb0..e4308cee3 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -11,9 +11,9 @@ DB_USER="zammad" MY_CNF="/etc/mysql/debian.cnf" # check which init system is used -if [ -n "$(which initctl)" ]; then +if [ -n "$(which initctl 2> /dev/null)" ]; then INIT_CMD="initctl" -elif [ -n "$(which systemctl)" ]; then +elif [ -n "$(which systemctl 2> /dev/null)" ]; then INIT_CMD="systemctl" else function sysvinit () { @@ -40,45 +40,45 @@ else DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)" # postgresql - if [ -n "$(which psql)" ]; then - echo "installing zammad on postgresql" + if [ -n "$(which psql 2> /dev/null)" ]; then + echo "# Installing zammad on postgresql" # centos - if [ -n "$(which postgresql-setup)" ]; then - echo "preparing postgresql server" + if [ -n "$(which postgresql-setup 2> /dev/null)" ]; then + echo "# Preparing postgresql server" postgresql-setup initdb - echo "backuping postgres config" + echo "# Backuping postgres config" test -f /var/lib/pgsql/data/pg_hba.conf.bak || cp /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.bak - echo "allow login via username and password in postgresql" + echo "# Allow login via username and password in postgresql" sed 's/ident/trust/g' < /var/lib/pgsql/data/pg_hba.conf.bak > /var/lib/pgsql/data/pg_hba.conf - echo "restarting postgresql server" + echo "# Restarting postgresql server" ${INIT_CMD} restart postgresql - echo "create postgresql bootstart" + echo "# Creating postgresql bootstart" ${INIT_CMD} enable postgresql.service fi - echo "creating zammad postgresql db" + echo "# Creating zammad postgresql db" su - postgres -c "createdb -E UTF8 ${DB}" - echo "creating zammad postgresql user" + echo "# Creating zammad postgresql user" echo "CREATE USER \"${DB_USER}\" WITH PASSWORD '${DB_PASS}';" | su - postgres -c psql - echo "grant privileges to new postgresql user" + echo "# Grant privileges to new postgresql user" echo "GRANT ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql - echo "updating database.yml" + echo "# Updating database.yml" sed -e "s/.*adapter:.*/ adapter: postgresql/" \ -e "s/.*username:.*/ username: ${DB_USER}/" \ -e "s/.*password:.*/ password: ${DB_PASS}/" \ -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.dist > ${ZAMMAD_DIR}/config/database.yml # mysql / mariadb - elif [ -n "$(which mysql)" ];then - echo "installing zammd on mysql" + elif [ -n "$(which mysql 2> /dev/null)" ];then + echo "# Installing zammd on mysql" if [ -f "${MY_CNF}" ]; then MYSQL_CREDENTIALS="--defaults-file=${MY_CNF}" @@ -88,25 +88,25 @@ else MYSQL_CREDENTIALS="-u root -p${MYSQL_ROOT_PASS}" fi - echo "creating zammad mysql db" + echo "# Creating zammad mysql db" mysql ${MYSQL_CREDENTIALS} -e "CREATE DATABASE ${DB} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" - echo "creating zammad mysql user" + echo "# Creating zammad mysql user" mysql ${MYSQL_CREDENTIALS} -e "CREATE USER \"${DB_USER}\"@\"${DB_HOST}\" IDENTIFIED BY \"${DB_PASS}\";" - echo "grant privileges to new mysql user" + echo "# Grant privileges to new mysql user" mysql ${MYSQL_CREDENTIALS} -e "GRANT ALL PRIVILEGES ON ${DB}.* TO \"${DB_USER}\"@\"${DB_HOST}\"; FLUSH PRIVILEGES;" - echo "updating database.yml" + echo "# Updating database.yml" sed -e "s/.*adapter:.*/ adapter: mysql2/" \ -e "s/.*username:.*/ username: ${DB_USER}/" \ -e "s/.*password:.*/ password: ${DB_PASS}/" \ -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.dist > ${ZAMMAD_DIR}/config/database.yml # sqlite / no local db - elif [ -n "$(which sqlite)" ];then - echo "installing zammad on sqlite" - echo "in fact this does nothing at the moment. use this to install zammad without a local database. sqlite should only be used in dev environment anyway." + elif [ -n "$(which sqlite 2> /dev/null)" ];then + echo "# Installing zammad on sqlite" + echo "# In fact this does nothing at the moment. use this to install zammad without a local database. sqlite should only be used in dev environment anyway." fi # fill database @@ -119,19 +119,21 @@ echo "# Starting Zammad" ${INIT_CMD} start zammad # on centos, allow nginx to connect to application server -if [ -n "$(which setsebool)" ]; then +if [ -n "$(which setsebool 2> /dev/null)" ]; then + echo "# Adding SE Linux rules" setsebool httpd_can_network_connect on -P fi # on centos, open port 80 and 443 -if [ -n "$(which firewall-cmd)" ]; then +if [ -n "$(which firewall-cmd 2> /dev/null)" ]; then + echo "# Adding firewall rules" firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=443/tcp --permanent firewall-cmd --reload fi # copy nginx config -if [ -n "$(which nginx)" ]; then +if [ -n "$(which nginx 2> /dev/null)" ]; then # debian / ubuntu if [ -d /etc/nginx/sites-enabled ]; then NGINX_CONF="/etc/nginx/sites-enabled/zammad.conf" @@ -144,10 +146,10 @@ if [ -n "$(which nginx)" ]; then test -f ${NGINX_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${NGINX_CONF} fi - echo "restarting Nginx" + echo "# Restarting Nginx" ${INIT_CMD} restart nginx - echo "create Nginx bootstart" + echo "# Creating Nginx bootstart" ${INIT_CMD} enable nginx echo -e "############################################################################################################" From 6500154a835c1a5d0bc006c0e86ded4c4b4b8415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 15 Nov 2016 10:29:31 +0100 Subject: [PATCH 2/6] added apache2 proxy config --- contrib/apache2/zammad.conf | 45 ++++++++++++++++++++++++++++++ contrib/packager.io/postinstall.sh | 20 ++++++------- 2 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 contrib/apache2/zammad.conf diff --git a/contrib/apache2/zammad.conf b/contrib/apache2/zammad.conf new file mode 100644 index 000000000..7926d1fa9 --- /dev/null +++ b/contrib/apache2/zammad.conf @@ -0,0 +1,45 @@ +# +# this is the apache config for zammad +# + + + # replace 'localhost' with your fqdn if you want to use zammad from remote + ServerName localhost + + ## don't loose time with IP address lookups + HostnameLookups Off + + ## needed for named virtual hosts + UseCanonicalName Off + + ## configures the footer on server-generated documents + ServerSignature Off + + ProxyRequests Off + ProxyPreserveHost On + + + Order deny,allow + Allow from localhost + + + ProxyPass /assets ! + ProxyPass /favicon.ico ! + ProxyPass /robots.txt ! + ProxyPass /ws ws://localhost:6042/ + ProxyPass / http://localhost:3000/ + + DocumentRoot "/opt/zammad/public" + + + Options FollowSymLinks + AllowOverride None + + + + Options FollowSymLinks + Order allow,deny + Allow from all + + + diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index e4308cee3..719d93848 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -45,20 +45,20 @@ else # centos if [ -n "$(which postgresql-setup 2> /dev/null)" ]; then - echo "# Preparing postgresql server" - postgresql-setup initdb + echo "# Preparing postgresql server" + postgresql-setup initdb - echo "# Backuping postgres config" - test -f /var/lib/pgsql/data/pg_hba.conf.bak || cp /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.bak + echo "# Backuping postgres config" + test -f /var/lib/pgsql/data/pg_hba.conf.bak || cp /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.bak - echo "# Allow login via username and password in postgresql" - sed 's/ident/trust/g' < /var/lib/pgsql/data/pg_hba.conf.bak > /var/lib/pgsql/data/pg_hba.conf + echo "# Allow login via username and password in postgresql" + sed 's/ident/trust/g' < /var/lib/pgsql/data/pg_hba.conf.bak > /var/lib/pgsql/data/pg_hba.conf - echo "# Restarting postgresql server" - ${INIT_CMD} restart postgresql + echo "# Restarting postgresql server" + ${INIT_CMD} restart postgresql - echo "# Creating postgresql bootstart" - ${INIT_CMD} enable postgresql.service + echo "# Creating postgresql bootstart" + ${INIT_CMD} enable postgresql.service fi echo "# Creating zammad postgresql db" From e3733be61357db128770f266a013a7820f665252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 15 Nov 2016 11:10:57 +0100 Subject: [PATCH 3/6] added apache2 configuration to postinstall.sh --- contrib/packager.io/postinstall.sh | 52 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index 719d93848..e365a6135 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -132,33 +132,53 @@ if [ -n "$(which firewall-cmd 2> /dev/null)" ]; then firewall-cmd --reload fi -# copy nginx config -if [ -n "$(which nginx 2> /dev/null)" ]; then +# copy webserver config +if [ -n "$(which apache2 2> /dev/null)" ] || [ -n "$(which httpd 2> /dev/null)" ] || [ -n "$(which nginx 2> /dev/null)" ] ; then + # Nginx # debian / ubuntu if [ -d /etc/nginx/sites-enabled ]; then - NGINX_CONF="/etc/nginx/sites-enabled/zammad.conf" + WEBSERVER_CONF="/etc/nginx/sites-enabled/zammad.conf" + WEBSERVER_CMD="nginx" test -f /etc/nginx/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf /etc/nginx/sites-available/zammad.conf - test -h ${NGINX_CONF} || ln -s /etc/nginx/sites-available/zammad.conf ${NGINX_CONF} - + test -h ${WEBSERVER_CONF} || ln -s /etc/nginx/sites-available/zammad.conf ${WEBSERVER_CONF} # centos / sles elif [ -d /etc/nginx/conf.d ]; then - NGINX_CONF="/etc/nginx/conf.d/zammad.conf" - test -f ${NGINX_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${NGINX_CONF} + WEBSERVER_CONF="/etc/nginx/conf.d/zammad.conf" + WEBSERVER_CMD="nginx" + test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${WEBSERVER_CONF} + # Apache2 + # debian / ubuntu + elif [ -d /etc/apache2/sites-enabled ]; then + WEBSERVER_CONF="/etc/apache2/sites-enabled/zammad.conf" + WEBSERVER_CMD="apache2" + test -f /etc/apache2/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/apache2/zammad.conf /etc/apache2/sites-available/zammad.conf + test -h ${WEBSERVER_CONF} || ln -s /etc/apache2/sites-available/zammad.conf ${WEBSERVER_CONF} + + echo "# Activating Apache2 modules" + a2enmod proxy + a2enmod proxy_http + a2enmod proxy_wstunnel + # centos / sles + elif [ -d /etc/httpd/conf.d ]; then + WEBSERVER_CONF="/etc/httpd/conf.d/zammad.conf" + WEBSERVER_CMD="httpd" + test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/apache2/zammad.conf ${WEBSERVER_CONF} fi - echo "# Restarting Nginx" - ${INIT_CMD} restart nginx + echo "# Restarting webserver ${WEBSERVER_CMD}" + ${INIT_CMD} restart ${WEBSERVER_CMD} - echo "# Creating Nginx bootstart" - ${INIT_CMD} enable nginx + echo "# Creating webserver bootstart" + ${INIT_CMD} enable ${WEBSERVER_CMD} - echo -e "############################################################################################################" - echo -e "\nAdd your FQDN to servername directive in ${NGINX_CONF} and restart nginx if you're not testing localy" + echo -e "####################################################################################" + echo -e "\nAdd your FQDN to servername directive in ${WEBSERVER_CONF}" + echo -e "and restart your webserver if you're not testing localy" echo -e "or open http://localhost in your browser to start using Zammad.\n" - echo -e "############################################################################################################" + echo -e "####################################################################################" else - echo -e "############################################################################################################" + echo -e "####################################################################################" echo -e "\nOpen http://localhost:3000 in your browser to start using Zammad.\n" - echo -e "############################################################################################################" + echo -e "####################################################################################" fi From 096ea6d48977e73ca787103d4c9b31b6ccc259f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 15 Nov 2016 16:21:16 +0100 Subject: [PATCH 4/6] fix 415 - remove creation of Gemfile.local from pkgr.yml --- .pkgr.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pkgr.yml b/.pkgr.yml index 59b3c715d..58f0cb2fc 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -27,7 +27,6 @@ before: - uname -a - ruby -v - env - - echo "gem 'mysql2'" >> Gemfile.local - "cat Gemfile.lock" - contrib/cleanup.sh env: From 1bc91c15b745922509ad7c943a79ae6bc1aaf34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 15 Nov 2016 22:44:06 +0100 Subject: [PATCH 5/6] sles / opensuse support in postinstall.sh --- contrib/packager.io/postinstall.sh | 57 +++++++++++++++++------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index e365a6135..16f8d6f33 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -11,10 +11,10 @@ DB_USER="zammad" MY_CNF="/etc/mysql/debian.cnf" # check which init system is used -if [ -n "$(which initctl 2> /dev/null)" ]; then - INIT_CMD="initctl" -elif [ -n "$(which systemctl 2> /dev/null)" ]; then +if [ -n "$(which systemctl 2> /dev/null)" ]; then INIT_CMD="systemctl" +elif [ -n "$(which initctl 2> /dev/null)" ]; then + INIT_CMD="initctl" else function sysvinit () { service $2 $1 @@ -25,6 +25,9 @@ fi echo "# (Re)creating init scripts" zammad scale web=1 websocket=1 worker=1 +echo "# Enabling Zammad on boot" +${INIT_CMD} enable zammad + echo "# Stopping Zammad" ${INIT_CMD} stop zammad @@ -53,14 +56,15 @@ else echo "# Allow login via username and password in postgresql" sed 's/ident/trust/g' < /var/lib/pgsql/data/pg_hba.conf.bak > /var/lib/pgsql/data/pg_hba.conf - - echo "# Restarting postgresql server" - ${INIT_CMD} restart postgresql - - echo "# Creating postgresql bootstart" - ${INIT_CMD} enable postgresql.service fi + # centos / ubuntu / sles + echo "# Creating postgresql bootstart" + ${INIT_CMD} enable postgresql.service + + echo "# Restarting postgresql server" + ${INIT_CMD} restart postgresql + echo "# Creating zammad postgresql db" su - postgres -c "createdb -E UTF8 ${DB}" @@ -72,13 +76,13 @@ else echo "# Updating database.yml" sed -e "s/.*adapter:.*/ adapter: postgresql/" \ - -e "s/.*username:.*/ username: ${DB_USER}/" \ - -e "s/.*password:.*/ password: ${DB_PASS}/" \ - -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.dist > ${ZAMMAD_DIR}/config/database.yml + -e "s/.*username:.*/ username: ${DB_USER}/" \ + -e "s/.*password:.*/ password: ${DB_PASS}/" \ + -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.dist > ${ZAMMAD_DIR}/config/database.yml # mysql / mariadb elif [ -n "$(which mysql 2> /dev/null)" ];then - echo "# Installing zammd on mysql" + echo "# Installing zammad on mysql" if [ -f "${MY_CNF}" ]; then MYSQL_CREDENTIALS="--defaults-file=${MY_CNF}" @@ -94,14 +98,14 @@ else echo "# Creating zammad mysql user" mysql ${MYSQL_CREDENTIALS} -e "CREATE USER \"${DB_USER}\"@\"${DB_HOST}\" IDENTIFIED BY \"${DB_PASS}\";" - echo "# Grant privileges to new mysql user" + echo "# Grant privileges to new mysql user" mysql ${MYSQL_CREDENTIALS} -e "GRANT ALL PRIVILEGES ON ${DB}.* TO \"${DB_USER}\"@\"${DB_HOST}\"; FLUSH PRIVILEGES;" - echo "# Updating database.yml" + echo "# Updating database.yml" sed -e "s/.*adapter:.*/ adapter: mysql2/" \ - -e "s/.*username:.*/ username: ${DB_USER}/" \ - -e "s/.*password:.*/ password: ${DB_PASS}/" \ - -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.dist > ${ZAMMAD_DIR}/config/database.yml + -e "s/.*username:.*/ username: ${DB_USER}/" \ + -e "s/.*password:.*/ password: ${DB_PASS}/" \ + -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.dist > ${ZAMMAD_DIR}/config/database.yml # sqlite / no local db elif [ -n "$(which sqlite 2> /dev/null)" ];then @@ -141,11 +145,17 @@ if [ -n "$(which apache2 2> /dev/null)" ] || [ -n "$(which httpd 2> /dev/null)" WEBSERVER_CMD="nginx" test -f /etc/nginx/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf /etc/nginx/sites-available/zammad.conf test -h ${WEBSERVER_CONF} || ln -s /etc/nginx/sites-available/zammad.conf ${WEBSERVER_CONF} - # centos / sles + # centos elif [ -d /etc/nginx/conf.d ]; then WEBSERVER_CONF="/etc/nginx/conf.d/zammad.conf" WEBSERVER_CMD="nginx" test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${WEBSERVER_CONF} + elif [ -d /etc/YaST2 ]; then + WEBSERVER_CONF="/etc/nginx/vhosts.d/zammad.conf" + WEBSERVER_CMD="nginx" + test -d /etc/nginx/vhosts.d || mkdir -p /etc/nginx/vhosts.d + test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${WEBSERVER_CONF} + # Apache2 # debian / ubuntu elif [ -d /etc/apache2/sites-enabled ]; then @@ -158,19 +168,19 @@ if [ -n "$(which apache2 2> /dev/null)" ] || [ -n "$(which httpd 2> /dev/null)" a2enmod proxy a2enmod proxy_http a2enmod proxy_wstunnel - # centos / sles + # centos elif [ -d /etc/httpd/conf.d ]; then WEBSERVER_CONF="/etc/httpd/conf.d/zammad.conf" WEBSERVER_CMD="httpd" test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/apache2/zammad.conf ${WEBSERVER_CONF} fi - echo "# Restarting webserver ${WEBSERVER_CMD}" - ${INIT_CMD} restart ${WEBSERVER_CMD} - echo "# Creating webserver bootstart" ${INIT_CMD} enable ${WEBSERVER_CMD} + echo "# Restarting webserver ${WEBSERVER_CMD}" + ${INIT_CMD} restart ${WEBSERVER_CMD} + echo -e "####################################################################################" echo -e "\nAdd your FQDN to servername directive in ${WEBSERVER_CONF}" echo -e "and restart your webserver if you're not testing localy" @@ -181,4 +191,3 @@ else echo -e "\nOpen http://localhost:3000 in your browser to start using Zammad.\n" echo -e "####################################################################################" fi - From ca4a2e97dd996e9ae9fadb9717451e758f6d0405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Wed, 16 Nov 2016 10:33:06 +0100 Subject: [PATCH 6/6] fix apache config --- contrib/apache2/zammad.conf | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/contrib/apache2/zammad.conf b/contrib/apache2/zammad.conf index 7926d1fa9..4226b7166 100644 --- a/contrib/apache2/zammad.conf +++ b/contrib/apache2/zammad.conf @@ -4,7 +4,7 @@ # replace 'localhost' with your fqdn if you want to use zammad from remote - ServerName localhost + ServerName ubuntu.local ## don't loose time with IP address lookups HostnameLookups Off @@ -18,9 +18,8 @@ ProxyRequests Off ProxyPreserveHost On - - Order deny,allow - Allow from localhost + + Require local ProxyPass /assets ! @@ -38,8 +37,7 @@ Options FollowSymLinks - Order allow,deny - Allow from all + Require all granted