#!/bin/bash # Run: curl -s https://raw.github.com/r888888888/danbooru/master/INSTALL.debian > install.sh ; chmod +x install.sh ; ./install.sh if [[ "$(whoami)" != "root" ]] ; then echo "You must run this script as root" exit 1 fi echo "Danbooru Install" echo "This script will install Ruby, Rails, PostgreSQL, 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 copy and install it in" echo "/var/www/danbooru." echo echo "It is mostly automated but you will receive some prompts when installing" echo "Passenger towards the end of the script." 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 # Install packages echo "Installing packages..." apt-get -y install build-essential automake openssl libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf ncurses-dev sudo gcc g++ libreadline-dev zlib1g-dev flex bison libgd2-noxpm libgd2-noxpm-dev bzip2 ragel memcached libmemcache-dev git curl libcurl4-openssl-dev emacs-nox # Install PostgreSQL 9.1 apt-get -y install python-software-properties add-apt-repository ppa:pitti/postgresql apt-get update apt-get install -y postgresql-9.1 postgresql-contrib-9.1 libpq-dev if [ $? -ne 0 ]; then exit 1 fi # Install RVM echo "Installing RVM..." bash < <(curl -s https://rvm.beginrescueend.com/install/rvm) echo "source /usr/local/rvm/scripts/rvm" >> /etc/bash.bashrc echo "source /usr/local/rvm/scripts/rvm" >> /etc/profile source /usr/local/rvm/scripts/rvm rvm install ruby-1.9.2-p290 --with-openssl-dir=/usr/local rvm 1.9.2 --default # Install gems gem install --no-ri --no-rdoc capistrano gem install --no-ri --no-rdoc capistrano-ext gem install --no-ri --no-rdoc bundler # Install Passenger gem install --no-ri --no-rdoc -v 3.0.8 passenger rvm exec passenger-install-nginx-module rm /opt/nginx/conf/*.default if [ $? -ne 0 ]; then exit 1 fi # Create user account useradd -m danbooru chsh -s /bin/bash danbooru echo "source /usr/local/rvm/scripts/rvm" > /home/danbooru/.bashrc chmod g-wx,o-wx /home/danbooru/.bashrc chown danbooru:danbooru /home/danbooru/.bashrc echo "export rvm_path=/usr/local/rvm" > /etc/rvmrc addgroup wheel usermod -G root,wheel root usermod -G danbooru,wheel danbooru # Update PostgreSQL PG_HBA_FILE="/etc/postgresql/9.1/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 /etc/init.d/postgresql restart sudo -u postgres createuser -s danbooru mkdir -p /var/log/www # Setup nginx curl -s https://raw.github.com/r888888888/danbooru/master/script/install/init_d.templ > /etc/init.d/nginx chmod +x,g-w /etc/init.d/nginx update-rc.d -f nginx defaults mkdir -p /opt/nginx/conf/sites curl -s https://raw.github.com/r888888888/danbooru/master/script/install/nginx.conf > /opt/nginx/conf/nginx.conf curl -s https://raw.github.com/r888888888/danbooru/master/script/install/nginx.danbooru.conf > /opt/nginx/conf/sites/danbooru.conf sed -i -e 's/\$hostname/$HOSTNAME/g' /opt/nginx/conf/sites/danbooru.conf /etc/init.d/nginx start echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers # Setup logrotate LOGROTATE_CONF_FILE="/etc/logrotate.conf" echo >> $LOGROTATE_CONF_FILE echo "/var/log/www/danbooru.access.log" >> $LOGROTATE_CONF_FILE echo "/var/log/www/danbooru.error.log">> $LOGROTATE_CONF_FILE echo "/var/www/danbooru/current/log/production.log {" >> $LOGROTATE_CONF_FILE echo " daily" >> $LOGROTATE_CONF_FILE echo " rotate 3" >> $LOGROTATE_CONF_FILE echo " copytruncate" >> $LOGROTATE_CONF_FILE echo "}" >> $LOGROTATE_CONF_FILE # Setup danbooru account echo "*************************************************" echo "* Enter a new password for the danbooru account *" echo "*************************************************" passwd danbooru sudo -u danbooru createdb danbooru2 cd /home/danbooru sudo -u danbooru mkdir /home/danbooru/apps git clone git://github.com/r888888888/danbooru.git danbooru chown -R danbooru:danbooru danbooru cap deploy:setup cap deploy:update_code cap deploy:migrate chown danbooru:danbooru /var/www/danbooru/shared/log/development.log echo echo echo "**************************************************************" echo "* Danbooru has now been setup on this computer and should be *" echo "* accessible from the web. Go ahead and create an account. *" echo "* The first account will automatically be made an admin. You *" echo "* can edit the configuration files by editing *" echo "* /var/www/danbooru/shared/config/local_config and *" echo "* /var/www/danbooru/shared/config/database.yml *" echo "**************************************************************"