File: debian-edu-router-config.preinst

package info (click to toggle)
debian-edu-router 2.13.5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,616 kB
  • sloc: sh: 12,562; perl: 74; makefile: 35
file content (113 lines) | stat: -rwxr-xr-x 3,528 bytes parent folder | download
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
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash

# Copyright (C) 2010-2023 Pädagogisches Landesinstitut Rheinland-Pfalz
# Copyright (C) 2022-2023 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
# Copyright (C) 2022-2023 Daniel Teichmann <daniel.teichmann@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.

# preinst script for debian-edu-router-config

set -e

. /usr/share/debconf/confmodule || exit 255
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

# prepare debconf
export DC_PRIO_LOW="medium"
export DC_PRIO_HIGH="high"

if [ -e /etc/debian-edu/router.conf ]; then
	source /etc/debian-edu/router.conf
fi
PRODUCTNAME="${PRODUCTNAME:-"Debian Edu Router"}"
db_title "$PRODUCTNAME"

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
	install|upgrade)
		# Make sure these directories exist first.
		mkdir -p /etc/debian-edu-router/

		touch /etc/debian-edu-router/MANAGED_BY_DEBIAN_EDU_ROUTER
		cat <<-'EOF' > /etc/debian-edu-router/MANAGED_BY_DEBIAN_EDU_ROUTER
			# THIS DIRECTORY IS MANAGED BY DEBIAN EDU ROUTER.
			# Do not delete or modify any symlinks in this directory, except you exactly
			# know what you are doing.
		EOF

		mkdir -p /etc/uif/uif.conf.d/
		mkdir -p /etc/uif/uif-ipv4-networks.inc.d/
		mkdir -p /etc/uif/uif-ipv6-networks.inc.d/
		mkdir -p /etc/network/interfaces.d/
		mkdir -p /etc/dnsmasq.d/debian-edu-router/
		mkdir -p /etc/ssh/sshd_config.d/

		# Make sure symlinks are actually symlinks and not real directories.
		symlinks=(
			"/etc/debian-edu-router/uif.conf.d"
			"/etc/debian-edu-router/uif-ipv4-networks.inc.d"
			"/etc/debian-edu-router/uif-ipv6-networks.inc.d"
			"/etc/debian-edu-router/interfaces.d"
			"/etc/debian-edu-router/dnsmasq.d"
			"/etc/debian-edu-router/ssh.d"
		)

		for link in "${symlinks[@]}"; do
			if [ ! -L "${link}" ] && [ -e "${link}" ]; then
				if [[ -d "${link}" && -z "$( ls ${link} -A )" ]]; then
					rm -r "${link}"
					notice_log "Directory '$link' was not a symlink! It was empty, removed it."
				else
					backup_dir="${link}.no-symlink-$(date +%Y.%m.%d-%H:%M:%S)"
					mv "${link}" "${backup_dir}"
					warning_log "Directory '$link' was not a symlink! Moved it to '$backup_dir'."
				fi
			fi
		done
	;;

	abort-upgrade)
	;;

	*)
		echo "preinst called with unknown argument \`$1'" >&2
		exit 1
	;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0