提交 c724c0a2 编写于 作者: J Joerg Jaspert

Merge branch 'unify-setup' into 'master'

Unify the setting up script for integration tests and for the README

See merge request ftp-team/dak!26
......@@ -20,39 +20,24 @@ if [[ ! -v DAK_INTEGRATION_TEST || ! -v DAK_ROOT ]]; then
exit 1
fi
dak-setup() {
test-setup() {
local setupdir="${DAK_ROOT}/setup"
export DAKBASE=$(mktemp -d)
export DAKHOST=dak-master
(cd ${setupdir}; ./init_db)
if [[ ${PGUSER:-} != dak ]]; then
psql -c "GRANT dak TO \"${PGUSER}\""
fi
psql -f ${setupdir}/current_schema.sql -d projectb >/dev/null
unset PGDATABASE
(cd ${setupdir}; ./init_core)
mkdir ${DAKBASE}/etc ${DAKBASE}/bin ${DAKBASE}/keyrings ${DAKBASE}/tmp
ln -s ${DAK_ROOT}/templates ${DAKBASE}/
export DAK_CONFIG="${DAKBASE}/etc/dak.conf"
(cd ${setupdir}; ./init_minimal_conf) > ${DAK_CONFIG}
echo 'DB::Role "dak";' >> ${DAK_CONFIG}
${setupdir}/dak-setup.sh
export PATH="${DAKBASE}/bin:${PATH}"
ln -s ${DAK_ROOT}/dak/dak.py ${DAKBASE}/bin/dak
dak update-db --yes
dak init-dirs
export DAK_CONFIG="${DAKBASE}/etc/dak.conf"
}
dak-cleanup() {
test-cleanup() {
if [[ -v DAKBASE ]]; then
rm -rf -- "${DAKBASE}"
fi
}
trap dak-cleanup EXIT
dak-setup
trap test-cleanup EXIT
test-setup
......@@ -2,14 +2,14 @@ Initialising a dak database schema
==================================
The following packages are needed for the database:
* postgresql-9.4 postgresql-client-9.4 postgresql-9.4-debversion
* postgresql-9.6 postgresql-client-9.6 postgresql-9.6-debversion
and the following packages for dak itself:
* python-psycopg2 python-sqlalchemy python-apt gnupg dpkg-dev lintian
binutils-multiarch python-yaml less python-ldap python-pyrss2gen python-rrdtool
symlinks python-debian python-debianbts
(the schema assumes at least postgresql 9.1; ftpmaster in Debian currently uses
the postgresql 9.4 version from Debian 8)
the postgresql 9.6 version from Debian 9)
The following roles are assumed to exist:
* dak: database superuser: needs to be an actual user
......@@ -23,47 +23,26 @@ Set up the dak user:
# sudo addgroup ftpmaster
# sudo adduser dak --disabled-login --ingroup ftpmaster --shell /bin/bash
Create postgres roles and database:
# sudo -u postgres ./init_db
Set up the dak directory:
# sudo mkdir /etc/dak
# sudo mkdir /srv/dak
# sudo chown dak:ftpmaster /srv/dak
# sudo chmod 2775 /srv/dak
Create a symlink to /srv/dak/dak.conf in /etc/dak
Create a symlink to /srv/dak/etc/dak.conf in /etc/dak
(we'll create the config file in a bit)
# sudo ln -s /srv/dak/dak.conf /etc/dak/dak.conf
Become the dak user:
# sudo -u dak -s -H
Import the schema. We redirect STDOUT to /dev/null as otherwise it's
impossible to see if something fails.
# psql -1 -f current_schema.sql -d projectb >/dev/null
Set up some core data in projectb to get started (read the init_vars file if
you wish to customise various aspects):
# ./init_core
# sudo ln -s /srv/dak/etc/dak.conf /etc/dak/dak.conf
Create a minimal dak.conf
# ./init_minimal_conf > /srv/dak/dak.conf
This script does the rest of the work. It uses the generic variables set in
init_vars, which can be customized if needed.
# setup/dak-setup.sh
Set up a symlink somewhere
# mkdir ~dak/bin
# ln -s /path/to/dak.py ~dak/bin/dak
At this point, you should be able to test that the database schema is
up-to-date
# dak update-db
Run dak init-dirs to set up the initial /srv/dak tree
# dak init-dirs
The above script symlinks the dak.py script to /srv/dak/bin/dak, you should also
update your PATH variable to be able to execute dak:
# export PATH="/srv/dak/bin:${PATH}"
Copy the email templates into the /srv/dak tree.
WARNING: Please check these templates over and customise as necessary
# cp templates/* /srv/dak/templates/
WARNING: Please check the templates in /srv/dak/templates over and customise
as necessary
Set up a private signing key: don't set a passphrase as dak will not
pass one through to gpg. Guard this key carefully!
......
#!/bin/bash
# -*- mode: sh -*-
#
# © 2017-2018 Ansgar Burchardt <ansgar@debian.org>
# 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/>.
dak-setup() {
# Get the parent directory of the current script
local DAK_ROOT="$(cd $(dirname "$0")/..; pwd)"
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 -u postgres"
SYS_CMD="sudo"
USER_CMD="sudo -u dak -s -H"
else
PG_CMD=""
SYS_CMD=""
USER_CMD=""
fi
# Get default values from init_vars.
# This sets the DAKBASE variable in case it didn't have a value.
. ${setupdir}/init_vars
# 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 projectb >/dev/null
unset PGDATABASE
# Set up some core data in projectb 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
ln -s ${DAK_ROOT}/dak/dak.py ${DAKBASE}/bin/dak
# Update the database schema
$USER_CMD ${DAK_ROOT}/dak/dak.py update-db --yes
# Run dak init-dirs to set up the initial /srv/dak tree
$USER_CMD ${DAK_ROOT}/dak/dak.py init-dirs
}
dak-setup
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册