diff options
| author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2023-09-04 14:28:50 +0200 |
|---|---|---|
| committer | Mike Gabriel <sunweaver@debian.org> | 2023-09-07 18:45:35 +0000 |
| commit | c1f2924f5d350365b2cc5afc17da4130761ac890 (patch) | |
| tree | b2fd0ff108544df4f346059308deaeb55fce0946 | |
| parent | 0b635dd527763704c45cc319790c3f69234d1669 (diff) | |
| download | debian-edu-fai+itzks-c1f2924f5d350365b2cc5afc17da4130761ac890.tar.gz debian-edu-fai+itzks-c1f2924f5d350365b2cc5afc17da4130761ac890.tar.bz2 debian-edu-fai+itzks-c1f2924f5d350365b2cc5afc17da4130761ac890.zip | |
bin/debian-edu-faiinstall: Manage config space with ucf
Add bin/debian-edu-fai_updateconfigspace.
| -rw-r--r-- | bin/debian-edu-fai_updateconfigspace | 92 | ||||
| -rwxr-xr-x | bin/debian-edu-faiinstall | 22 | ||||
| -rw-r--r-- | debian/dirs | 2 | ||||
| -rw-r--r-- | debian/install | 1 | ||||
| -rw-r--r-- | fai/config/FAI-configspace_obsolete-files.txt | 0 |
5 files changed, 105 insertions, 12 deletions
diff --git a/bin/debian-edu-fai_updateconfigspace b/bin/debian-edu-fai_updateconfigspace new file mode 100644 index 0000000..6b1632b --- /dev/null +++ b/bin/debian-edu-fai_updateconfigspace @@ -0,0 +1,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 [ -d "${FAI_CONFIGDIR_REAL}/.git" ]; 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 diff --git a/bin/debian-edu-faiinstall b/bin/debian-edu-faiinstall index 74a8ad7..7d51a0e 100755 --- a/bin/debian-edu-faiinstall +++ b/bin/debian-edu-faiinstall @@ -195,18 +195,16 @@ for codename in ${codenames}; do FAI_CONFIGDIR_REAL="$(readlink ${FAI_CONFIGDIR})" fi - # Copy FAI config space into /srv/fai/config if not already present - if [ ! -d "${FAI_CONFIGDIR_REAL}" ]; then - # Ensure parent directory exists before copying config space - fai_configdir_parent="$(dirname "${FAI_CONFIGDIR_REAL}")" - mkdir -p "${fai_configdir_parent}" - if [ -d /usr/share/debian-edu-fai/fai/config ]; then - cp -a /usr/share/debian-edu-fai/fai/config "${fai_configdir_parent}" - else - echo "ERROR: Package debian-edu-fai is not installed, please install it first" - exit 1 - fi - fi + set +x + + echo + echo "###" + echo "### Installing/updating FAI config space (this takes some time)" + echo "### (codename: ${codename}, architecture: ${arch})" + echo "###" + debian-edu-fai_updateconfigspace "${FAI_CONFIGDIR_REAL}" + + set -x # Update variables to be customized in FAI config space diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..8472e77 --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +/var/lib/debian-edu-fai/ +/var/lib/debian-edu-fai/ucf/ diff --git a/debian/install b/debian/install index 727d878..5c39b88 100644 --- a/debian/install +++ b/debian/install @@ -3,3 +3,4 @@ conf/debian-edu/fai/ etc/debian-edu/ conf/exports.d/debian-edu-fai.exports usr/share/debian-edu-fai/exports.d/ fai/config usr/share/debian-edu-fai/fai/ bin/debian-edu-faiinstall usr/sbin/ +bin/debian-edu-fai_updateconfigspace usr/sbin/ diff --git a/fai/config/FAI-configspace_obsolete-files.txt b/fai/config/FAI-configspace_obsolete-files.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/fai/config/FAI-configspace_obsolete-files.txt |
