-
Notifications
You must be signed in to change notification settings - Fork 2
/
provision.sh
349 lines (291 loc) · 8.01 KB
/
provision.sh
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/bash
# If you provide any command line argument to this script it will run in "dev
# mode", which means:
# 1. Some prod-specific cleanup is skipped, like removing the setuid bit from
# all binaries.
# 2. Some dev-specific packages will be installed, like Supervisor, Postgres,
# etc.
export DEV_ENV=$1
echo -e "BEGINNING PRODUCTION-SPECIFIC PROVISIONING"
exec 2>&1
set -e
set -x
export PATH
cat > /etc/apt/sources.list <<EOF
deb http://archive.ubuntu.com/ubuntu trusty main
deb http://archive.ubuntu.com/ubuntu trusty-security main
deb http://archive.ubuntu.com/ubuntu trusty-updates main
deb http://archive.ubuntu.com/ubuntu trusty universe
EOF
###################
# PROD: APT DEPS
###################
apt-get update
apt-get install -y --force-yes \
autoconf \
bind9-host \
bison \
build-essential \
coreutils \
curl \
daemontools \
dnsutils \
ed \
git \
graphviz \
imagemagick \
iputils-tracepath \
language-pack-en \
libbz2-dev \
libcap-dev \
libcurl3-dev \
libcurl4-openssl-dev \
libevent-dev \
libffi-dev \
libglib2.0-dev \
libjpeg-dev \
libldap2-dev \
libltdl7 \
libncurses5-dev \
libpcre3-dev \
libpq-dev \
libpq5 \
libreadline6-dev \
libsasl2-dev \
libssl-dev \
libxml2-dev \
libxslt-dev \
libyaml-0-2 \
libyaml-dev \
libzmq-dev \
netcat-openbsd \
openssh-client \
openssh-server \
python \
python-dev \
ruby \
ruby-dev \
socat \
syslinux \
tar \
telnet \
zip \
zlib1g-dev \
#
# https://github.com/docker/docker/issues/963
apt-get install -y --force-yes --no-install-recommends default-jdk
# language packs are usually installed on cedarish, but Ubuntu's been lazy
# about updating their dependencies, leading to things like https://paste.yougov.net/0Tf1g
# comment them out for now.
#apt-cache search language-pack \
#| cut -d ' ' -f 1 \
#| grep -v '^language\-pack\-\(gnome\|kde\)\-' \
#| grep -v '\-base$' \
#| xargs apt-get install -y --force-yes --no-install-recommends
###################
# PROD: CLEANUP
###################
if [ -z "$DEV_ENV" ]; then
echo -e "\nDEV_ENV not set. Doing production cleanup"
cd /
rm -rf /var/cache/apt/archives/*.deb
rm -rf /root/*
rm -rf /tmp/*
# remove SUID and SGID flags from all binaries
function pruned_find() {
find / -type d \( -name dev -o -name proc \) -prune -o $@ -print
}
# Once you do this, sudo is disabled.
pruned_find -perm /u+s | xargs -r chmod u-s
pruned_find -perm /g+s | xargs -r chmod g-s
# remove non-root ownership of files
chown root:root /var/lib/libuuid
set +x
echo -e "\nRemaining suspicious security bits:"
(
pruned_find ! -user root
pruned_find -perm /u+s
pruned_find -perm /g+s
pruned_find -perm /+t
) | sed -u "s/^/ /"
else
echo -e "\nDEV_ENV set. Skipping production cleanup"
fi
echo -e "\nInstalled versions:"
(
git --version
ruby -v
gem -v
python -V
) | sed -u "s/^/ /"
echo -e "\nFINISHED PRODUCTION-SPECIFIC PROVISIONING"
if [ $DEV_ENV ] ; then
echo -e "\nBEGINNING DEV-SPECIFIC PROVISIONING"
# Set root passwd in VM so VR workers can SSH in.
echo "root:vagrant" | chpasswd
cat > /etc/hosts <<EOF
127.0.0.1 localhost vagrant-ubuntu-trusty-64
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
EOF
#######################
# DEV: PACKAGES
#######################
# Keep this package list alphabetized
apt-get install -y --force-yes \
htop \
python-pip \
python-setuptools \
python-software-properties \
rabbitmq-server \
vim \
#
gem install foreman
#######################
# DEV: BASIC/MISC STUFF
#######################
pip install \
mercurial \
virtualenv \
virtualenvwrapper \
#
#######################
# DEV: ~/.bashrc
#######################
cat > /home/vagrant/.bashrc <<EOF
case \$- in
*i*) ;;
*) return;;
esac
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "\$(SHELL=/bin/sh lesspipe)"
if [ -z "\${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=\$(cat /etc/debian_chroot)
fi
case "\$TERM" in
xterm-color) color_prompt=yes;;
esac
#force_color_prompt=yes
if [ -n "\$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_prompt=yes
else
color_prompt=
fi
fi
if [ "\$color_prompt" = yes ]; then
PS1='\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$ '
else
PS1='\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\\$ '
fi
unset color_prompt force_color_prompt
case "\$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;\${debian_chroot:+(\$debian_chroot)}\u@\h: \w\a\]\$PS1"
;;
*)
;;
esac
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "\$(dircolors -b ~/.dircolors)" || eval "\$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias alert='notify-send --urgency=low -i "\$([ \$? = 0 ] && echo terminal || echo error)" "\$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert\$//'\'')"'
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
source /usr/local/bin/virtualenvwrapper.sh
EOF
# end /home/vagrant/.bashrc
###################
# DEV: RABBIT CONFIG
###################
cat > /etc/rabbitmq/enabled_plugins << EOF
[rabbitmq_management].
EOF
/etc/init.d/rabbitmq-server restart
###################
# DEV: POSTGRES
###################
cat > /etc/apt/sources.list.d/pgdg.list <<EOF
deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main
EOF
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
apt-key add -
apt-get update
apt-get install -y --force-yes \
postgresql-9.4 \
postgresql-server-dev-9.4 \
postgresql-contrib-9.4 \
#
cat > /etc/postgresql/9.4/main/pg_hba.conf <<EOF
local all postgres trust
local all all trust
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
local replication postgres trust
EOF
cat > /etc/postgresql/9.4/main/postgresql.conf <<EOF
data_directory = '/var/lib/postgresql/9.4/main'
hba_file = '/etc/postgresql/9.4/main/pg_hba.conf'
ident_file = '/etc/postgresql/9.4/main/pg_ident.conf'
external_pid_file = '/var/run/postgresql/9.4-main.pid'
port = 5432
max_connections = 100
unix_socket_directories = '/var/run/postgresql'
ssl = true
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'
shared_buffers = 128MB
# dynamic_shared_memory_type = posix
log_line_prefix = '%t [%p-%l] %q%u@%d '
log_timezone = 'UTC'
stats_temp_directory = '/var/run/postgresql/9.4-main.pg_stat_tmp'
datestyle = 'iso, mdy'
timezone = 'UTC'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
EOF
service postgresql restart
set +e
createuser -U postgres --superuser vagrant
createdb -U postgres --owner=vagrant vagrant
set -e
###################
# DEV: CLEANUP
###################
# Vagrant has Puppet and Chef in all boxes by default. Clean them out.
apt-get remove -y --force-yes \
chef \
puppet \
#
apt-get autoremove -y --force-yes
echo -e "\nFINISHED DEV-SPECIFIC PROVISIONING"
fi
exit 0