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..59b3c715d 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -1,26 +1,28 @@ +name: zammad +description: Zammad is a web based open source helpdesk/customer support system +homepage: https://zammad.org 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: - - postgresql + - nginx|apache2 + - postgresql|mysql-server|mariadb-server|sqlite ubuntu-16.04: dependencies: - - postgresql + - nginx|apache2 + - postgresql|mysql-server|mariadb-server|sqlite sles-12: dependencies: - - postgresql + - nginx + - postgresql-server before: - uname -a - ruby -v @@ -31,7 +33,6 @@ before: env: - RAILS_ENV=production - PORT=3000 - - RAILS_SERVE_STATIC_FILES=true services: - postgres -after_install: contrib/pkgr-postinstall.sh +after_install: contrib/packager.io/postinstall.sh diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh new file mode 100755 index 000000000..ee9542db4 --- /dev/null +++ b/contrib/packager.io/postinstall.sh @@ -0,0 +1,140 @@ +#!/bin/bash +# +# packager.io postinstall script +# + +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 + INIT_CMD="initctl" +elif [ -n "$(which systemctl)" ]; then + INIT_CMD="systemctl" +else + function sysvinit () { + service $2 $1 + } + INIT_CMD="sysvinit" +fi + +echo "# (Re)creating init scripts" +zammad scale web=1 websocket=1 worker=1 + +echo "# Stopping Zammad" +${INIT_CMD} stop zammad + +# check if database.yml exists +if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then + # db migration + 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)" + + # postgresql + if [ -n "$(which psql)" ]; then + echo "installing zammad on postgresql" + + # centos + 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 + + 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 + + # fill database + zammad run rake db:migrate + zammad run rake db:seed + +fi + +echo "# Starting Zammad" +${INIT_CMD} start zammad + +# copy nginx config +if [ -n "$(which nginx)" ]; then + # 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" + test -f ${NGINX_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${NGINX_CONF} + fi + + echo "# Restarting Nginx" + ${INIT_CMD} restart nginx +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" diff --git a/contrib/pkgr-postinstall.sh b/contrib/pkgr-postinstall.sh deleted file mode 100755 index 80ee532d8..000000000 --- a/contrib/pkgr-postinstall.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash -# -# packager.io postinstall script -# - -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" - -# check which init system is used -if [ -n $(which initctl) ]; then - INIT_CMD="initctl" -elif [ -n $(which systemctl) ]; then - INIT_CMD="systemctl" -else - function sysvinit () { - service $2 $1 - } - INIT_CMD="sysvinit" -fi - -echo "# (Re)creating init scripts" -zammad scale web=1 websocket=1 worker=1 - -echo "# Stopping Zammad" -${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..." - zammad run rake db:migrate -else - # create new password - DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)" - - # 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:seed -fi - -echo "# Starting Zammad" -${INIT_CMD} start zammad - -# 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" - test -f ${NGINX_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${NGINX_CONF} - fi - - 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