summaryrefslogtreecommitdiff
path: root/vagrant/setup.sh
blob: e0df50110d25fe5efd315d044aa53129e8fb3ead (plain)
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
#!/usr/bin/env bash

script_log() {
	echo -e "[setup.sh] >>> $@"
}

APP_DIR=$1
CHRUBY_PATH=$2

source $CHRUBY_PATH

RUBY_VER_NUM=$(cat $APP_DIR/.ruby-version)
RUBY_VER="ruby-$RUBY_VER_NUM"

if ! command -v ruby >/dev/null || ruby -v | grep -v "$RUBY_VER_NUM" >/dev/null 2>&1; then
    script_log "Downloading, compiling and installing $RUBY_VER... (this will take a while)"
    ruby-install $RUBY_VER
    source $CHRUBY_PATH
    chruby $RUBY_VER
    script_log "Installed ruby version: $(ruby -v)"
fi

if [ ! -f "$APP_DIR/config/nginx.local.conf" ]; then
  script_log "Setting up nginx configuration..."
  cp "$APP_DIR/config/nginx.conf.example" "$APP_DIR/config/nginx.local.conf"
  sed -i -e "s|/home/derpibooru/derpibooru|$APP_DIR|g" "$APP_DIR/config/nginx.local.conf"
  sed -i -e "s/server_name .*;/server_name derp.lc;/" "$APP_DIR/config/nginx.local.conf"
fi

if [ ! -f "$APP_DIR/config/booru/settings.yml" ]; then
  script_log "Copying settings files..."
  cd "$APP_DIR/config/booru"
  for f in *.yml.sample; do
    cp "$f" "${f%.sample}"
  done
fi

cd "$APP_DIR"

script_log "Dropping existing databases (if any)..."
dropdb --if-exists derpibooru_test
dropdb --if-exists derpibooru_development

script_log "Installing bundler gem..."
gem install bundler:2.0.1
bundler config github.https true

script_log "Running setup..."
./bin/setup --root "derp.lc" --seed -a || exit 1