-
Notifications
You must be signed in to change notification settings - Fork 13
/
dak-setup.sh
executable file
·102 lines (87 loc) · 3.27 KB
/
dak-setup.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
#!/bin/bash
# -*- mode: sh -*-
#
# © 2017-2018 Ansgar Burchardt <[email protected]>
# License: GPL-2+
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -e
set -u
set -o pipefail
dak-setup() {
# Get the parent directory of the current script
if [[ ! -v DAK_ROOT ]]; then
local DAK_ROOT="$(cd $(dirname "$0")/..; pwd)"
fi
local setupdir="${DAK_ROOT}/setup"
# This script can be used both for the integration tests and for actual
# creation of a system dak. This is governed by the DAK_INTEGRATION_TEST var.
if [[ ! -v DAK_INTEGRATION_TEST ]]; then
PG_CMD="sudo -E -u postgres"
SYS_CMD="sudo -E"
USER_CMD="sudo -E -u dak -s -H"
PYTHON_COVERAGE=
else
PG_CMD=""
SYS_CMD=""
USER_CMD=""
if [ "${RUN_COVERAGE:-n}" = "y" ]; then
PYTHON_COVERAGE="python3-coverage run --rcfile ${DAK_ROOT}/.coveragerc --parallel-mode"
else
PYTHON_COVERAGE=
fi
fi
# Get default values from init_vars.
# This sets the DAKBASE variable in case it didn't have a value.
. ${setupdir}/init_vars
# Ensure that DAKBASE exists
$SYS_CMD mkdir -p ${DAKBASE}
# Ensure the right permissions when not running tests
if [[ ! -v DAK_INTEGRATION_TEST ]]; then
$SYS_CMD chown dak:ftpmaster ${DAKBASE}
$SYS_CMD chmod 2775 ${DAKBASE}
fi
# When setting up the system DB, this needs to be run as postgres
(cd ${setupdir}; $PG_CMD ./init_db)
if [[ ${PGUSER:-} != dak && -v PGUSER ]]; then
$PG_CMD psql -c "GRANT dak TO \"${PGUSER}\""
fi
$USER_CMD mkdir -p ${DAKBASE}/etc ${DAKBASE}/bin ${DAKBASE}/keyrings ${DAKBASE}/tmp
# Copy/Link the email templates into the /srv/dak tree.
if [[ ! -v DAK_INTEGRATION_TEST ]]; then
$USER_CMD cp -r ${DAK_ROOT}/templates ${DAKBASE}/
else
$USER_CMD ln -s ${DAK_ROOT}/templates ${DAKBASE}/
fi
# Import the schema. We redirect STDOUT to /dev/null as otherwise it's
# impossible to see if something fails.
$USER_CMD psql -f ${setupdir}/current_schema.sql -d ${PGDATABASE} >/dev/null
# Set up some core data in PGDATABASE to get started
(cd ${setupdir}; $USER_CMD ./init_core)
# Create a minimal dak.conf
export DAK_CONFIG="${DAKBASE}/etc/dak.conf"
(cd ${setupdir}; ./init_minimal_conf | $USER_CMD tee ${DAK_CONFIG} >/dev/null)
$USER_CMD echo 'DB::Role "dak";' | tee -a ${DAK_CONFIG} >/dev/null
if [[ ! -v DAK_INTEGRATION_TEST ]]; then
ln -s ${DAK_ROOT}/dak/dak.py ${DAKBASE}/bin/dak
else
# wrapper to collect coverage information
ln -s ${DAK_ROOT}/integration-tests/dak-coverage.sh ${DAKBASE}/bin/dak
fi
# Update the database schema
$USER_CMD ${DAKBASE}/bin/dak update-db --yes
# Run dak init-dirs to set up the initial /srv/dak tree
$USER_CMD ${DAKBASE}/bin/dak init-dirs
}
dak-setup