summaryrefslogtreecommitdiffstats
path: root/debian/progress-linux.postinst
blob: 59e68c968ae1cebabe2311e458985cd02b283bf7 (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
#!/bin/sh

set -e

Install_apt ()
{
	# apt sources
	echo "Installing /etc/apt/sources.list.d/progress-linux.list ..."

cat > /etc/apt/sources.list.d/progress-linux.list << EOF
# /etc/apt/sources.list.d/progress-linux.list

EOF

	# apt preferences
	echo "Installing /etc/apt/preferences.d/progress-linux.pref ..."

cat > /etc/apt/preferences.d/progress-linux.pref << EOF
# /etc/apt/preferences.d/progress-linux.pref
EOF

	# apt key
	echo "Installing /etc/apt/trusted.gpg.d/progress-linux.gpg ..."
	rm -f /etc/apt/trusted.gpg.d/progress-linux.gpg
	for KEY in /usr/share/progress-linux/pgp-keys/*archive-key.gpg
	do
		cat "${KEY}" >> /etc/apt/trusted.gpg.d/progress-linux.gpg
	done
}

Remove_apt ()
{
	# apt sources
	echo "Removing /etc/apt/sources.list.d/progress-linux.list ..."
	rm -f /etc/apt/sources.list.d/progress-linux.list

	# apt preferences
	echo "Removing /etc/apt/sources.list.d/progress-linux.list ..."
	rm -f /etc/apt/preferences.d/progress-linux.pref

	# apt key
	echo "Removing /etc/apt/trusted.gpg.d/progress-linux.gpg ..."
	rm -f /etc/apt/trusted.gpg.d/progress-linux.gpg
}

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

	case "${ARCHIVE}" in
		*-extras)
			AREAS="${ARCHIVE_AREAS}"
			;;

		*)
			AREAS="$(echo ${ARCHIVE_AREAS} | sed -e 's| restricted||')"
			;;
	esac

	# apt sources
	cat >> /etc/apt/sources.list.d/progress-linux.list << EOF
deb https://deb.progress-linux.org/packages ${ARCHIVE} ${AREAS}
EOF

	# apt preferences
	cat >> /etc/apt/preferences.d/progress-linux.pref << EOF

Package: *
Pin: release n=${ARCHIVE}
Pin-Priority: 999
EOF
}

Configure_ssh ()
{
	KEY="$(cat /usr/share/progress-linux/ssh-keys/ssh.progress-linux.org.pub)"

	echo "Installing /etc/ssh/ssh_known_hosts ..."

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

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

@cert-authority *.progress-linux.org ${KEY}
EOF

	else
		grep -v '^@cert-authority \*.progress-linux.org' /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.tmp

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

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

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

		db_get progress-linux/archives
		ARCHIVES="${RET}" # multiselect w/ empty

		db_get progress-linux/archive-areas
		ARCHIVE_AREAS="${RET:-main}" # string w/o empty

		db_stop

		if [ -n "${ARCHIVES}" ]
		then
			Install_apt
		else
			Remove_apt
		fi

		ARCHIVES="$(echo ${ARCHIVES} | sed -e 's|, | |g')"
		ARCHIVE_AREAS="$(echo ${ARCHIVE_AREAS} | sed -e 's|, | |g')"

		for ARCHIVE in ${ARCHIVES}
		do
			Configure_apt ${ARCHIVE}
		done

		Configure_ssh
		;;

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

		;;

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

#DEBHELPER#

exit 0