Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. [ -z "${MYSQL_PASSWD}" ] && MYSQL_PASSWD=mysql
  6. [ -z "${REDMINE_PASSWD}" ] && REDMINE_PASSWD=redmine
  7.  
  8. mysql_install()
  9. {
  10. sudo pacman -Sy --noconfirm mariadb
  11.  
  12. # Install database.
  13. sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  14.  
  15. sudo systemctl enable mariadb
  16. sudo systemctl start mariadb
  17.  
  18. # Password configuration.
  19. cat <<EOF | sudo mysql_secure_installation
  20.  
  21. y
  22. ${MYSQL_PASSWD}
  23. ${MYSQL_PASSWD}
  24. n
  25. y
  26. y
  27. y
  28. EOF
  29.  
  30. # Create user and database for redmine.
  31. cat <<EOF | sudo mysql -uroot -p${MYSQL_PASSWD}
  32. CREATE DATABASE redmine CHARACTER SET UTF8;
  33. CREATE USER 'redmine'@'localhost' IDENTIFIED BY '${REDMINE_PASSWD}';
  34. GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
  35. EOF
  36. }
  37.  
  38. redmine_install()
  39. {
  40. sudo pacman -Sy --noconfirm git base-devel
  41. git clone https://aur.archlinux.org/redmine.git
  42. cd redmine
  43. makepkg -s --noconfirm
  44. sudo pacman -U --noconfirm ./*.pkg.tar.xz
  45. cd ..
  46.  
  47. # BUG: Current ruby-2.4 has a issue "stack level too deep" when running
  48. # "bundle exec rake db:migrate". This script will use ruby-2.3.
  49. sudo pacman -Sy --noconfirm ruby2.3 ruby2.3-bundler
  50. for f in ruby gem rake bundle; do
  51. sudo ln -s "$(which ${f}-2.3)" /usr/bin/"${f}"
  52. done
  53.  
  54. # Ruby on Rails.
  55. cd /usr/share/webapps/redmine/
  56. cat <<EOF | sudo tee config/database.yml
  57. production:
  58. adapter: mysql2
  59. database: redmine
  60. host: localhost
  61. username: redmine
  62. password: "${REDMINE_PASSWD}"
  63. encoding: utf8
  64. EOF
  65. sudo bundle install --without development test
  66. sudo RAILS_ENV=production bundle exec rake generate_secret_token
  67. sudo RAILS_ENV=production bundle exec rake db:migrate
  68. echo "en" | \
  69. sudo RAILS_ENV=production bundle exec rake redmine:load_default_data
  70. sudo chown -R http:http files log tmp public/plugin_assets
  71. }
  72.  
  73. apache_install()
  74. {
  75. sudo pacman -Sy --noconfirm apache
  76. sudo systemctl enable httpd
  77.  
  78. # ssl configuration.
  79. # Country Name (2 letter code) [AU]:
  80. # State or Province Name (full name) [Some-State]:
  81. # Locality Name (eg, city) []:
  82. # Organization Name (eg, company) [Internet Widgits Pty Ltd]:
  83. # Organizational Unit Name (eg, section) []:
  84. # Common Name (e.g. server FQDN or YOUR name) []:
  85. # Email Address []:
  86. cat <<EOF | sudo openssl req -new -x509 -nodes -newkey rsa:4096 -days 1095 \
  87. -keyout /etc/httpd/conf/server.key \
  88. -out /etc/httpd/conf/server.crt
  89. AU
  90. Some-State
  91. city
  92. company
  93. section
  94.  
  95.  
  96. EOF
  97. sudo sed -i /etc/httpd/conf/httpd.conf \
  98. -e 's/^#LoadModule ssl_module/LoadModule ssl_module/g' \
  99. -e 's/^#LoadModule socache_shmcb_module/LoadModule socache_shmcb_module/g'
  100. cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
  101. Include conf/extra/httpd-ssl.conf
  102. EOF
  103.  
  104. # rewrite configuration.
  105. sudo sed -i /etc/httpd/conf/httpd.conf \
  106. -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/g'
  107. cat << EOF | sudo tee /etc/httpd/conf/extra/redirect-to-https.conf
  108. RewriteEngine On
  109. RewriteCond %{HTTPS} off
  110. RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
  111. EOF
  112. cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
  113. Include conf/extra/redirect-to-https.conf
  114. EOF
  115.  
  116. # passenger configuration.
  117. sudo gem install --no-user-install passenger
  118. cd /opt/ruby2.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.11/bin
  119. echo "1" | sudo ./passenger-install-apache2-module
  120. cat << EOF | sudo tee /etc/httpd/conf/extra/passenger.conf
  121. PassengerRoot /opt/ruby2.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.11
  122. PassengerDefaultRuby /opt/ruby2.3/bin/ruby-2.3
  123. PassengerDefaultUser http
  124. RailsBaseURI /redmine
  125. EOF
  126. cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
  127. LoadModule passenger_module \
  128. /opt/ruby2.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.11/buildout/apache2/mod_passenger.so
  129. Include conf/extra/passenger.conf
  130. EOF
  131.  
  132. # redmine configuration.
  133. sudo ln -s /usr/share/webapps/redmine/public /srv/http/redmine
  134. cat << EOF | sudo tee /etc/httpd/conf/extra/redmine.conf
  135. <Directory /redmine>
  136. Options FollowSymLinks
  137. PassengerResolveSymlinksInDocumentRoot on
  138. AllowOverride None
  139. </Directory>
  140. EOF
  141. cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
  142. Include conf/extra/redmine.conf
  143. EOF
  144.  
  145. sudo systemctl restart httpd
  146. }
  147.  
  148. redmine_main()
  149. {
  150. mysql_install
  151. redmine_install
  152. apache_install
  153. }
  154.  
  155. redmine_main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement