install.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. USER=zammad
  3. REPOURL=git@github.com:martini/zammad.git
  4. DBNAME=zammad
  5. DBUSER=zammad
  6. function check_requirements() {
  7. items="git useradd sudo getent curl bash gcc make svn apg"
  8. for item in $items
  9. do
  10. which $item > /dev/null
  11. if [ $? -ne 0 ]; then
  12. echo Please install $item and start this script again.
  13. exit 1
  14. fi
  15. done
  16. }
  17. function check_os()
  18. {
  19. # Debian
  20. if [ -f /etc/debian_version ]; then
  21. OS=Debian
  22. local MAJOR=$(cut -d. /etc/debian_version -f1)
  23. if [ $MAJOR -lt 7 ]; then
  24. echo Please check the supported operating systems
  25. exit 1
  26. fi
  27. fi
  28. }
  29. check_requirements
  30. check_os
  31. #
  32. # @TODO Should the mysql user be created?
  33. # @TODO Install Elasticsearch?
  34. # @TODO Should the script create a VirtualHost or a config file to include for apache/nginx?
  35. #
  36. #
  37. # Check for zammad user and create if needed
  38. #
  39. id -u "${USER}" > /dev/null 2>&1
  40. if [ $? -ne 0 ]; then
  41. useradd -c 'user running zammad' -m -s /bin/bash $USER
  42. fi
  43. #
  44. # find the user's homedir and primary group name
  45. #
  46. HOMEDIR=$(getent passwd $USER | cut -d: -f 6)
  47. GROUP=$(id -gn $USER)
  48. cd "${HOMEDIR}"
  49. sudo -u "${USER}" -H git clone $REPOURL zammad
  50. cd zammad
  51. LATEST=$(git tag --list|sort|tail -1)
  52. git checkout tags/"${LATEST}"
  53. chown -R "${USER}":"${GROUP}" .
  54. #
  55. # RVM
  56. #
  57. sudo -u "${USER}" -H bash -c 'curl -sSL https://get.rvm.io | bash -s stable'
  58. #
  59. # install Ruby
  60. #
  61. sudo -u "${USER}" -H bash -l -c 'rvm install 2.1.2'
  62. sudo -u "${USER}" -H bash -l -c 'rvm alias create default 2.1.2'
  63. #
  64. # after rvm requirements
  65. # Installing required packages: gawk, g++, libreadline6-dev, zlib1g-dev, libssl-dev, libyaml-dev, libsqlite3-dev, sqlite3, autoconf, libgdbm-dev, libncurses5-dev, automake, libtool, bison, pkg-config, libffi-dev................
  66. sudo -u "${USER}" -H bash -l -c 'cd ~/zammad && gem install rails --no-ri --no-rdoc'
  67. sudo -u "${USER}" -H bash -l -c 'cd ~/zammad && bundle install --jobs 8'
  68. DBPASS=$(apg -x8|head -1)
  69. echo Password $DBPASS
  70. mysql -e "GRANT ALL ON ${DBNAME}.* to '${DBUSER}'@'localhost' IDENTIFIED BY '$DBPASS'";
  71. sudo -u $USER -H cp ${HOMEDIR}/zammad/config/database.yml.dist ${HOMEDIR}/zammad/config/database.yml
  72. sudo -u $USER -H sed -i s/some_pass/${DBPASS}/g ${HOMEDIR}/zammad/config/database.yml
  73. sudo -u $USER -H sed -i s/some_user/${DBUSER}/g ${HOMEDIR}/zammad/config/database.yml
  74. sudo -u $USER -H sed -i s/zammad_prod/zammad/g ${HOMEDIR}/zammad/config/database.yml
  75. #
  76. #
  77. #
  78. sudo -u "${USER}" -H bash -l -c 'cd ~/zammad && RAILS_ENV=production rake db:create'
  79. sudo -u "${USER}" -H bash -l -c 'cd ~/zammad && RAILS_ENV=production rake db:migrate'
  80. sudo -u "${USER}" -H bash -l -c 'cd ~/zammad && RAILS_ENV=production rake db:seed'
  81. sudo -u "${USER}" -H bash -l -c 'cd ~/zammad && RAILS_ENV=production rake assets:precompile'
  82. cp "${HOMEDIR}/zammad/script/init.d/zammad /etc/init.d/zammad"
  83. chmod +x /etc/init.d/zammad
  84. if [ "$OS" = "Debian" ]; then
  85. update-rc.d zammad defaults
  86. fi