Skip to content

@dobacco /setup.sh
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Moebooru setup
#!/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.