blob: 47b540b6bd459073ca2ec65fabbba3d76511248a (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#!/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: [email protected] |"
script_log "| Password: trixieisbestpony |"
script_log "+----------------------------+"
script_log "You can find additional users' credentials in db/seeds_development.yml"
|