#!/bin/bash # Copyright (C) 2024 Pädagogisches Landesinstitut Rheinland-Pfalz # Copyright (C) 2024 Daniel Teichmann # # 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. # postinst script for debian-edu-router-fai # # see: dh_installdeb(1) set -e # DEBCONF IS NOT AVAILABLE, PLEASE AMEND TO Pre-Depends BEFORE ENABLING. #. /usr/share/debconf/confmodule || exit 255 if [ -e /etc/debian-edu/router.conf ]; then source /etc/debian-edu/router.conf fi PRODUCTNAME="${PRODUCTNAME:-"Debian Edu Router"}" PRODUCTNAME_FAI="${PRODUCTNAME_FAI:-"${PRODUCTNAME} FAI"}" PRODUCTVERSION=$(dpkg-query --show --showformat='${Version}' "${DPKG_MAINTSCRIPT_PACKAGE}" 2>/dev/null || echo "UNKNOWN") # db_title "${PRODUCTNAME_FAI}" common_file="/usr/share/debian-edu-router/debian-edu-router.common" # Load common functions, variables and stuff. if [ -s "$common_file" ]; then source "$common_file" else echo "Could not load common file at "$common_file"." exit 0; fi # db_version 2.0 # db_capb backup escape # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package # Load dialog answers # db_get debian-edu-router-fai... || true # question="${RET}" function center() { local total_width="$1" local str="$2" local str_length=${#str} local padding=$(( (total_width - str_length) / 2 )) local left_padding=$padding local right_padding=$(( total_width - str_length - left_padding )) printf "%${left_padding}s%s%${right_padding}s" "" "$str" "" } function create_files_from_templates() { product_name_and_version="${PRODUCTNAME_FAI} ${PRODUCTVERSION}" # Pad $product_name_and_version, with spaces left and right, to make it center aligned. product_name_and_version="$(center 54 "$product_name_and_version")" fai_templates_dir="/usr/share/debian-edu-router/templates/debian-edu-router-fai.TEMPLATE/" # NOTE: .temp, not .in! .in files are also used by FAI. for conf_tpl in $(ls ${fai_templates_dir}/*.temp); do conf="/etc/debian-edu/fai/debian-edu-router-fai.TEMPLATE/$(basename ${conf_tpl/.temp/})" cp "${conf_tpl}" "${conf}" sed -i "${conf}" -e "s|@PRODUCT_NAME_AND_VERSION@|${product_name_and_version}|" \ ${NULL} done } function main() { create_files_from_templates debug_log "Configuration of '$PRODUCTNAME' FAI finished." } case "$1" in configure) main ;; abort-upgrade) notice_log "Upgrade of debian-edu-router-fai package was aborted." ;; *) error_log "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. exit 0