forked from openSUSE/open-build-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.setup-appliance.sh
executable file
·710 lines (611 loc) · 23.6 KB
/
functions.setup-appliance.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#!/bin/bash
###############################################################################
#
# DEFINITION OF FUNCTIIONS
#
###############################################################################
function execute_silently {
$@ > /dev/null 2>&1
return $?
}
###############################################################################
function logline {
[[ $BOOTSTRAP_TEST_MODE == 1 ]] && return
echo $@
}
###############################################################################
function check_unit {
srv=$1
service_critical=$2
[[ $SETUP_ONLY == 1 ]] && return
echo "Checking unit $srv ..."
IS_ENABLED=`systemctl is-enabled $srv`
if [ "$IS_ENABLED" != "enabled" ];then
logline "Enabling $srv"
execute_silently systemctl enable --now $srv
fi
if [[ $? -gt 0 ]];then
logline "WARNING: Enabling $srv daemon failed."
fi
STATUS=`systemctl is-active $srv 2>/dev/null`
if [[ "$STATUS" == "inactive" ]];then
echo "$srv daemon not started. Trying to start"
execute_silently systemctl start $srv
if [[ $? -gt 0 ]];then
echo -n "Starting $srv daemon failed."
if [[ $service_critical == 1 ]];then
echo " Exiting ..."
exit 1
fi
fi
fi
}
###############################################################################
function check_server_cert {
# Create directory if not exists
# Usefull on testing systems where no obs-server rpm is installed
[ -d $backenddir/certs/ ] || mkdir -p $backenddir/certs/
if [[ ! -e $backenddir/certs/server.${FQHOSTNAME}.created || ! -e $backenddir/certs/server.${FQHOSTNAME}.crt ]]; then
# setup ssl certificates (NOT protected with a passphrase)
logline "Creating a default SSL certificate for the server"
logline "Please replace it with your version in $backenddir/certs directory..."
DETECTED_CERT_CHANGE=1
# hostname specific certs - survive intermediate hostname changes
if [ ! -e $backenddir/certs/server.${FQHOSTNAME}.crt ] ; then
# This is just a dummy SSL certificate, but it has a valid hostname.
# Admin can replace it with his version.
create_selfsigned_certificate
echo "$OPENSSL_CONFIG" | openssl req -new -nodes -config /dev/stdin \
-x509 -days 365 -batch \
-key $backenddir/certs/server.key \
-out $backenddir/certs/server.${FQHOSTNAME}.crt
if [[ $? == 0 ]];then
echo "Do not remove this file or new SSL CAs will get created." > $backenddir/certs/server.${FQHOSTNAME}.created
fi
else
echo "ERROR: SSL CAs in $backenddir/certs exists, but were not created for your hostname"
exit 1
fi
fi
}
###############################################################################
function create_selfsigned_certificate() {
cert_outdir=$backenddir/certs
COUNTER=0
DNS_NAMES=""
for name in $PROPOSED_DNS_NAMES;do
DNS_NAMES="$DNS_NAMES
DNS.$COUNTER = $name"
COUNTER=$(($COUNTER + 1 ))
done
logline "Creating crt/key in $cert_outdir"
OPENSSL_CONFIG="prompt = no
distinguished_name = req_distinguished_name
[req_distinguished_name]
countryName = CC
stateOrProvinceName = OBS Autogen State or Province
localityName = OBS Autogen Locality
organizationName = OBS Autogen Organisation
organizationalUnitName = OBS Autogen Organizational Unit
commonName = $FQHOSTNAME
emailAddress = [email protected]
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca
[req_attributes]
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
[ v3_ca ]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer
basicConstraints = CA:true
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = critical,CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
$DNS_NAMES
[ v3_ca ]
basicConstraints = CA:TRUE
subjectAltName = @alt_names
"
}
###############################################################################
function get_hostname {
if [[ $1 && $BOOTSTRAP_TEST_MODE == 1 ]];then
FQHOSTNAME=$1
else
TIMEOUT=30
while [ -z "$FQHOSTNAME" -o "$FQHOSTNAME" = "localhost" ];do
# Try to get the FQHN via hostname
HN=`hostname -f 2>/dev/null`
if [[ $HN =~ ^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$ ]];then
FQHOSTNAME=$HN
fi
TIMEOUT=$(($TIMEOUT-1))
[ "$TIMEOUT" -le 0 ] && break
echo "Waiting for FQHOSTNAME ($TIMEOUT)"
sleep 1
done
if [ -z "$FQHOSTNAME" -o "$FQHOSTNAME" = "localhost" ] && [ -x "$(command -v hostnamectl)" ];then
FQHOSTNAME=`hostnamectl --static 2>/dev/null`
fi
if [ -z "$FQHOSTNAME" -o "$FQHOSTNAME" = "localhost" -a -s /etc/hostname ];then
FQHOSTNAME=`cat /etc/hostname`
fi
fi
if type -p ec2-public-hostname; then
FQHOSTNAME=`ec2-public-hostname`
fi
if [ "$FQHOSTNAME" = "" ]; then
ask "Please enter the full qualified hostname!"
FQHOSTNAME=$rv
fi
# fallback in non-interative mode
if [ "$FQHOSTNAME" = "" ]; then
# Prefer interface with default route if exists
DEFAULT_ROUTE_INTERFACE=`LANG=C ip route show|perl -e '$_=<>; ( m/^default via.*dev\s+([\w]+)\s.*/ ) && print $1'`
# Fallback to IP of the VM/host
FQHOSTNAME=`LANG=C ip addr show $DEFAULT_ROUTE_INTERFACE| perl -lne '( m#^\s+inet\s+([0-9\.]+)(/\d+)?\s+.*# ) && print $1' | grep -v ^127. | head -n 1`
if [ "$?" != "0" -o "$FQHOSTNAME" = "" ]; then
echo " Can't determine hostname or IP - Network setup failed!"
echo " Check if networking is up and dhcp is working!"
echo " Using 'localhost' as FQHOSTNAME."
FQHOSTNAME="localhost"
fi
USEIP=$FQHOSTNAME
fi
if [[ -z $USEIP ]];then
DOMAINNAME=""
if [[ $FQHOSTNAME =~ '.' ]];then
DOMAINNAME=$(echo $FQHOSTNAME | perl -pe 's/^[\w\-_]*\.(.*)/$1/')
SHORTHOSTNAME=$(echo $FQHOSTNAME | perl -pe 's/^([\w\-_]*)\..*/$1/')
else
SHORTHOSTNAME=$FQHOSTNAME
fi
fi
}
###############################################################################
function generate_proposed_dnsnames {
if [[ ! $FQHOSTNAME ]];then
get_hostname
fi
if [[ $FQHOSTNAME != 'localhost' ]];then
LOCAL_HOST="localhost"
fi
if [[ $FQHOSTNAME == $SHORTHOSTNAME ]];then
DNSNAMES="$SHORTHOSTNAME $LOCAL_HOST"
else
DNSNAMES="$SHORTHOSTNAME $FQHOSTNAME $LOCAL_HOST"
fi
ask "Proposed DNS names: " "$DNSNAMES"
PROPOSED_DNS_NAMES=$rv
}
###############################################################################
function adjust_api_config {
echo "Adjust configuration for this hostname"
# use local host to avoid SSL verification between webui and api
api_options_yml=$apidir/config/options.yml
sed -i 's,^frontend_host: .*,frontend_host: "localhost",' $api_options_yml
sed -i 's,^frontend_port: .*,frontend_port: 443,' $api_options_yml
sed -i 's,^frontend_protocol: .*,frontend_protocol: "'"https"'",' $api_options_yml
}
###############################################################################
function adapt_worker_jobs {
#changed IP means also that leftover jobs are invalid - cope with that
echo "Adapting present worker jobs"
sed -i "s,server=\"http://[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*:5352,server=\"http://$FQHOSTNAME:5352,g" \
$backenddir/jobs/*/* 2> /dev/null
sed -i "s,server=\"http://[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*:5252,server=\"http://$FQHOSTNAME:5252,g" \
$backenddir/jobs/*/* 2> /dev/null
#remove old workers status and idling/building markers
rm -f $backenddir/jobs/*/*status 2> /dev/null
rm -f $backenddir/workers/*/* 2> /dev/null
# create repo directory or apache fails when nothing got published
mkdir -p $backenddir/repos
chown obsrun:obsrun $backenddir/repos
}
###############################################################################
function prepare_database_setup {
cd $apidir
RAILS_ENV=production bin/rails db:migrate:status > /dev/null 2>&1
if [[ $? > 0 ]];then
echo "Initialize MySQL databases (first time only)"
DATADIR_FILE=$(grep datadir -rl /etc/my.cnf*)
echo " - reconfiguring datadir in $DATADIR_FILE"
sed -i -E '0,/(#\s*)?datadir/ s!#\s*datadir\s*=\s*/var/lib/mysql$!datadir = /srv/obs/MySQL!' $DATADIR_FILE
echo " - installing to new datadir"
mysql_install_db
echo " - changing ownership for new datadir"
chown mysql:mysql -R /srv/obs/MySQL
MYSQL_LOG=$(grep log-error /etc/my.cnf.d/*.cnf|perl -p -e 's/.*:log-error=(.*)/$1/')
if [ -n "$MYSQL_LOG" ];then
echo " - prepare log file $MYSQL_LOG"
LOG_DIR=`dirname $MYSQL_LOG`
if [ ! -d $LOG_DIR ];then
mkdir -p $LOG_DIR
chown mysql:mysql $LOG_DIR
fi
touch $MYSQL_LOG
chown mysql:mysql $MYSQL_LOG
fi
echo " - restarting mysql"
systemctl restart $MYSQL_SERVICE
echo " - setting new password for user root in mysql"
mysqladmin -u $MYSQL_USER password $MYSQL_PASS
if [[ $? > 0 ]];then
echo "ERROR: Your mysql setup doesn't fit your rails setup"
echo "Please check your database settings for mysql and rails"
exit 1
fi
RUN_INITIAL_SETUP="true"
fi
RAKE_COMMANDS=""
if [ -n "$RUN_INITIAL_SETUP" ]; then
logline "Initialize OBS api database (first time only)"
cd $apidir
RAKE_COMMANDS="db:setup writeconfiguration"
else
logline "Migrate OBS api database"
cd $apidir
RAKE_COMMANDS="db:migrate:with_data"
echo
fi
logline "Setting ownership of '$backenddir' obsrun"
chown obsrun:obsrun $backenddir
logline "Setting up rails environment"
for cmd in $RAKE_COMMANDS
do
logline " - Doing 'rails $cmd'"
RAILS_ENV=production SAFETY_ASSURED=1 bin/rails $cmd >> $apidir/log/db_migrate.log 2>&1
if [[ $? > 0 ]];then
(>&2 echo "Command $cmd FAILED")
exit 1
fi
done
if [ -n "$RUN_INITIAL_SETUP" ]; then
if [[ ! "$SETUP_ONLY" ]];then
`systemctl restart obsscheduler.service`
fi
fi
}
###############################################################################
function add_login_info_to_issue {
cat >> /etc/issue <<EOF
Connect to the web interface via: https://$FQHOSTNAME
Connect to the api interface via: https://$FQHOSTNAME
Browse the build packages via: http://$FQHOSTNAME:82
* "Admin"/"root" user password is "opensuse" by default.
* Connect to the web interface now to finish the OBS setup.
More informations about this appliance are available here:
http://en.opensuse.org/Build_Service/OBS-Appliance
Greetings from the Open Build Service Team
http://www.open-build-service.org
EOF
}
###############################################################################
function network_failure_warning {
echo "OBS appliance could not get setup, no network found" > /srv/www/obs/overview/index.html
cat <<EOF > /etc/issue
*******************************************************************************
** NETWORK SETUP FAILED **
** **
** OBS is not usable. A working DNS resolution for your host is required! **
** You can check this with 'hostname -f'. **
** This often happens in virtualization environments like e.g. VirtualBox. **
** **
** You also could run **
** **
** /usr/lib/obs/server/setup-appliance.sh **
** **
** for interactive configuration **
** **
*******************************************************************************
EOF
}
###############################################################################
function check_server_key {
# reuse signing key even if hostname changed
if [ ! -e $backenddir/certs/server.key ]; then
logline "Creating $backenddir/certs/server.key"
install -d -m 0700 $backenddir/certs
openssl genrsa -out $backenddir/certs/server.key 4096 2>/dev/null
else
logline "Found $backenddir/certs/server.key"
fi
}
###############################################################################
function import_ca_cert {
# apache has to trust the api ssl certificate
if [ ! -e /etc/ssl/certs/server.${FQHOSTNAME}.crt ]; then
cp $backenddir/certs/server.${FQHOSTNAME}.crt \
${TRUST_ANCHORS_DIR}/server.${FQHOSTNAME}.pem
$UPDATE_SSL_TRUST_BIN
fi
}
###############################################################################
function relink_server_cert {
if [[ $DETECTED_CERT_CHANGE == 1 ]];then
CERT_LINK_FILE=$backenddir/certs/server.crt
# check if CERT_LINK_FILE not exists or is symbolic link because we don't
# want to remove real files
if [ ! -e $CERT_LINK_FILE -o -L $CERT_LINK_FILE ];then
# change links for certs according to hostnames
cd $backenddir/certs
rm -f server.crt
ln -sf server.${FQHOSTNAME}.crt server.crt
cd - >/dev/null
fi
fi
}
###############################################################################
function fix_permissions {
cd $apidir
chown -R $HTTPD_USER:$HTTPD_GROUP $apidir/log
}
###############################################################################
function create_issue_file {
echo "Recreating /etc/issue"
# create base version of /etc/issues
cat > /etc/issue <<EOF
Welcome to Open Build Service(OBS) Appliance $OBSVERSION
based on $OS
EOF
# check if signing packages is enabled, otherwise add warning to /etc/issue
if ! grep -q "^our \$sign =" /usr/lib/obs/server/BSConfig.pm ; then
echo "Adding signing hint to /etc/issue"
cat >> /etc/issue <<EOF
WARNING: **** Package signing is disabled, maybe due to lack of hardware number generator ****
EOF
fi
}
###############################################################################
function create_overview_html {
echo "Creating overview.html"
sed -e "s,___API_URL___,https://$FQHOSTNAME,g" \
-e "s,___REPO_URL___,http://$FQHOSTNAME:82,g" \
/srv/www/obs/overview/overview.html.TEMPLATE > /srv/www/obs/overview/index.html
}
###############################################################################
function ask {
logline $1
if [[ $NON_INTERACTIVE == 1 ]];then
rv=$2
logline "Using default value '$rv' in non-interactive mode"
return
fi
echo "Default: $2"
read rv
if [[ ! $rv ]];then
rv=$2
fi
}
###############################################################################
function check_required_backend_services {
[[ $SETUP_ONLY == 1 ]] && return
REQUIRED_SERVICES="obsrepserver obssrcserver obsscheduler obsdispatcher obspublisher"
for srv in $REQUIRED_SERVICES ;do
ENABLED=`systemctl is-enabled $srv`
[[ "$ENABLED" == "enabled" ]] || systemctl enable --now $srv
ACTIVE=`systemctl is-active $srv`
[[ "$ACTIVE" == "active" ]] || systemctl start $srv
done
}
###############################################################################
function check_recommended_backend_services {
[[ $SETUP_ONLY == 1 ]] && return
RECOMMENDED_SERVICES="obsdodup obsdeltastore obssigner $OBS_SIGND obsservicedispatch"
for srv in $RECOMMENDED_SERVICES;do
STATE=$(systemctl is-enabled $srv)
if [ $STATE != "enabled" ];then
ask "Service $srv is not enabled. Would you like to enable it? [Yn]" "y"
case $rv in
y|yes|Y|YES)
logline "Recommended service $srv enabled now!"
systemctl enable --now $srv
;;
esac
else
logline "Recommended service $srv already enabled!"
fi
done
}
###############################################################################
function check_optional_backend_services {
DEFAULT_ANSWER="n"
if [[ $ENABLE_OPTIONAL_SERVICES ]];then
DEFAULT_ANSWER="y"
fi
[[ $SETUP_ONLY == 1 ]] && return
OPTIONAL_SERVICES="obswarden obsapisetup obsstoragesetup obsworker obsservice obssourcepublish"
for srv in $OPTIONAL_SERVICES;do
STATE=$(systemctl is-enabled $srv)
if [ $STATE != "enabled" ];then
ask "Service $srv is not enabled. Would you like to enable it? [yN]" $DEFAULT_ANSWER
case $rv in
y|yes|Y|YES)
systemctl enable --now $srv
;;
esac
else
logline "Optional service $srv already enabled!"
fi
done
}
###############################################################################
function prepare_apache2 {
[[ $SETUP_ONLY == 1 ]] && return
PKG2INST=""
for pkg in $APACHE_ADDITIONAL_PACKAGES;do
rpm -q $pkg >/dev/null || PKG2INST="$PKG2INST $pkg"
done
if [[ -n $PKG2INST ]];then
$INST_PACKAGES_CMD $PKG2INST >/dev/null
fi
if [ "$CONFIGURE_APACHE" == 1 ];then
MODULES="passenger rewrite proxy proxy_http headers socache_shmcb xforward"
for mod in $MODULES;do
a2enmod -q $mod || a2enmod $mod
done
FLAGS=SSL
for flag in $FLAGS;do
a2enflag $flag >/dev/null
done
fi
}
###############################################################################
function prepare_passenger {
perl -p -i -e \
's#^(\s*)PassengerRuby "/usr/bin/ruby"#$1\PassengerRuby "/usr/bin/ruby.ruby3.1"#' \
$MOD_PASSENGER_CONF
}
###############################################################################
function prepare_obssigner {
# Only used if there is a local BSConfig
if [ -e /usr/lib/obs/server/BSConfig.pm ]; then
# signing setup
perl -p -i -e 's,^\s*#\s*our \$gpg_standard_key.*,our \$gpg_standard_key = "/srv/obs/obs-default-gpg.asc";,' /usr/lib/obs/server/BSConfig.pm
perl -p -i -e 's,^\s*#\s*our \$keyfile.*,our \$keyfile = "/srv/obs/obs-default-gpg.asc";,' /usr/lib/obs/server/BSConfig.pm
perl -p -i -e 's,^\s*#\s*our \$sign = .*,our \$sign = "/usr/bin/sign";,' /usr/lib/obs/server/BSConfig.pm
chmod 4755 /usr/bin/sign
# create default gpg key if not existing
if [ ! -e "$backenddir"/obs-default-gpg.asc ] && grep -q "^our \$keyfile.*/obs-default-gpg.asc.;$" /usr/lib/obs/server/BSConfig.pm; then
GPG_KEY_CREATED=1
echo -n Generating OBS default GPG key ....
mkdir -p "$backenddir"/gnupg/phrases
chmod -R 0700 "$backenddir"/gnupg
cat >/tmp/obs-gpg.$$ <<EOF
%echo Generating a default OBS instance key
Key-Type: RSA
Key-Length: 4096
Subkey-Type: ELG-E
Subkey-Length: 4096
Name-Real: private OBS
Name-Comment: key without passphrase
Name-Email: defaultkey@localobs
Expire-Date: 30y
%no-protection
%commit
%echo done
EOF
gpg2 --homedir $backenddir/gnupg --batch --gen-key /tmp/obs-gpg.$$
gpg2 --homedir $backenddir/gnupg --export -a > "$backenddir"/obs-default-gpg.asc
rm /tmp/obs-gpg.$$
# empty file just for accepting the key
touch "$backenddir/gnupg/phrases/defaultkey@localobs"
fi
# to update sign.conf also after an appliance update
if [ -e "$backenddir"/obs-default-gpg.asc ] && ! grep -q "^user" /etc/sign.conf; then
logline "Configuring /etc/sign.conf"
# extend signd config
echo "user: defaultkey@localobs" >> /etc/sign.conf
echo "server: 127.0.0.1" >> /etc/sign.conf
echo "allowuser: obsrun" >> /etc/sign.conf
echo "allow: 127.0.0.1" >> /etc/sign.conf
echo "phrases: $backenddir/gnupg/phrases" >> /etc/sign.conf
echo done
sed -i 's,^# \(our $sign =.*\),\1,' /usr/lib/obs/server/BSConfig.pm
# ensure that $OBS_SIGND gets restarted if already started
systemctl is-active $OBS_SIGND 2>&1 > /dev/null
if [ $? -eq 0 ] ; then
logline "Restarting $OBS_SIGND"
systemctl restart $OBS_SIGND
fi
fi
if [ ! -e "$backenddir"/obs-default-gpg.asc ] ; then
sed -i 's,^\(our $sign =.*\),# \1,' /usr/lib/obs/server/BSConfig.pm
ENABLE_FORCEPROJECTKEYS=0
fi
systemctl is-enabled $OBS_SIGND 2>&1 > /dev/null
if [ $? == 0 ];then
systemctl is-failed $OBS_SIGND 2>&1 > /dev/null
if [ $? == 0 ];then
logline "obssignd failed to start. Restarting!"
systemctl status $OBS_SIGND # for debugging output
systemctl restart $OBS_SIGND
fi
fi
fi
}
###############################################################################
function prepare_os_settings {
. /etc/os-release
for d in $ID_LIKE $ID;do
case $d in
suse|opensuse)
MYSQL_SERVICE=mysql
HTTPD_SERVICE=apache2
HTTPD_USER=wwwrun
HTTPD_GROUP=www
PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/mod_passenger.conf
TRUST_ANCHORS_DIR=/usr/share/pki/trust/anchors
UPDATE_SSL_TRUST_BIN=update-ca-certificates
MOD_PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/mod_passenger.conf
INST_PACKAGES_CMD="zypper --non-interactive install"
APACHE_ADDITIONAL_PACKAGES="$HTTPD_SERVICE apache2-mod_xforward rubygem-passenger-apache2 memcached"
CONFIGURE_APACHE=1
OBS_SIGND=obssignd
SIGND_BIN="/usr/sbin/signd"
;;
fedora)
MYSQL_SERVICE=mariadb
HTTPD_SERVICE=httpd
HTTPD_USER=apache
HTTPD_GROUP=apache
PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/passenger.conf
TRUST_ANCHORS_DIR=/etc/pki/ca-trust/source/anchors
UPDATE_SSL_TRUST_BIN=update-ca-trust
MOD_PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/passenger.conf
INST_PACKAGES_CMD="dnf -y install"
APACHE_ADDITIONAL_PACKAGES="$HTTPD_SERVICE mod_xforward mod_passenger memcached"
CONFIGURE_APACHE=0
OBS_SIGND=signd
SIGND_BIN="/usr/sbin/signd"
;;
esac
done
}
###############################################################################
function enable_forceprojectkeys {
# Only run on initial setup
echo "Starting enable_forceprojectkeys"
if [ -z "$RUN_INITIAL_SETUP" ];then
echo "Not running in intial setup mode. Skipping"
return
fi
# This is done manually and not via api to avoid authentication
# and service dependency (systemd) problems.
cd $apidir
echo " - Setting enforce_project_keys in api_production.configurations to '$ENABLE_FORCEPROJECTKEYS'"
mysql -u $MYSQL_USER -p$MYSQL_PASS -e "update configurations SET enforce_project_keys=$ENABLE_FORCEPROJECTKEYS" api_production || exit 1
echo " - Starting 'rails writeconfiguration'"
RAILS_ENV=production bin/rails writeconfiguration || exit 1
}
###############################################################################
function create_sign_cert {
echo "Starting create_sign_cert"
if [ -f "$backenddir/obs-default-gpg.asc" -a ! -f "$backenddir/obs-default-gpg.cert" ];then
echo "Creating new signer cert"
GNUPGHOME="$backenddir/gnupg" sign --test-sign $SIGND_BIN -C $backenddir/obs-default-gpg.asc > $backenddir/obs-default-gpg.cert 2>&1 || { cat $backenddir/obs-default-gpg.cert ; exit 1; }
else
echo "Skipping new signer cert"
fi
}
###############################################################################
function set_gpg_expiry_date {
export GNUPGHOME="$backenddir/gnupg"
KEYID=`gpg -k --with-colons --no-tty --batch| awk -F: '/^pub:/ { print $5 }'`
EXPIRE=`gpg -k --no-tty $KEYID|grep expires`
if [ -z "$EXPIRE" ];then
echo "Set expire date "
echo -en "expire\n30y\nquit\ny\n" | gpg --no-tty --command-fd 0 --expert --edit-key $KEYID
gpg --export -a $KEYID > $backenddir/obs-default-gpg.asc
fi
EXPIRE=`gpg -k --no-tty $KEYID|grep expires`
[ -z "$EXPIRE" ] && exit 1
}
###############################################################################