-
Notifications
You must be signed in to change notification settings - Fork 12
/
bootstrap.sh
221 lines (172 loc) · 5.93 KB
/
bootstrap.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
#!/usr/bin/env bash
setup_ubuntu ()
{
# enable the multiverse package repositories.
sudo sed -i "/^# deb.*multiverse/ s/^# //" /etc/apt/sources.list
if [[ `lsb_release -rs` == "14.04" ]]
then
sudo add-apt-repository --yes ppa:fkrull/deadsnakes
fi
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get dist-upgrade -y
echo Creating 2GB swap file \(this is occationally required when fetching extremely large files\).
# Create swapfile of 2GB with block size 1MB
sudo /bin/dd if=/dev/zero of=/swapfile bs=1024 count=2097152
sudo /sbin/mkswap /swapfile
sudo /sbin/swapon /swapfile
sudo /bin/echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
sudo mount -a
sudo apt-get install -y python3.5 python3.5-dev build-essential postgresql-client postgresql-common libpq-dev postgresql-9.6 unrar
sudo apt-get install -y postgresql-server-dev-9.6 postgresql-contrib libyaml-dev git wget
# Replace system python on 14.04
# Probably not the best idea if you use the system seriously, but
# I don't care for testing.
if [[ `lsb_release -rs` == "14.04" ]]
then
sudo mv /usr/bin/python3 /usr/bin/python3-old
sudo ln -s /usr/bin/python3.5 /usr/bin/python3
fi
# PIL/Pillow support stuff
sudo apt-get install -y libtiff5-dev libjpeg-turbo8-dev zlib1g-dev liblcms2-dev libwebp-dev libxml2 libxslt1-dev
# Install Numpy/Scipy support packages. Yes, scipy depends on FORTAN. Arrrgh
sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
}
build_py_from_sauce_3_5 ()
{
sudo apt-get update
sudo cd /tmp
sudo apt-get install libssl-dev openssl
sudo cd opt
sudo wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
sudo tar -xvzf Python-3.5.2.tgz
cd Python-3.5.2
sudo ./configure
sudo make -j 2
sudo make install
}
build_py_from_sauce_3_4 ()
{
sudo apt-get update
sudo cd /tmp
sudo apt-get install libssl-dev openssl
sudo cd opt
sudo wget https://www.python.org/ftp/python/3.4.5/Python-3.4.5.tgz
sudo tar -xvzf Python-3.4.5.tgz
cd Python-3.4.5
sudo ./configure
sudo make -j 2
sudo make install
}
setup_debian ()
{
sudo apt-get update
sudo apt-get dist-upgrade -y
echo Creating 2GB swap file \(this is occationally required when fetching extremely large files\).
# Create swapfile of 2GB with block size 1MB
sudo /bin/dd if=/dev/zero of=/swapfile bs=1024 count=2097152
sudo /sbin/mkswap /swapfile
sudo /sbin/swapon /swapfile
sudo /bin/echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
sudo mount -a
sudo apt-get install -y build-essential
sudo apt-get install -y libyaml-dev
sudo apt-get install -y unrar
sudo apt-get install -y git
sudo apt-get install -y wget
# PIL/Pillow support stuff
sudo apt-get install -y libtiff5-dev
sudo apt-get install -y libjpeg-turbo8-dev
sudo apt-get install -y zlib1g-dev
sudo apt-get install -y liblcms2-dev
sudo apt-get install -y libwebp-dev
sudo apt-get install -y libxml2
sudo apt-get install -y libxslt1-dev
sudo apt-get install -y libbz2-dev
# Install Numpy/Scipy support packages. Yes, scipy depends on FORTAN. Arrrgh
sudo apt-get install -y gfortran
sudo apt-get install -y libopenblas-dev
sudo apt-get install -y liblapack-dev
# So debian is retarded, and wheezy doesn't ship anything from this decade.
# Fukkit, build from source
# build_py_from_sauce_3_5
build_py_from_sauce_3_4
}
setup_postgres()
{
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client
sudo apt-get install -y postgresql-common
sudo apt-get install -y libpq-dev
sudo apt-get install -y postgresql-9.6
sudo apt-get install -y postgresql-server-dev-9.6
sudo apt-get install -y postgresql-contrib
echo Setting up Database
echo 'local test_db all md5' | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf
service postgresql reload
sudo -u postgres psql -c 'CREATE DATABASE test_db;'
sudo -u postgres psql -c "CREATE USER test_user WITH PASSWORD '2YwzyARHG8agtRdE';"
sudo -u postgres psql -c 'GRANT ALL PRIVILEGES ON DATABASE test_db TO test_user;'
}
setup_python()
{
echo Installing required python libraries
# Install pip (You cannot use the ubuntu repos for this, because they will also install python3.2)
wget https://bootstrap.pypa.io/get-pip.py -nv
sudo python3.5 get-pip.py
rm get-pip.py
# And numpy itself
sudo pip3 install numpy
sudo pip3 install scipy
# Install the libraries we actually need
sudo pip3 install rarfile python-magic cython psycopg2 Colorama
sudo pip3 install python-sql rpyc server_reloader
sudo pip3 install Coverage Bitstring nose
sudo pip3 install pytz apscheduler
sudo pip3 install git+https://github.com/fake-name/UniversalArchiveInterface.git
# So pillow keeps changing the behaviour of image.resize. Arrrgh.
sudo pip3 install pillow=='5.1.0'
}
run_tests()
{
echo Doing setup for user: $1
sudo -u $1 -H bash <<EOF
cd ~/;
git clone https://github.com/fake-name/IntraArchiveDeduplicator.git;
cd IntraArchiveDeduplicator;
chmod +x runTests.sh;
touch settings.py;
./runTests.sh;
EOF
}
platform_str=$(cat /etc/*-release);
if echo $platform_str | grep -i "ubuntu";
then
echo "Doing ubuntu setup"
setup_ubuntu
setup_postgres
setup_python
if [[ `lsb_release -rs` == "14.04" ]]
then
username="vagrant"
elif [[ `lsb_release -rs` == "16.04" ]]
then
username="ubuntu"
else
echo Unknown platform: $(lsb_release -rs)
exit 1
fi
run_tests "$username"
elif echo $platform_str | grep -i "debian";
then
echo "Doing debian setup"
setup_debian
setup_postgres
setup_python
run_tests vagrant
else
echo "Unknown platform";
fi