7thwraith

Danbooru Install Script with Moe Via Passenger for Debian

Aug 11th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $USER != root ] ; then
  4.   echo "You must run this script as root"
  5.   exit 1
  6. fi
  7.  
  8. echo "Danbooru Install"
  9. echo "This script will install Ruby, Rails, PostgreSQL, Unicorn, and Nginx. By the end,"
  10. echo "you should be able to connect to the server and create an account."
  11. echo
  12. echo "It will create a new user called danbooru which will run the Danbooru"
  13. echo "processes. It will download the latest trunk copy or v1.16.0 and install it in"
  14. echo "/var/www/danbooru. It will run unicorn, starting on port 8050"
  15. echo
  16. echo
  17. echo -n "Enter the hostname for this server (ex: danbooru.donmai.us): "
  18. read hostname
  19.  
  20. if [ -z $hostname ] ; then
  21.   echo "Must enter a hostname"
  22.   exit 1
  23. fi
  24.  
  25. echo -n "Enter a name for the site (default: Danbooru): "
  26. read sitename
  27.  
  28. if [ -z $sitename ] ; then
  29.   sitename=Danbooru
  30. fi
  31.  
  32. echo -n "Enter a path for danbooru (default: /var/www/danbooru): "
  33. read danboorupath
  34.  
  35. if [ -z $danboorupath ] ; then
  36.   danboorupath="/var/www/danbooru"
  37. fi
  38.  
  39. echo -n "Which danbooru version? [trunk, 1.16.0, 1.18.0, moe]"
  40. read danbooruversion
  41.  
  42. if [ -z $danbooruversion ] ; then
  43.   danbooruversion="1.16.0"
  44. fi
  45.  
  46.  
  47. # Install packages
  48. echo "install required packages via apt-get"
  49. apt-get -y install gcc g++ make libreadline5-dev zlib1g-dev flex bison libgd2-noxpm libgd2-noxpm-dev bzip2 postgresql-8.4 postgresql-contrib-8.4 libpq-dev ruby ruby1.8-dev ri irb rdoc rubygems ragel memcached libmemcache-dev subversion nginx libopenssl-ruby libxml2-dev libxslt-dev libcurl4-openssl-dev
  50.  
  51. # Install Ruby gems
  52. echo "install Ruby/Rails"
  53.  
  54. # this bypasses the problem with debian's stupid old version of rubygems
  55. # html5 requires hoe, but not the most recent version
  56. gem install hoe --version=2.2.0 --no-ri --no-rdoc
  57.  
  58. for i in postgres diff-lcs html5 memcache-client aws-s3 json mechanize net-sftp passenger ; do gem install $i --no-ri --no-rdoc ; done
  59.  
  60. gem install rails --version=2.2.2 --no-ri --no-rdoc
  61.  
  62. # Create user account
  63. echo "create danbooru user, allow db access"
  64.  
  65. useradd -m danbooru
  66. PG_HBA_FILE="/etc/postgresql/8.4/main/pg_hba.conf"
  67. echo "local    all         postgres,danbooru                              trust" > $PG_HBA_FILE
  68. echo "host     all         postgres,danbooru          127.0.0.1/32        trust" >> $PG_HBA_FILE
  69.  
  70. if [ -f /etc/init.d/postgresql-8.4 ]; then /etc/init.d/postgresql-8.4 restart; else /etc/init.d/postgresql restart; fi
  71.  
  72. # Install Danbooru
  73. cd /var/www
  74.  
  75. echo "installing danbooru source"
  76.  
  77. case "$danbooruversion" in
  78.         1.16.0)
  79.                 echo "installing version: 1.16.0"
  80.                 svn export svn://donmai.us/danbooru/tags/danbooru-1.16.0 danbooru
  81.                 ;;
  82.         1.18.0)
  83.                 echo "installing version: 1.18.0"
  84.                 svn export svn://donmai.us/danbooru/tags/danbooru-1.18.0 danbooru
  85.                 ;;
  86.         trunk)
  87.                 echo "installing version: trunk"
  88.                 svn export svn://donmai.us/danbooru/trunk danbooru
  89.                 ;;
  90.  
  91.         moe)
  92.                 echo "installing imouto version: trunk"
  93.                 svn export http://svn.imouto.org/repo/svn/trunk/moe/ danbooru
  94.                 ;;
  95.         tar16) 
  96.                 echo "deflating tgz danbooru-1.16.0.tgz"
  97.                 tar xfz /tmp/danbooru-1.16.0.tgz -C /var/www
  98.                 ;;
  99.         tar18)
  100.                 echo "deflating tgz danbooru-1.18.0.tgz"
  101.                 tar xfz /tmp/danbooru-1.18.0.tgz -C /var/www
  102.                 ;;
  103. esac
  104.  
  105. chown -R danbooru:danbooru danbooru
  106. cd danbooru
  107. mkdir -p public/data/sample
  108. cd config
  109. cp database.yml.example database.yml
  110. cp local_config.rb.example local_config.rb
  111. sed -i -e "s/DAN_HOSTNAME/$hostname/g" local_config.rb
  112. sed -i -e "s/DAN_SITENAME/$sitename/g" local_config.rb
  113. cd ../lib/danbooru_image_resizer
  114. ruby extconf.rb
  115. make
  116. cd ../..
  117.  
  118. echo "installing danbooru database"
  119.  
  120. apt-get install sudo
  121. sudo -u postgres createuser -s danbooru
  122. sudo -u danbooru createdb danbooru
  123. sudo -u danbooru createdb danbooru_dev
  124. sudo -u danbooru createdb danbooru_test
  125. sudo -u danbooru psql danbooru < db/postgres.sql
  126. sudo -u danbooru psql danbooru_dev < db/postgres.sql
  127. sudo -u danbooru psql danbooru_test < db/postgres.sql
  128.  
  129. # I did not run this command when I ran it, but maybe it'll do something useful...
  130. if [ "$danbooruversion" = "1.18.0" || "$danbooruversion" = "trunk" ]; then
  131.     echo "initialising database"
  132.    
  133.     script/db-init.sh
  134.     script/db-init.sh
  135.     script/db-init.sh
  136.    
  137.     #### app/controller/application_controller in application umbenenen
  138.     mv app/controllers/application_controller.rb app/controllers/application.rb
  139.     #### config/envirnment.rb anpassen. ruby version rausnehmen
  140.     sed -i -e "/^RAILS_GEM_VERSION/d" config/environment.rb
  141.     ### middle ware entfernen
  142.     sed -i -e "/^config.middleware.use/d" config/environments/development.rb
  143. fi
  144.  
  145.  
  146.  
  147. # Install latest gems
  148.  
  149. echo "installing the CORRECT RAIL"
  150. apt-get install sudo
  151. cd /var/www/danbooru
  152. gem install -v=2.3.11 rails --no-ri --no-rdoc
  153. sudo -u danbooru /var/lib/gems/1.8/bin/rake db:migrate RAILS_ENV=production
  154.  
  155. # Install dos2unix
  156.  
  157. apt-get install dos2unix
  158.  
  159. # Install and configure Passenger
  160.  
  161. echo "installing Phusion Passenger"
  162. /var/lib/gems/1.8/bin/passenger-install-nginx-module --auto
  163.  
  164. # Configure nginx
  165.  
  166. cd /opt/nginx/conf
  167. rm -f nginx.conf
  168. wget http://pastebin.com/raw.php?i=6yrJr5s5
  169. mv raw.php?i=6yrJr5s5 nginx.conf
  170. dos2unix nginx.conf
  171.  
  172. cd /etc/init.d
  173. rm -f nginx
  174. wget http://pastebin.com/raw.php?i=ptFB0Txh
  175. mv raw.php?i=ptFB0Txh nginx
  176. dos2unix nginx
  177.  
  178. # I don't even...
  179.  
  180. pgrep nginx
  181. kill 873
  182.  
  183.  
  184. # Start nginx
  185. chmod a+x /etc/init.d/nginx
  186. /etc/init.d/nginx start
  187.  
  188. echo
  189. echo "I'm done!"
  190. echo "You should probably set the password for the danbooru account (run passwd danbooru)."
Advertisement
Add Comment
Please, Sign In to add comment