From a797add550aacbd27429efd04f8bf3983e1a7eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 13:00:59 +0100 Subject: [PATCH 01/10] packager additions --- .codeclimate.yml | 48 +++++++++++++++++++ .pkgr.yml | 15 +++--- .../postinstall.sh} | 14 ++++-- contrib/packager.io/preinstall.sh | 12 +++++ 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 .codeclimate.yml rename contrib/{pkgr-postinstall.sh => packager.io/postinstall.sh} (88%) create mode 100755 contrib/packager.io/preinstall.sh diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 000000000..54e14b269 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,48 @@ +--- +engines: + brakeman: + enabled: true + bundler-audit: + enabled: true + csslint: + enabled: true + coffeelint: + enabled: true + duplication: + enabled: true + config: + languages: + - ruby + - javascript + - python + - php + eslint: + enabled: true + fixme: + enabled: true + phpmd: + enabled: true + rubocop: + enabled: true +ratings: + paths: + - Gemfile.lock + - "**.erb" + - "**.haml" + - "**.rb" + - "**.rhtml" + - "**.slim" + - "**.css" + - "**.coffee" + - "**.inc" + - "**.js" + - "**.jsx" + - "**.module" + - "**.php" + - "**.py" +exclude_paths: +- config/ +- db/ +- script/ +- test/ +- vendor/ diff --git a/.pkgr.yml b/.pkgr.yml index 1a1429b9e..68e6b8d78 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -2,24 +2,23 @@ notifications: false targets: centos-6: dependencies: - - httpd - - postgresql + - nginx - postgresql-server - - postgresql-devel centos-7: dependencies: - - httpd - - postgresql + - nginx - postgresql-server - - postgresql-devel debian-8: dependencies: + - nginx - postgresql ubuntu-16.04: dependencies: + - nginx - postgresql sles-12: dependencies: + - nginx - postgresql before: - uname -a @@ -31,7 +30,7 @@ before: env: - RAILS_ENV=production - PORT=3000 - - RAILS_SERVE_STATIC_FILES=true services: - postgres -after_install: contrib/pkgr-postinstall.sh +before_install: contrib/packager.io/preinstall.sh +after_install: contrib/packager.io/postinstall.sh diff --git a/contrib/pkgr-postinstall.sh b/contrib/packager.io/postinstall.sh similarity index 88% rename from contrib/pkgr-postinstall.sh rename to contrib/packager.io/postinstall.sh index 80ee532d8..86561ac5c 100755 --- a/contrib/pkgr-postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -10,9 +10,9 @@ DB="zammad_production" DB_USER="zammad" # check which init system is used -if [ -n $(which initctl) ]; then +if [ -n "$(which initctl)" ]; then INIT_CMD="initctl" -elif [ -n $(which systemctl) ]; then +elif [ -n "$(which systemctl)" ]; then INIT_CMD="systemctl" else function sysvinit () { @@ -36,6 +36,14 @@ else # create new password DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)" + if [ -n "$(which postgresql-setup)" ]; then + echo "preparing postgresql server" + postgresql-setup initdb + + echo "restarting postgresql server" + ${INIT_CMD} restart postgresql + fi + # create database echo "# database.yml not found. Creating new db..." su - postgres -c "createdb -E UTF8 ${DB}" @@ -58,7 +66,7 @@ echo "# Starting Zammad" ${INIT_CMD} start zammad # nginx config -if [ -n $(which nginx) ]; then +if [ -n "$(which nginx)" ]; then # copy nginx config # debian / ubuntu if [ -d /etc/nginx/sites-enabled ]; then diff --git a/contrib/packager.io/preinstall.sh b/contrib/packager.io/preinstall.sh new file mode 100755 index 000000000..1bc7e735f --- /dev/null +++ b/contrib/packager.io/preinstall.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# packager.io preinstall script +# + +PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin: + +# install epel-release on centos (needed for nginx) +if [ -n "$(which yum)" ]; then + yum install -y epel-release +fi + From f07982daf58dece18a3cebdf34c338e2eef22293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 13:40:00 +0100 Subject: [PATCH 02/10] fix nginx install on centos (#336) fix nginx install on centos (#336) --- .pkgr.yml | 2 -- contrib/packager.io/preinstall.sh | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pkgr.yml b/.pkgr.yml index 68e6b8d78..ca301daad 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -2,11 +2,9 @@ notifications: false targets: centos-6: dependencies: - - nginx - postgresql-server centos-7: dependencies: - - nginx - postgresql-server debian-8: dependencies: diff --git a/contrib/packager.io/preinstall.sh b/contrib/packager.io/preinstall.sh index 1bc7e735f..c462aed21 100755 --- a/contrib/packager.io/preinstall.sh +++ b/contrib/packager.io/preinstall.sh @@ -5,8 +5,10 @@ PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin: -# install epel-release on centos (needed for nginx) +# install epel-release & nginx on centos because it does not work via dependencies if [ -n "$(which yum)" ]; then yum install -y epel-release + + yum install -y nginx fi From b898d2de60cd2b086ab8ba113dacdba1b10d1523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 14:04:40 +0100 Subject: [PATCH 03/10] Update preinstall.sh --- contrib/packager.io/preinstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/packager.io/preinstall.sh b/contrib/packager.io/preinstall.sh index c462aed21..a1da656c3 100755 --- a/contrib/packager.io/preinstall.sh +++ b/contrib/packager.io/preinstall.sh @@ -7,8 +7,8 @@ PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin # install epel-release & nginx on centos because it does not work via dependencies if [ -n "$(which yum)" ]; then - yum install -y epel-release + yum install -y -q epel-release - yum install -y nginx + yum install -y -q nginx fi From 65324e99e86fe1243b983bb011edac5c7942d5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 14:12:35 +0100 Subject: [PATCH 04/10] packager.io centos fixes --- .pkgr.yml | 3 ++- contrib/packager.io/preinstall.sh | 14 -------------- 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100755 contrib/packager.io/preinstall.sh diff --git a/.pkgr.yml b/.pkgr.yml index ca301daad..c2c3178ac 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -2,9 +2,11 @@ notifications: false targets: centos-6: dependencies: + - nginx - postgresql-server centos-7: dependencies: + - nginx - postgresql-server debian-8: dependencies: @@ -30,5 +32,4 @@ env: - PORT=3000 services: - postgres -before_install: contrib/packager.io/preinstall.sh after_install: contrib/packager.io/postinstall.sh diff --git a/contrib/packager.io/preinstall.sh b/contrib/packager.io/preinstall.sh deleted file mode 100755 index a1da656c3..000000000 --- a/contrib/packager.io/preinstall.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# -# packager.io preinstall script -# - -PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin: - -# install epel-release & nginx on centos because it does not work via dependencies -if [ -n "$(which yum)" ]; then - yum install -y -q epel-release - - yum install -y -q nginx -fi - From e4d3f4704b97db8448558ceabea768836c313cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 15:46:37 +0100 Subject: [PATCH 05/10] more packager.io fixe (#339) - fix postgresql package name for sles12 - configure postgresql on centos to accept username/password logins --- .pkgr.yml | 2 +- contrib/packager.io/postinstall.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.pkgr.yml b/.pkgr.yml index c2c3178ac..ea7cce21e 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -19,7 +19,7 @@ targets: sles-12: dependencies: - nginx - - postgresql + - postgresql-server before: - uname -a - ruby -v diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index 86561ac5c..3dee19124 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -40,8 +40,17 @@ else 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 + + "allow login via username and password in postgresql" + egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/trust/g' > /var/lib/pgsql/data/pg_hba.conf + echo "restarting postgresql server" ${INIT_CMD} restart postgresql + + echo "create postgresql bootstart" + ${INIT_CMD} enable postgresql.service fi # create database From af6f10def59fccd291f91fee95fc5edfd8e52dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 16:18:13 +0100 Subject: [PATCH 06/10] fix missing echo and change login to md5 --- contrib/packager.io/postinstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index 3dee19124..493ba9734 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -43,8 +43,8 @@ else 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 - "allow login via username and password in postgresql" - egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/trust/g' > /var/lib/pgsql/data/pg_hba.conf + echo "allow login via username and password in postgresql" + egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/md5/g' > /var/lib/pgsql/data/pg_hba.conf echo "restarting postgresql server" ${INIT_CMD} restart postgresql From ab29cfec3250442fcad746d39af08b7a5136c7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 31 Oct 2016 16:32:53 +0100 Subject: [PATCH 07/10] Update postinstall.sh --- contrib/packager.io/postinstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index 493ba9734..c16b5cacb 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -44,7 +44,7 @@ else 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" - egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/md5/g' > /var/lib/pgsql/data/pg_hba.conf + egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/trust/g' > /var/lib/pgsql/data/pg_hba.conf echo "restarting postgresql server" ${INIT_CMD} restart postgresql From 09b38b44d1d1ab784deacf11d6bf7bc783668c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Wed, 2 Nov 2016 18:18:29 +0100 Subject: [PATCH 08/10] adding mysql / mariadb to postinstall.sh (#346) * .pkgr.yml - add mysql/mariadb as dependenciy alternatvies / postinstall.sh - add mysql db creation * postinstall.sh fixes * pkgr.yml additions * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * [skip ci] postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes * postinstall.sh fixes --- .pkgr.yml | 9 ++- contrib/packager.io/postinstall.sh | 110 ++++++++++++++++++++--------- 2 files changed, 82 insertions(+), 37 deletions(-) diff --git a/.pkgr.yml b/.pkgr.yml index ea7cce21e..7dd73a88f 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -1,3 +1,6 @@ +name: zammad +description: Zammad is a web based open source helpdesk/customer support system +homepage: https://zammad.org notifications: false targets: centos-6: @@ -11,15 +14,15 @@ targets: debian-8: dependencies: - nginx - - postgresql + - postgresql|mysql-server|mariadb-server|sqlite ubuntu-16.04: dependencies: - nginx - - postgresql + - postgresql|mysql-server|mariadb-server|sqlite sles-12: dependencies: - nginx - - postgresql-server + - postgresql-server|mysql-server|mariadb-server before: - uname -a - ruby -v diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index c16b5cacb..ee9542db4 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -8,6 +8,7 @@ PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin ZAMMAD_DIR="/opt/zammad" DB="zammad_production" DB_USER="zammad" +MY_CNF="/etc/mysql/debian.cnf" # check which init system is used if [ -n "$(which initctl)" ]; then @@ -30,58 +31,101 @@ ${INIT_CMD} stop zammad # check if database.yml exists if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then # db migration - echo "# database.yml exists. Updating db..." + echo "# database.yml found. Updating db..." zammad run rake db:migrate else + echo "# database.yml not found. Creating db..." + # create new password DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)" - if [ -n "$(which postgresql-setup)" ]; then - 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 + # postgresql + if [ -n "$(which psql)" ]; then + echo "installing zammad on postgresql" - echo "allow login via username and password in postgresql" - egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/trust/g' > /var/lib/pgsql/data/pg_hba.conf + # centos + if [ -n "$(which postgresql-setup)" ]; then + echo "preparing postgresql server" + postgresql-setup initdb - echo "restarting postgresql server" - ${INIT_CMD} restart postgresql + 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 "create postgresql bootstart" - ${INIT_CMD} enable postgresql.service + 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 "create postgresql bootstart" + ${INIT_CMD} enable postgresql.service + fi + + echo "creating zammad postgresql db" + su - postgres -c "createdb -E UTF8 ${DB}" + + 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 ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql + + 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" + + if [ -f "${MY_CNF}" ]; then + MYSQL_CREDENTIALS="--defaults-file=${MY_CNF}" + else + echo -n "Please enter your MySQL root password:" + read -s MYSQL_ROOT_PASS + MYSQL_CREDENTIALS="-u root -p${MYSQL_ROOT_PASS}" + fi + + 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" + mysql ${MYSQL_CREDENTIALS} -e "CREATE USER \"${DB_USER}\"@\"${DB_HOST}\" IDENTIFIED BY \"${DB_PASS}\";" + + 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" + 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." fi - # create database - echo "# database.yml not found. Creating new db..." - su - postgres -c "createdb -E UTF8 ${DB}" - - # create postgres user - echo "CREATE USER \"${DB_USER}\" WITH PASSWORD '${DB_PASS}';" | su - postgres -c psql - - # grant privileges - echo "GRANT ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql - - # update configfile - sed "s/.*password:.*/ password: ${DB_PASS}/" < ${ZAMMAD_DIR}/config/database.yml.pkgr > ${ZAMMAD_DIR}/config/database.yml - # fill database - zammad run rake db:migrate + zammad run rake db:migrate zammad run rake db:seed + fi echo "# Starting Zammad" ${INIT_CMD} start zammad -# nginx config +# copy nginx config if [ -n "$(which nginx)" ]; then - # copy nginx config # debian / ubuntu if [ -d /etc/nginx/sites-enabled ]; then NGINX_CONF="/etc/nginx/sites-enabled/zammad.conf" 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} + # centos / sles elif [ -d /etc/nginx/conf.d ]; then NGINX_CONF="/etc/nginx/conf.d/zammad.conf" @@ -90,9 +134,7 @@ if [ -n "$(which nginx)" ]; then echo "# Restarting Nginx" ${INIT_CMD} restart nginx - - echo -e "\nAdd your FQDN to servername directive in ${NGINX_CONF} and restart nginx if you're not testing localy" - echo -e "or open http://localhost in your browser to start using Zammad.\n" -else - echo -e "\nOpen http://localhost:3000 in your browser to start using Zammad.\n" fi + +echo -e "\nAdd your FQDN to servername directive in ${NGINX_CONF} and restart nginx if you're not testing localy" +echo -e "or open http://localhost in your browser to start using Zammad.\n" From c2aca71e6d5ad24d26dc97c61deca20c2f35813a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Thu, 3 Nov 2016 11:09:22 +0100 Subject: [PATCH 09/10] Update .pkgr.yml --- .pkgr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pkgr.yml b/.pkgr.yml index 7dd73a88f..450171283 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -22,7 +22,7 @@ targets: sles-12: dependencies: - nginx - - postgresql-server|mysql-server|mariadb-server + - postgresql-server before: - uname -a - ruby -v From e8dccb50e0e25c70b77e645aa5a859eb26c741c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Thu, 3 Nov 2016 15:11:00 +0100 Subject: [PATCH 10/10] Added Apache2 to Debian / Ubuntu dependencies --- .pkgr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pkgr.yml b/.pkgr.yml index 450171283..59b3c715d 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -13,11 +13,11 @@ targets: - postgresql-server debian-8: dependencies: - - nginx + - nginx|apache2 - postgresql|mysql-server|mariadb-server|sqlite ubuntu-16.04: dependencies: - - nginx + - nginx|apache2 - postgresql|mysql-server|mariadb-server|sqlite sles-12: dependencies: