From dbf46d3522cd26f0a9085f8ce77fd7f5f0efffd4 Mon Sep 17 00:00:00 2001 From: Kira Date: Thu, 31 Jan 2019 12:27:40 -0800 Subject: [PATCH] Initial setup script changes as required by danbooru. --- .ruby-version | 2 +- Gemfile.lock | 2 +- INSTALL.debian | 34 +++++++------ INSTALL_DEV.ubuntu | 114 ++++++++++++++++++++++++++++++++++++++++++ config/application.rb | 2 +- config/deploy.rb | 4 +- 6 files changed, 137 insertions(+), 21 deletions(-) create mode 100644 INSTALL_DEV.ubuntu diff --git a/.ruby-version b/.ruby-version index 4fd0fe3cd..aedc15bb0 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.1 \ No newline at end of file +2.5.3 diff --git a/Gemfile.lock b/Gemfile.lock index 8c6ba7242..c67347ae1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -521,4 +521,4 @@ DEPENDENCIES whenever BUNDLED WITH - 1.16.1 + 2.0.1 diff --git a/INSTALL.debian b/INSTALL.debian index 64e842b0c..58d7aad2f 100644 --- a/INSTALL.debian +++ b/INSTALL.debian @@ -1,9 +1,9 @@ #!/bin/bash -# Run: curl -L -s https://raw.githubusercontent.com/r888888888/danbooru/master/INSTALL.debian -o install.sh ; chmod +x install.sh ; ./install.sh +# Run: curl -L -s https://raw.githubusercontent.com/zwagoth/e621ng/master/INSTALL.debian -o install.sh ; chmod +x install.sh ; ./install.sh -export RUBY_VERSION=2.5.1 -export GITHUB_INSTALL_SCRIPTS=https://raw.githubusercontent.com/r888888888/danbooru/master/script/install +export RUBY_VERSION=2.5.3 +export GITHUB_INSTALL_SCRIPTS=https://raw.githubusercontent.com/zwagoth/e621ng/master/script/install export VIPS_VERSION=8.7.0 if [[ "$(whoami)" != "root" ]] ; then @@ -97,25 +97,26 @@ fi # Install rbenv echo "* Installing rbenv..." cd /tmp -sudo -u danbooru git clone git://github.com/sstephenson/rbenv.git ~danbooru/.rbenv -sudo -u danbooru touch ~danbooru/.bash_profile +sudo -i -u danbooru git clone git://github.com/sstephenson/rbenv.git ~danbooru/.rbenv +sudo -i -u danbooru touch ~danbooru/.bash_profile echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~danbooru/.bash_profile echo 'eval "$(rbenv init -)"' >> ~danbooru/.bash_profile -sudo -u danbooru mkdir -p ~danbooru/.rbenv/plugins -sudo -u danbooru git clone git://github.com/sstephenson/ruby-build.git ~danbooru/.rbenv/plugins/ruby-build -sudo -u danbooru bash -l -c "rbenv install $RUBY_VERSION" -sudo -u danbooru bash -l -c "rbenv global $RUBY_VERSION" +sudo -i -u danbooru mkdir -p ~danbooru/.rbenv/plugins +sudo -i -u danbooru git clone git://github.com/sstephenson/ruby-build.git ~danbooru/.rbenv/plugins/ruby-build +sudo -i -u danbooru bash -l -c "rbenv install $RUBY_VERSION" +sudo -i -u danbooru bash -l -c "rbenv global $RUBY_VERSION" # Generate secret token and secret key echo "* Generating secret keys..." -sudo -u danbooru mkdir ~danbooru/.danbooru/ -sudo -u danbooru sh -c 'openssl rand -hex 32 > ~danbooru/.danbooru/secret_token' -sudo -u danbooru sh -c 'openssl rand -hex 32 > ~danbooru/.danbooru/session_secret_key' +sudo -i -u danbooru mkdir ~danbooru/.danbooru/ +openssl rand -hex 32 > ~danbooru/.danbooru/secret_token +openssl rand -hex 32 > ~danbooru/.danbooru/session_secret_key +chown danbooru:danbooru ~danbooru/.danbooru/* chmod 600 ~danbooru/.danbooru/* # Install gems echo "* Installing gems..." -sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc bundler' +sudo -i -u danbooru bash -l -c 'gem install --no-ri --no-rdoc bundler' echo "* Install configuration scripts..." @@ -123,7 +124,7 @@ echo "* Install configuration scripts..." curl -L -s $GITHUB_INSTALL_SCRIPTS/postgresql_hba_conf -o /etc/postgresql/$PG_VERSION/main/pg_hba.conf /etc/init.d/postgresql restart sudo -u postgres createuser -s danbooru -sudo -u danbooru createdb danbooru2 +sudo -i -u danbooru createdb danbooru2 # Setup nginx curl -L -s $GITHUB_INSTALL_SCRIPTS/nginx.danbooru.conf -o /etc/nginx/sites-enabled/danbooru.conf @@ -138,7 +139,7 @@ echo "* Enter a new password for the danbooru account" passwd danbooru echo "* Setting up SSH keys for the danbooru account" -sudo -u danbooru ssh-keygen +sudo -i -u danbooru ssh-keygen mkdir -p /var/www/danbooru2/shared/config mkdir -p /var/www/danbooru2/shared/data @@ -149,7 +150,7 @@ curl -L -s $GITHUB_INSTALL_SCRIPTS/database.yml.templ -o /var/www/danbooru2/shar curl -L -s $GITHUB_INSTALL_SCRIPTS/danbooru_local_config.rb.templ -o /var/www/danbooru2/shared/config/danbooru_local_config.rb echo "* Almost done! You are now ready to deploy Danbooru onto this server." -echo "* Log into Github and fork https://github.com/r888888888/danbooru into" +echo "* Log into Github and fork https://github.com/zwagoth/e621ng into" echo "* your own repository. Clone your fork onto your local development" echo "* machine and modify the following files:" echo "*" @@ -178,3 +179,4 @@ echo "*" echo "* This will start a web process running on port 3000 that you can" echo "* connect to. This is useful for development and testing purposes." echo "* If something breaks post about it on the Danbooru Github. Good luck!" + diff --git a/INSTALL_DEV.ubuntu b/INSTALL_DEV.ubuntu new file mode 100644 index 000000000..462e13380 --- /dev/null +++ b/INSTALL_DEV.ubuntu @@ -0,0 +1,114 @@ +#!/bin/bash + +# Run: curl -L -s https://raw.githubusercontent.com/zwagoth/e621ng/master/INSTALL.debian -o install.sh ; chmod +x install.sh ; ./install.sh + +export RUBY_VERSION=2.5.3 +export GITHUB_INSTALL_SCRIPTS=https://raw.githubusercontent.com/zwagoth/e621ng/master/script/install +export VIPS_VERSION=8.7.0 + +verlte() { + [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] +} + +verlt() { + [ "$1" = "$2" ] && return 1 || verlte $1 $2 +} + +# Install packages +echo "* Installing packages..." + +if [ -n "$(uname -a | grep Ubuntu)" ] ; then + LIBSSL_DEV_PKG=libssl-dev +else + LIBSSL_DEV_PKG=$( verlt `lsb_release -sr` 9.0 && echo libssl-dev || echo libssl1.0-dev ) +fi +sudo apt-get update +sudo apt-get -y install $LIBSSL_DEV_PKG build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix +sudo apt-get -y install libpq-dev postgresql-client postgresql postgresql-server-dev-10 +sudo apt-get -y install liblcms2-dev libjpeg-turbo8-dev libexpat1-dev libgif-dev libpng-dev libexif-dev + +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - +echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list +curl -sSL https://deb.nodesource.com/setup_10.x | sudo -E bash - +sudo apt-get update +sudo apt-get -y install nodejs yarn +sudo apt-get remove cmdtest + +if [ $? -ne 0 ]; then + echo "* Error installing packages; aborting" + exit 1 +fi + +# compile and install libvips (the version in apt is too old) +cd /tmp +wget -q https://github.com/libvips/libvips/releases/download/v$VIPS_VERSION/vips-$VIPS_VERSION.tar.gz +tar xzf vips-$VIPS_VERSION.tar.gz +cd vips-$VIPS_VERSION +./configure --prefix=/usr +sudo make install +sudo ldconfig + +# Set up Postgres +export PG_VERSION=`pg_config --version | egrep -o '[0-9]{1,}\.[0-9]{1,}'` +if verlte 9.5 $PG_VERSION ; then + # only do this on postgres 9.5 and above + git clone https://github.com/r888888888/test_parser.git /tmp/test_parser + cd /tmp/test_parser + sudo make install +fi + +# Install rbenv +echo "* Installing rbenv..." +cd /tmp +git clone git://github.com/sstephenson/rbenv.git ~/.rbenv +touch ~/.bash_profile +echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile +echo 'eval "$(rbenv init -)"' >> ~/.bash_profile +mkdir -p ~/.rbenv/plugins +git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build +rbenv install $RUBY_VERSION +rbenv global $RUBY_VERSION + +# Generate secret token and secret key +echo "* Generating secret keys..." +mkdir ~/.danbooru/ +openssl rand -hex 32 > ~/.danbooru/secret_token +openssl rand -hex 32 > ~/.danbooru/session_secret_key +chmod 600 ~/.danbooru/* + +# Install gems +echo "* Installing gems..." +gem install --no-ri --no-rdoc bundler + +echo "* Install configuration scripts..." + +# Update PostgreSQL +curl -L -s $GITHUB_INSTALL_SCRIPTS/postgresql_hba_conf -o /etc/postgresql/$PG_VERSION/main/pg_hba.conf +/etc/init.d/postgresql restart +sudo -u postgres createuser -s danbooru +sudo -u postgres createdb danbooru2 + +# Setup nginx +curl -L -s $GITHUB_INSTALL_SCRIPTS/nginx.danbooru.conf -o /etc/nginx/sites-enabled/danbooru.conf +sed -i -e "s/__hostname__/$HOSTNAME/g" /etc/nginx/sites-enabled/danbooru.conf +/etc/init.d/nginx restart + +echo "* Clone the repo into your home folder." +echo "* Copy the database.yml and danbooru_local_config.rb templates from the " +echo "* scripts/install folder into the config folder and edit them to your needs." +echo "* Remember to add 'user: danbooru' to the database yml file for development roles." +echo "* You can then run a server locally without having to deal with deploys" +echo "* by running the following command:" +echo "*" +echo "* bundle install" +echo "* yarn install" +echo "* RAILS_ENV=development bundle exec rake db:migrate" +echo "* bundle exec rails server" +echo "*" +echo "* Run RAILS_ENV=development bundle exec rake db:seed after you have" +echo "* created a new user!" +echo "*" +echo "* This will start a web process running on port 3000 that you can" +echo "* connect to. This is useful for development and testing purposes." +echo "* If something breaks post about it on the Github. Good luck!" + diff --git a/config/application.rb b/config/application.rb index 408263aab..170525703 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,7 +17,7 @@ module Danbooru config.assets.version = '1.0' config.autoload_paths += %W(#{config.root}/app/presenters #{config.root}/app/logical #{config.root}/app/mailers) config.plugins = [:all] - config.time_zone = 'Eastern Time (US & Canada)' + config.time_zone = 'UTC' config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = {:enable_starttls_auto => false} config.action_mailer.perform_deliveries = true diff --git a/config/deploy.rb b/config/deploy.rb index 51a6a1679..498851775 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,9 +1,9 @@ set :stages, %w(production development staging) set :default_stage, "staging" set :application, "danbooru" -set :repo_url, "git://github.com/r888888888/danbooru.git" +set :repo_url, "git://github.com/zwagoth/e621ng.git" set :scm, :git set :deploy_to, "/var/www/danbooru" set :rbenv_ruby, "2.5.1" set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle') -set :branch, ENV.fetch("branch", "master") \ No newline at end of file +set :branch, ENV.fetch("branch", "master")