#!/bin/bash #### http://tech.tomgoren.com/archives/245 #### http://animebsd.net/archives/2528 #### http://trac.donmai.us/browser/danbooru/trunk/INSTALL.debian #### root@danbooru:/var/www/danbooru# vim app/models/post_methods/file_methods.rb #### sftp albert maskieren if [ $USER != root ] ; then echo "You must run this script as root" exit 1 fi echo "Danbooru Install" echo "This script will install Ruby, Rails, PostgreSQL, Unicorn, and Nginx. By the end," echo "you should be able to connect to the server and create an account." echo echo "It will create a new user called danbooru which will run the Danbooru" echo "processes. It will download the latest trunk copy or v1.16.0 and install it in" echo "/var/www/danbooru. It will run unicorn, starting on port 8050" echo echo echo -n "Enter the hostname for this server (ex: danbooru.donmai.us): " read hostname if [ -z $hostname ] ; then echo "Must enter a hostname" exit 1 fi echo -n "Enter a name for the site (default: Danbooru): " read sitename if [ -z $sitename ] ; then sitename=Danbooru fi echo -n "Enter a path for danbooru (default: /var/www/danbooru): " read danboorupath if [ -z $danboorupath ] ; then danboorupath="/var/www/danbooru" fi echo -n "Which danbooru version? [trunk, 1.16.0, 1.18.0]" read danbooruversion if [ -z $danbooruversion ] ; then danbooruversion="1.16.0" fi # Install packages echo "install required packages via apt-get" apt-get -qq -y install sudo 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 rake libopenssl-ruby libxml2-dev libxslt-dev byobu vim htop # Install Ruby gems echo "install Ruby/Rails/Unicorn" gem install hoe --version=2.2.0 --no-ri --no-rdoc for i in postgres diff-lcs html5 unicorn memcache-client aws-s3 json mechanize net-sftp sys-cpu ; do gem install $i --no-ri --no-rdoc ; done gem install rails --version=2.2.2 --no-ri --no-rdoc # Create user account echo "create danbooru user, allow db access" useradd -m danbooru PG_HBA_FILE="/etc/postgresql/8.4/main/pg_hba.conf" echo "local all postgres,danbooru trust" > $PG_HBA_FILE echo "host all postgres,danbooru 127.0.0.1/32 trust" >> $PG_HBA_FILE if [ -f /etc/init.d/postgresql-8.4 ]; then /etc/init.d/postgresql-8.4 restart; else /etc/init.d/postgresql restart; fi # Install Danbooru cd /var/www echo "installing danbooru source" case "$danbooruversion" in 1.16.0) echo "installing version: 1.16.0" svn export svn://donmai.us/danbooru/tags/danbooru-1.16.0 danbooru ;; 1.18.0) echo "installing version: 1.18.0" svn export svn://donmai.us/danbooru/tags/danbooru-1.18.0 danbooru ;; trunk) echo "installing version: trunk" svn export svn://donmai.us/danbooru/trunk danbooru ;; tar16) echo "deflating tgz danbooru-1.16.0.tgz" tar xfz /tmp/danbooru-1.16.0.tgz -C /var/www ;; tar18) echo "deflating tgz danbooru-1.18.0.tgz" tar xfz /tmp/danbooru-1.18.0.tgz -C /var/www ;; esac chown -R danbooru:danbooru danbooru cd danbooru mkdir -p public/data/sample cd config cp database.yml.example database.yml cp local_config.rb.example local_config.rb sed -i -e "s/DAN_HOSTNAME/$hostname/g" local_config.rb sed -i -e "s/DAN_SITENAME/$sitename/g" local_config.rb cd ../lib/danbooru_image_resizer ruby extconf.rb make cd ../.. ### Database anlegen echo "installing danbooru database" sudo -u postgres createuser -s danbooru sudo -u danbooru createdb danbooru sudo -u danbooru createdb danbooru_dev sudo -u danbooru createdb danbooru_test sudo -u danbooru psql danbooru < db/postgres.sql sudo -u danbooru psql danbooru_dev < db/postgres.sql sudo -u danbooru psql danbooru_test < db/postgres.sql if [ "$danbooruversion" = "1.18.0" || "$danbooruversion" = "trunk" ]; then echo "initialising database" script/db-init.sh script/db-init.sh script/db-init.sh #### app/controller/application_controller in application umbenenen mv app/controllers/application_controller.rb app/controllers/application.rb #### config/envirnment.rb anpassen. ruby version rausnehmen sed -i -e "/^RAILS_GEM_VERSION/d" config/environment.rb ### middle ware entfernen sed -i -e "/^config.middleware.use/d" config/environments/development.rb fi echo "initialising production database" sudo -u danbooru RAILS_ENV=production rake db:migrate # Set up nginx echo "generating nginx danbooru conf" nginx_danbooru_conf="/etc/nginx/sites-enabled/danbooru.conf" echo 'server {' > $nginx_danbooru_conf echo ' listen 80;' >> $nginx_danbooru_conf echo " server_name $hostname;" >> $nginx_danbooru_conf echo ' location ~ /\.svn { deny all; }' >> $nginx_danbooru_conf echo ' location / {' >> $nginx_danbooru_conf echo " root $danboorupath/public;" >> $nginx_danbooru_conf echo ' try_files $uri /maintenance.html @danbooru;' >> $nginx_danbooru_conf echo ' client_max_body_size 30m;' >> $nginx_danbooru_conf echo ' expires max;' >> $nginx_danbooru_conf echo ' }' >> $nginx_danbooru_conf echo ' location @danbooru {' >> $nginx_danbooru_conf echo ' proxy_set_header X-Real-IP $remote_addr;' >> $nginx_danbooru_conf echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $nginx_danbooru_conf echo ' proxy_set_header Host $http_host;' >> $nginx_danbooru_conf echo ' proxy_redirect off;' >> $nginx_danbooru_conf echo ' proxy_pass http://127.0.0.1:8050;' >> $nginx_danbooru_conf echo ' }' >> $nginx_danbooru_conf echo '}' >> $nginx_danbooru_conf /etc/init.d/nginx restart ### unicorn config file echo "generating unicorn danoobru conf" mkdir /etc/unicorn unicorn_conf="/etc/unicorn/danbooru.conf" echo "RAILS_ROOT=$danboorupath" > $unicorn_conf echo "RAILS_ENV=production" >> $unicorn_conf ### unicorn danbooru-config file echo "generating danbooru unicorn conf" danbooru_unicorn_conf="$danboorupath/config/unicorn.rb" echo "app_path = \"$danboorupath\"" > $danbooru_unicorn_conf echo -n >> $danbooru_unicorn_conf echo 'listen 8050' >> $danbooru_unicorn_conf echo 'worker_processes 2' >> $danbooru_unicorn_conf echo 'pid "#{app_path}/tmp/pids/unicorn.pid"' >> $danbooru_unicorn_conf echo 'stderr_path "#{app_path}/log/unicorn.log"' >> $danbooru_unicorn_conf echo 'stdout_path "#{app_path}/log/unicorn.log"' >> $danbooru_unicorn_conf ### unicron init skript echo "downloading unicorn init skript" unicorn_rails_path="/var/lib/gems/1.8/bin/unicorn_rails" cd /etc/init.d/ wget http://tech.tomgoren.com/wp-content/uploads/unicorn_init.gz gunzip unicorn_init.gz sed -i -e "s|/usr/local/bin/unicorn_rails|$unicorn_rails_path|g" unicorn_init chmod +x unicorn_init /etc/init.d/unicorn_init start echo echo echo echo "I'm done!" echo "You should probably set the password for the danbooru account (run passwd danbooru)."