-
Notifications
You must be signed in to change notification settings - Fork 434
/
common.sh
206 lines (169 loc) · 5.51 KB
/
common.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
#!/bin/bash
function allow_vendor_change() {
echo 'solver.allowVendorChange = true' >> /etc/zypp/zypp.conf
}
function add_common_repos() {
zypper -q rr systemsmanagement-chef
zypper -q rr systemsmanagement-puppet
zypper -q ar -f http://download.opensuse.org/repositories/OBS:/Server:/Unstable/openSUSE_42.1/OBS:Server:Unstable.repo
zypper -q ar -f http://download.opensuse.org/repositories/openSUSE:/Tools/openSUSE_42.1/openSUSE:Tools.repo
zypper -q --gpg-auto-import-keys refresh
zypper -q -n dup -l --replacefiles
}
function install_common_packages() {
echo -e "\ninstalling required software packages...\n"
zypper -q -n install --replacefiles\
update-alternatives make gcc gcc-c++ patch cyrus-sasl-devel openldap2-devel \
libmysqld-devel libxml2-devel zlib-devel libxslt-devel nodejs mariadb memcached \
sphinx phantomjs \
screen \
ruby2.4-devel \
ruby2.4-rubygem-bundler \
ruby2.4-rubygem-mysql2 \
ruby2.4-rubygem-nokogiri \
ruby2.4-rubygem-multi_json \
ruby2.4-rubygem-ruby-ldap \
ruby2.4-rubygem-xmlhash \
ruby2.4-rubygem-thinking-sphinx\
perl-GD \
perl-XML-Parser \
perl-Devel-Cover \
obs-server \
perl-BSSolv \
perl-Socket-MsgHdr \
perl-JSON-XS \
curl \
vim-data \
psmisc \
obs-service-download_src_package obs-service-download_files obs-service-download_url \
obs-service-format_spec_file obs-service-kiwi_import \
osc
# This is a workaround for a very strange behavior
# After installing one of the follwing packages - obs-server, curl or vim-data
# grub installation is broken, if we don`t re-install grub, the VM will hang
# on reboot
grub2-install /dev/sda
}
function setup_ruby() {
echo -e "\nsetup ruby binaries...\n"
[ -f /usr/bin/ruby ] ||ln -s /usr/bin/ruby.ruby2.4 /usr/bin/ruby
for bin in rake rdoc ri; do
/usr/sbin/update-alternatives --set $bin /usr/bin/$bin.ruby.ruby2.4
done
}
function setup_ruby_gem() {
echo -e "\ndisabling versioned gem binary names...\n"
echo 'install: --no-format-executable' >> /etc/gemrc
}
function install_bundler_package() {
echo -e "\ninstalling bundler...\n"
gem install bundler
}
function install_bundle() {
echo -e "\ninstalling your bundle...\n"
su - vagrant -c "cd /vagrant/src/api/; bundle install --quiet"
}
function setup_mariadb() {
echo -e "\nsetting up mariadb...\n"
systemctl restart mysql
systemctl enable mysql
check_for_databases || mysqladmin -u root password 'opensuse'
}
function setup_memcached() {
echo -e "\nsetting up memcached...\n"
systemctl restart memcached
systemctl enable memcached
}
function configure_app() {
copy_example_file options.yml || return 1
}
function configure_database() {
copy_example_file database.yml || return 1
check_for_databases && return 1
rake -f /vagrant/src/api/Rakefile db:create
rake -f /vagrant/src/api/Rakefile db:setup
}
function setup_data_dir() {
echo "Generating data dir and mounting them So hard links can be used..."
# Put the backend data dir outside the shared folder so it can use hardlinks
# which isn't possible with VirtualBox shared folders...
_prepare_bound_directory tmp
_prepare_bound_directory log
mount -a
}
function print_final_information() {
echo -e "\nProvisioning of your OBS API rails app done!"
echo -e "To start your development OBS backend run: vagrant exec contrib/start_development_backend\n"
echo -e "To start your development OBS frontend run: vagrant exec rails server\n"
echo -e "\nHappy hacking!\n"
}
function chown_vagrant_owned_dirs() {
BASE_DIR=/vagrant/src/api/
# create log files to ensure they are owned by vagrant
for dir in log tmp
do
chown -R vagrant:users $BASE_DIR/$dir
done
}
function prepare_apache2 {
echo -e "\nPreparing apache setup\n"
PACKAGES="apache2 apache2-mod_xforward rubygem-passenger-apache2 memcached"
PKG2INST=""
for pkg in $PACKAGES;do
rpm -q $pkg >/dev/null || PKG2INST="$PKG2INST $pkg"
done
if [[ -n $PKG2INST ]];then
zypper --non-interactive install $PKG2INST >/dev/null
fi
MODULES="passenger rewrite proxy proxy_http xforward headers socache_shmcb"
for mod in $MODULES;do
a2enmod -q $mod || a2enmod $mod
done
FLAGS=SSL
for flag in $FLAGS;do
a2enflag $flag >/dev/null
done
systemctl enable apache2.service
}
##### INTERNAL FUNCTIONS #####
function copy_example_file {
if [ -z $1 ]; then
return 1
fi
if [ ! -f /vagrant/src/api/config/$1 ] && [ -f /vagrant/src/api/config/$1.example ]; then
echo "Setting up config/$1 from config/$1.exmaple"
cp /vagrant/src/api/config/$1.example /vagrant/src/api/config/$1
else
echo "WARNING: You already have the config file $1, make sure it works with vagrant"
return 1
fi
}
function check_for_databases {
echo "show databases" | mysql -u root --password=opensuse|grep -q api_ && return 0 || return 1
}
function _prepare_bound_directory() {
DIRNAMEEXT=$1
TMP_DIR=/tmp/vagrant_$1
MOUNT_DIR=/vagrant/src/api/$1
for dir in $MOUNT_DIR $TMP_DIR
do
if [ ! -d $dir ];then
echo " - Creating directory $dir"
mkdir -p $dir
fi
chown vagrant:users $dir
done
# create log files to ensure they are owned by vagrant
if [ "$1" == "log" ];then
for log in backend_access.log development.log test.log
do
touch $TMP_DIR/$log
done
fi
chown vagrant:users -R $TMP_DIR
TMP_IN_FSTAB=$(grep "$MOUNT_DIR" /etc/fstab)
if [ -z "$TMP_IN_FSTAB" ];then
echo " - Adding $TMP_DIR to fstab"
echo -e "$TMP_DIR $MOUNT_DIR none bind 0 0" >> /etc/fstab
fi
}