#!/usr/bin/env bash APP_USER=vagrant APP_DIR=/home/$APP_USER/derpibooru CHRUBY_PATH=/etc/profile.d/chruby.sh echo "debconf debconf/frontend select noninteractive" | debconf-set-selections sed -i -e 's/\(AcceptEnv LANG LC_\*\)/#\1/' /etc/ssh/sshd_config service sshd restart add_key() { wget -qO - "$1" | apt-key add - &>/dev/null } install_packages() { apt-get install -y $@ } script_log() { echo "[install.sh] >>> $@" } # Vagrant setup, if required if [ -e /vagrant ]; then ln -s /vagrant "$APP_DIR" chown -R "$APP_USER:$APP_USER" "/home/$APP_USER" fi # Necessary for apt and elasticsearch to succeed in the next step if ! install_packages apt-transport-https default-jre-headless ; then script_log "Failed to install prerequisites; fix the errors above and re-run \`vagrant provision\`" exit 1 fi if [ ! -f /etc/apt/sources.list.d/elasticsearch-6.x.list ]; then add_key https://packages.elastic.co/GPG-KEY-elasticsearch echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" > /etc/apt/sources.list.d/elasticsearch-6.x.list fi if [ ! -f /etc/apt/sources.list.d/pgdg.list ]; then add_key https://www.postgresql.org/media/keys/ACCC4CF8.asc echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list fi if [ ! -f /etc/apt/sources.list.d/nginx.list ]; then add_key http://nginx.org/keys/nginx_signing.key echo "deb http://nginx.org/packages/debian/ buster nginx" > /etc/apt/sources.list.d/nginx.list fi if [ ! -f /etc/apt/sources.list.d/nodesource.list ]; then add_key https://deb.nodesource.com/gpgkey/nodesource.gpg.key echo 'deb https://deb.nodesource.com/node_12.x buster main' > /etc/apt/sources.list.d/nodesource.list fi script_log "Updating..." apt-get update script_log "Installing packages..." if ! install_packages elasticsearch ffmpeg gifsicle git inkscape libcurl4-openssl-dev libicu-dev \ libjpeg-progs libpq-dev libreadline-dev libxml2-dev nodejs optipng libgit2-27 \ redis-server postgresql-11 nginx libbison-dev libffi-dev libpng-dev libgdbm-dev \ libncurses5-dev libssl-dev libyaml-dev ; then script_log "Package installation failed; fix the errors above and re-run \`vagrant provision\`" exit 1 fi script_log "Configuring PostgreSQL..." sed -i -e 's/md5/trust/' /etc/postgresql/11/main/pg_hba.conf service postgresql restart script_log "Creating PostgreSQL user..." sudo -u postgres createuser -s $APP_USER script_log "Configuring Elasticsearch..." sed -i -e 's/\(-Xm[sx]\)1g/\1256m/' /etc/elasticsearch/jvm.options systemctl enable elasticsearch systemctl start elasticsearch if ! type ruby-install >/dev/null 2>&1; then script_log "Installing ruby-install..." cd /usr/local/src wget -qO ruby-install-0.7.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.7.0.tar.gz tar -xzvf ruby-install-0.7.0.tar.gz >/dev/null cd ruby-install-0.7.0/ make install rm /usr/local/src/ruby-install-0.7.0.tar.gz echo "export RAILS_ENV=development" > /etc/profile.d/rails_env.sh fi if [ -f "$CHRUBY_PATH" ]; then source $CHRUBY_PATH fi if ! type chruby >/dev/null 2>&1; then script_log "Installing chruby..." cd /usr/local/src wget -qO chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz tar -xzvf chruby-0.3.9.tar.gz >/dev/null cd chruby-0.3.9/ make install >/dev/null ./scripts/setup.sh rm /usr/local/src/chruby-0.3.9.tar.gz echo -e \ "if [ -n \"\$BASH_VERSION\" ] || [ -n \"\$ZSH_VERSION\" ]; then source /usr/local/share/chruby/chruby.sh source /usr/local/share/chruby/auto.sh fi" > $CHRUBY_PATH fi if ! (which eslint && which stylelint); then script_log "Installing linters..." npm -g install eslint stylelint fi script_log "Stopping derpibooru systemd service..." systemctl stop derpibooru if ! sudo -u $APP_USER bash "$APP_DIR/vagrant/setup.sh" "$APP_DIR" "$CHRUBY_PATH" ; then script_log "Error during setup; fix the errors above and re-run \`vagrant provision\`" exit 1 fi script_log "Copying systemd unit file..." cp "$APP_DIR/vagrant/derpibooru.service" /lib/systemd/system/ systemctl daemon-reload systemctl enable derpibooru script_log "Copy nginx config file..." cp "$APP_DIR/config/nginx.local.conf" /etc/nginx/conf.d/default.conf systemctl restart nginx systemctl enable nginx script_log "Restarting derpibooru systemd service..." systemctl restart derpibooru script_log "Install complete. You can log into the site using the following credentials:" script_log "+----------------------------+" script_log "| URL: http://derp.lc/ |" script_log "| E-mail: admin@example.com |" script_log "| Password: trixieisbestpony |" script_log "+----------------------------+" script_log "You can find additional users' credentials in db/seeds_development.yml"