summaryrefslogtreecommitdiffstats
path: root/debian/progress-linux.postinst
blob: c44a254a1f09963a59839f85520f29f9c2b8b25e (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/sh

set -e

PROJECT="progress-linux"
DOMAIN="progress-linux.org"
PACKAGES="https://deb.progress-linux.org/packages"
KEY="/usr/share/progress-linux/pgp-keys/deb.progress-linux.org.gpg"

Install_apt_sources ()
{
cat > "/etc/apt/sources.list.d/${PROJECT}.sources" << EOF
# /etc/apt/sources.list.d/${PROJECT}.sources
EOF
}

Remove_apt_sources ()
{
	rm -f "/etc/apt/sources.list.d/${PROJECT}.sources"
}

Install_apt_preferences ()
{
cat > "/etc/apt/preferences.d/${PROJECT}.pref" << EOF
# /etc/apt/preferences.d/${PROJECT}.pref
EOF
}

Remove_apt_preferences ()
{
	rm -f "/etc/apt/preferences.d/${PROJECT}.pref"
}

Configure_apt_sources ()
{
	# Configure repositories: ${release}, ${release}-security, ${release}-updates, ${release}-backports
	SUITES=""

	for ARCHIVE in ${ARCHIVES}
	do
		case "${ARCHIVE}" in
			*-extras|*-test)
				;;

			*)
				SUITES="${SUITES} ${ARCHIVE}"

				Configure_apt_preferences ${ARCHIVE}
				;;
		esac
	done

	COMPONENTS="$(echo ${ARCHIVE_AREAS} | sed -e 's| restricted||')"
	SUITES="$(echo ${SUITES} | sed -e 's|^ *||')"

	if [ -n "${SUITES}" ]
	then
		Configure_apt_sources_stanza "${SUITES}" "${COMPONENTS}"
	fi

	# Configure repositories: ${release}-extras, ${release}-test, ${release}-backports-extras, ${release}-backports-test
	SUITES=""

	for ARCHIVE in ${ARCHIVES}
	do
		case "${ARCHIVE}" in
			*-extras|*-test)
				SUITES="${SUITES} ${ARCHIVE}"

				Configure_apt_preferences ${ARCHIVE}
				;;

			*)
				;;
		esac
	done

	COMPONENTS="${ARCHIVE_AREAS}"
	SUITES="$(echo ${SUITES} | sed -e 's|^ *||')"

	if [ -n "${SUITES}" ]
	then
		Configure_apt_sources_stanza "${SUITES}" "${COMPONENTS}"
	fi
}

Configure_apt_sources_stanza ()
{
	SUITES="${1}"
	COMPONENTS="${2}"

cat >> "/etc/apt/sources.list.d/${PROJECT}.sources" << EOF

Types: deb
URIs: ${MIRROR}
Suites: ${SUITES}
Components: ${COMPONENTS}
PDiffs: no
Signed-By: ${KEY}
EOF
}

Configure_apt_preferences ()
{
	ARCHIVE="${1}"

	case "${ARCHIVE}" in
		*-backports*)
			PIN_PRIORITY="${BACKPORTS_PRIORITY}"
			;;

		*)
			PIN_PRIORITY="999"
			;;
	esac

cat >> "/etc/apt/preferences.d/${PROJECT}.pref" << EOF

Package: *
Pin: release o=${PROJECT}, n=${ARCHIVE}
Pin-Priority: ${PIN_PRIORITY}
EOF
}

Configure_ssh_known_hosts ()
{
	KEY="$(cat /usr/share/${PROJECT}/ssh-keys/ssh.${DOMAIN}.pub)"

	if [ ! -e "/etc/ssh/ssh_known_hosts" ]
	then
		mkdir -p /etc/ssh

cat > "/etc/ssh/ssh_known_hosts" << EOF
# /etc/ssh/ssh_known_hosts

@cert-authority *.${DOMAIN} ${KEY}
EOF

	else
		grep -v "^@cert-authority \*.${DOMAIN}" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.tmp

cat >> "/etc/ssh/ssh_known_hosts.tmp" << EOF
@cert-authority *.${DOMAIN} ${KEY}
EOF

		mv -f /etc/ssh/ssh_known_hosts.tmp /etc/ssh/ssh_known_hosts
	fi
}

Remove_ssh_known_hosts ()
{
	if [ ! -e /etc/ssh/ssh_known_hosts ]
	then
		return
	fi

	# ssh cert-authority
	grep -v "^@cert-authority \*.${DOMAIN}" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.tmp

	if [ "$(md5sum /etc/ssh/ssh_known_hosts.tmp | cut -d' ' -f1)" = "2a2b4fdd70705b2029b35a24217138e6" ]
	then
		rm -f /etc/ssh/ssh_known_hosts.tmp
		rm -f /etc/ssh/ssh_known_hosts

		rmdir /etc/ssh > /dev/null 2>&1 || true
	else
		mv -f /etc/ssh/ssh_known_hosts.tmp /etc/ssh/ssh_known_hosts
	fi
}

Clean ()
{
	# Remove apt keys
	rm -f "/etc/apt/trusted.gpg.d/${PROJECT}.gpg"

	# Remove apt lists
	rm -f "/etc/apt/sources.list.d/${PROJECT}.list"
}

case "${1}" in
	configure)
		. /usr/share/debconf/confmodule

		db_get ${PROJECT}/archives
		ARCHIVES="$(echo ${RET} | sed -e 's|, | |g')" # multiselect w/ empty

		db_get ${PROJECT}/archive-areas
		ARCHIVE_AREAS="$(echo ${RET:-main} | sed -e 's|, | |g')" # string w/o empty

		db_get ${PROJECT}/mirror
		MIRROR="$(echo ${RET:-${PACKAGES}})" # string w/o empty

		db_stop

		BACKPORTS_PRIORITY="100"

		for ARCHIVE in ${ARCHIVES}
		do
			case "${ARCHIVE}" in
				engywuck|fuchur|graograman|horok|illuan)
					BACKPORTS_PRIORITY="999"
					;;
			esac
		done

		DEBIAN_VERSION="$(cat /etc/debian_version)"

		case "${DEBIAN_VERSION}" in
			10.*|buster/sid)
				;;

			11.*|bullseye/sid)
				;;

			12.*|bookworm/sid)
				;;

			13.*|trixie/sid)
				;;

			14.*|forky/sid)
				;;

			*)
				echo "W: unsupported debian release"

				Remove_apt_sources
				Remove_apt_preferences

				Remove_ssh_known_hosts

				exit 0
				;;
		esac

		# apt
		if [ -n "${ARCHIVES}" ]
		then
			Install_apt_sources
			Install_apt_preferences

			Configure_apt_sources
		else
			Remove_apt_sources
			Remove_apt_preferences
		fi

		# openssh-server
		Configure_ssh_known_hosts

		# upgrading from buster
		Clean
		;;

	abort-upgrade|abort-remove|abort-deconfigure)

		;;

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

#DEBHELPER#

exit 0