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
|
#!/bin/sh
# Copyright (C) 2010-2023 Pädagogisches Landesinstitut Rheinland-Pfalz
# Copyright (C) 2022-2023 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
# 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, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
# Sync FAI config space files from DATADIR/fai/config/ to
# /srv/fai/config. For this, the 'ucf' tool is used, three-way
# patching is supported for this.
set -e
LC_ALL=C
export LC_ALL
if [ -z "$1" ]; then
echo "usage: $(basename $0) <FAI_CONFIGDIR>"
exit 1
fi
# first parameter is the configspace's target dir
FAI_CONFIGDIR="$1"
FAI_CONFIGDIR_REAL="${FAI_CONFIGDIR}"
# if FAI_CONFIGDIR is a symlink, we need to find the real location...
if [ -h ${FAI_CONFIGDIR} ]; then
FAI_CONFIGDIR_REAL="$(readlink ${FAI_CONFIGDIR})"
fi
# Copy FAI config space into /srv/fai/config if not already present
if [ "${FAI_CONFIGDIR_REAL}" = "/usr/share/debian-edu-fai/fai/config" ]; then
echo "ERROR: FAI_CONFIGDIR points to '${FAI_CONFIGDIR_REAL}'."
echo "ERROR: Such a setup is not supported..."
exit 1
elif command -v git 1>/dev/null && [ "$(cd "${FAI_CONFIGDIR_REAL}"; git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
# FAI config space is managed by Git, don't do anything then...
:
else
# create config space's base directory if it does not yet exist
if [ ! -d "${FAI_CONFIGDIR_REAL}" ]; then
mkdir -p "${FAI_CONFIGDIR_REAL}"
fi
# remove obsolete files used in previous FAI configspace versions
cd "${FAI_CONFIGDIR_REAL}"
cat /usr/share/debian-edu-fai/fai/config/_obsolete-files.d/*.removed | while read obsolete_configspace_file; do
rm -fv "${obsolete_configspace_file}"
# purge file's hash from ucf hash list
ucf -p "${FAI_CONFIGDIR_REAL}/${obsolete_configspace_file}"
# try to remove non-used / empty directories
if [ -d "$(dirname ${obsolete_configspace_file})" ]; then
rmdir --parents --ignore-fail-on-non-empty "$(dirname ${obsolete_configspace_file})"
fi
done
cd - 1>/dev/null
# managed FAI config space with 'ucf'...
cd "/usr/share/debian-edu-fai/fai/config"
find . -type f | grep -v "_obsolete-files.d/" | while read new_configspace_file; do
# handle files that shall become a directory gracefully
target_dir="${FAI_CONFIGDIR_REAL}/$(dirname "${new_configspace_file}")"
if [ -e "${target_dir}" ] && [ ! -d "${target_dir}" ]; then
mv -v "${target_dir}" "${target_dir}.moved-out-of-the-way"
fi
mkdir -p "${FAI_CONFIGDIR_REAL}/$(dirname "${new_configspace_file}")"
if [ -e "${target_dir}.moved-out-of-the-way" ]; then
mv -v "${target_dir}.moved-out-of-the-way" "${target_dir}/OBSOLETE"
fi
# install/update configspace file via ucf
ucf --state-dir "/var/lib/debian-edu-fai/ucf/" --three-way "$new_configspace_file" "${FAI_CONFIGDIR_REAL}/${new_configspace_file}"
done
cd - 1>/dev/null
# clean-up ucf backup files... (they confuse FAI)
cd "${FAI_CONFIGDIR_REAL}"
find . -name "*.ucf-*" -delete
cd - 1>/dev/null
fi
|