public
Last active

Moebooru setup

  • Download Gist
setup.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
#!/bin/bash
 
echo "This will install moebooru 3.2.0"
echo "This should be ran as root"
echo "This will install 2 extra PPAs"
echo "This script assumes fresh install of Ubuntu Server 12.04.1 with just openssh server installed"
 
echo "Enter the hostname for this server (ex: moeboo.ru): "
read HOSTNAME
 
if [[ -z "$HOSTNAME" ]] ; then
echo "Must enter a hostname"
exit 1
fi
 
echo "Enter a name for the site (default: Moebooru): "
read SITENAME
 
if [[ -z "$SITENAME" ]] ; then
SITENAME=Moebooru
fi
 
#add extra ppas
apt-get install python-software-properties -y
apt-add-repository ppa:pitti/postgresql -y
apt-add-repository ppa:brightbox/ruby-ng -y
 
#upgrade all packages after fresh install
apt-get update
apt-get upgrade -y
apt-get install postgresql-contrib-9.2 postgresql-9.2 libpq-dev libxml2-dev libxslt-dev mercurial jhead build-essential libgd2-noxpm-dev ruby1.9.3 nginx nodejs memcached postfix -y
 
#add moebooru user
useradd -m moebooru
chsh -s /bin/bash moebooru
 
#setup dbs
echo "Creating moebooru postgresql user and db"
su postgres -c "createuser moe -d -s"
 
echo "Cloning moebooru in to /home/moebooru/"
cd /home/moebooru/
hg clone https://bitbucket.org/edogawaconan/moebooru live
cd live
hg checkout 3.2.0-release
 
#install gems
echo "Installing gems"
 
echo "install: --no-rdoc --no-ri" > /etc/gemrc
echo "update: --no-rdoc --no-ri" >> /etc/gemrc
gem install bundler
cd /home/moebooru/live/
bundle install
 
#compile resizer
echo "Compiling resizer"
cd /home/moebooru/live/lib/danbooru_image_resizer/
ruby extconf.rb
make
cd /home/moebooru/live/
 
#setup db
echo "Configuring and setting up moebooru database"
 
echo "local all postgres peer" > /etc/postgresql/9.2/main/pg_hba.conf
echo "local all all peer" >> /etc/postgresql/9.2/main/pg_hba.conf
echo "host all all 127.0.0.1/32 trust" >> /etc/postgresql/9.2/main/pg_hba.conf
 
service postgresql restart
 
cd /home/moebooru/live/config/
echo "login: &login" > database.yml
echo " adapter: postgresql" >> database.yml
echo " username: moe" >> database.yml
echo " host: 127.0.0.1" >> database.yml
echo "production:" >> database.yml
echo " database: moebooru" >> database.yml
echo " <<: *login" >> database.yml
echo "development:" >> database.yml
echo " database: moebooru" >> database.yml
echo " <<: *login" >> database.yml
echo "test:" >> database.yml
echo " database: moebooru" >> database.yml
echo " <<: *login" >> database.yml
 
 
mv local_config.rb.example local_config.rb
RAILS_ENV=production bundle exec rake db:create
 
su postgres -c "psql moebooru < /home/moebooru/live/db/structure.sql"
 
#db setup complete
echo "Database setup complete"
 
#at this point the site works in development mode.
#now to get it to work with nginx proxy
 
echo "Configuring nginx and Unicorn"
 
mkdir /etc/nginx/moebooru
 
#generic config for moebooru
curl -s https://raw.github.com/gist/3808792/b20fed3afdd76e3f8664640e4594502a5562f6b6/generic.conf > /etc/nginx/moebooru/generic.conf
 
#site specific
curl -s https://raw.github.com/gist/3808791/5900a35f8194f5a48fcfcbbb0647941764cfa46f/moebooru.conf > /etc/nginx/sites-available/moebooru.conf
 
#find REPLACEWITHIPADDRESS replace with ip address
#find REPLACEWITHHOSTNAME put in hostname
 
IPADDRESS=`curl -s ifconfig.me/ip`
 
sed -i "s/REPLACEWITHHOSTNAME/$HOSTNAME/g" /etc/nginx/moebooru/generic.conf
sed -i "s/REPLACEWITHHOSTNAME/$HOSTNAME/g" /etc/nginx/sites-available/moebooru.conf
sed -i "s/REPLACEWITHIPADDRESS/$IPADDRESS/g" /etc/nginx/sites-available/moebooru.conf
 
ln -s /etc/nginx/sites-available/moebooru.conf /etc/nginx/sites-enabled/moebooru.conf
 
#get unicorn configs
curl -s https://raw.github.com/gist/3808825/240dc77ef383b3a640eb0c747ef3daedcf7b1eb1/unicorn.rb > /home/moebooru/live/config/unicorn.rb
 
#insert sitename and hostname in config
 
sed -i "s/DAN_SITENAME/$SITENAME/g" /home/moebooru/live/config/local_config.rb
sed -i "s/DAN_HOSTNAME/$HOSTNAME/g" /home/moebooru/live/config/local_config.rb
 
#restart nginx and start unicorn
service nginx restart
mkdir /home/moebooru/live/public/data/preview
mkdir /home/moebooru/live/public/data/sample
mkdir /home/moebooru/live/tmp/pids/
chown -R moebooru:moebooru /home/moebooru/live/
su moebooru -c "cd /home/moebooru/live/ && RAILS_ENV=production bundle exec rake db:migrate"
su moebooru -c "cd /home/moebooru/live/ && RAILS_ENV=production bundle exec rake assets:precompile"
su moebooru -c "cd /home/moebooru/live/ && RAILS_ENV=production bundle exec unicorn -c /home/moebooru/live/config/unicorn.rb -D"
su moebooru -c "cd /home/moebooru/live/ && RAILS_ENV=production bundle exec rake job:start"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.