-
Notifications
You must be signed in to change notification settings - Fork 4
/
dockyard
245 lines (216 loc) · 5.08 KB
/
dockyard
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
#!/bin/bash
set -e
function info {
echo "[$log_prefix] $@"
}
function error {
echo "[$log_prefix] $@" > /dev/stderr
}
function enable_universe {
if [ `grep universe /etc/apt/sources.list 2>&1 > /dev/null` ]; then
info "enabling universe"
sed 's/main/universe main/' -i /etc/apt/sources.list
apt-get update
else
info "universe already enabled"
fi
}
function download_url {
current_url=$1
root=$2
if [ "$root" == "" ]; then
root=/tmp
fi
dst="$root/$(basename $current_url)"
mkdir -p $(dirname $dst)
if [ ! -e $dst ]; then
info "fetching $current_url to $dst"
curl -s -o $dst.tmp $current_url && mv $dst.tmp $dst
else
info "already fetched $current_url"
fi
}
function configure {
assign_variables
marker=/tmp/$name.configured
if [ ! -e $marker ]; then
cd /tmp/$name
info "configuring"
if [ "$configure_cmd" == "" ]; then
./configure
else
$configure_cmd
fi
touch $marker
info "configured"
else
info "already configured"
fi
}
function build {
assign_variables
marker=/tmp/$name.built
if [ ! -e $marker ]; then
cd /tmp/$name
info "building"
make
touch $marker
else
info "already built"
fi
}
function install_binaries {
assign_variables
marker=/tmp/$name.installed
if [ ! -e $marker ]; then
cd /tmp/$name
info "installing"
make install
touch $marker
else
info "already installed"
fi
}
function assign_variables {
if [ "$url" == "" ]; then
error "url must be set"
exit 1
fi
file_name=$(basename $url)
name=$(echo $file_name | sed 's/\.tar\.gz//')
}
function extract {
assign_variables
marker=/tmp/$file_name.extracted$
if [ ! -e $marker ]; then
info "extracting"
cd /tmp
tar xfz $file_name
touch $marker
else
info "already extracted"
fi
}
function setup {
info "setup"
enable_universe
info "install build packages"
apt-get install build-essential curl git-core -y
info "installed build packages"
}
function install_required_packages {
if [ "$required_packages" != "" ]; then
info "installing required packages"
apt-get install -y $required_packages
info "installed required packages"
else
info "no packages to install"
fi
}
function install_postgresql {
url=http://ftp.postgresql.org/pub/source/v$version/postgresql-$version.tar.gz
configure_cmd="./configure --with-libxml --with-python --with-libxslt --with-openssl"
required_packages="libxslt1-dev libxml2-dev python-dev libreadline-dev bison flex"
download_url $url
install_required_packages
extract
configure
build
install_binaries
}
function apply_nginx_syslog_patch {
if [ $(echo $version | grep "^1\.4") ]; then
syslog_patch_version=1.3.14
else
syslog_patch_version=1.2.7
fi
syslog_config_url="https://raw.github.com/yaoweibin/nginx_syslog_patch/master/config"
syslog_patch_url="https://raw.github.com/yaoweibin/nginx_syslog_patch/master/syslog_$syslog_patch_version.patch"
download_url $syslog_config_url /tmp/nginx_syslog_patch
download_url $syslog_patch_url /tmp/nginx_syslog_patch
marker=/tmp/nginx_syslog_patch.applied
if [ ! -e $marker ]; then
cd /tmp/$name
patch -p1 < /tmp/nginx_syslog_patch/$(basename $syslog_patch_url)
touch $marker
else
info "already applied nginx syslog patch"
fi
}
function install_nginx {
url="http://nginx.org/download/nginx-$version.tar.gz"
required_packages="unzip libpcre3 libpcre3-dev libssl-dev libpcrecpp0 zlib1g-dev libgd2-xpm-dev"
configure_cmd="./configure --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-http_stub_status_module"
download_url $url
install_required_packages
extract
# apply_nginx_syslog_patch
configure
build
install_binaries
}
function install_ruby {
minor_version=$(echo $version | cut -b 1-3)
url="http://ftp.ruby-lang.org/pub/ruby/$minor_version/ruby-$version.tar.gz"
required_packages="libyaml-dev libxml2-dev libxslt1-dev libreadline-dev libssl-dev zlib1g-dev"
configure_cmd="./configure --disable-install-doc"
download_url $url
install_required_packages
extract
configure
build
install_binaries
}
function install_redis {
url=http://download.redis.io/releases/redis-$version.tar.gz
download_url $url
extract
build
install_binaries
}
function install_memcached {
url="http://memcached.googlecode.com/files/memcached-$version.tar.gz"
required_packages="libevent-dev"
download_url $url
install_required_packages
extract
configure
build
install_binaries
}
function do_install {
name=$1
version=$2
setup
case $name in
"ruby")
install_ruby $version
;;
"nginx")
install_nginx $version
;;
"postgresql")
install_postgresql $version
;;
"memcached")
install_memcached $version
;;
"redis")
install_redis $version
;;
"*")
log "recipe $name unknwon"
esac
}
case $1 in
"enable_universe")
enable_universe
;;
"install")
log_prefix="$2:$3"
do_install $2 $3
;;
*)
error "action $1 unknwon. use any of enable_universe, install"
;;
esac