Debian Codegraph @

debian/progress-linux.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 PROJECT="progress-linux"
6 DOMAIN="progress-linux.org"
7 PACKAGES="https://deb.progress-linux.org/packages"
8 KEY="/usr/share/progress-linux/pgp-keys/deb.progress-linux.org.pgp"
9
10 Install_apt_sources ()
11 {
12 cat > "/etc/apt/sources.list.d/${PROJECT}.sources" << EOF
13 # /etc/apt/sources.list.d/${PROJECT}.sources
14 EOF
15 }
16
17 Remove_apt_sources ()
18 {
19 rm -f "/etc/apt/sources.list.d/${PROJECT}.sources"
20 }
21
22 Install_apt_preferences ()
23 {
24 cat > "/etc/apt/preferences.d/${PROJECT}.pref" << EOF
25 # /etc/apt/preferences.d/${PROJECT}.pref
26 EOF
27 }
28
29 Remove_apt_preferences ()
30 {
31 rm -f "/etc/apt/preferences.d/${PROJECT}.pref"
32 }
33
34 Configure_apt_sources ()
35 {
36 # Configure repositories: ${release}, ${release}-security, ${release}-updates, ${release}-backports
37 SUITES=""
38
39 for ARCHIVE in ${ARCHIVES}
40 do
41 case "${ARCHIVE}" in
42 *-extras|*-test)
43 ;;
44
45 *)
46 SUITES="${SUITES} ${ARCHIVE}"
47
48 Configure_apt_preferences ${ARCHIVE}
49 ;;
50 esac
51 done
52
53 COMPONENTS="$(echo ${ARCHIVE_AREAS} | sed -e 's| restricted||')"
54 SUITES="$(echo ${SUITES} | sed -e 's|^ *||')"
55
56 if [ -n "${SUITES}" ]
57 then
58 Configure_apt_sources_stanza "${SUITES}" "${COMPONENTS}"
59 fi
60
61 # Configure repositories: ${release}-extras, ${release}-test, ${release}-backports-extras, ${release}-backports-test
62 SUITES=""
63
64 for ARCHIVE in ${ARCHIVES}
65 do
66 case "${ARCHIVE}" in
67 *-extras|*-test)
68 SUITES="${SUITES} ${ARCHIVE}"
69
70 Configure_apt_preferences ${ARCHIVE}
71 ;;
72
73 *)
74 ;;
75 esac
76 done
77
78 COMPONENTS="${ARCHIVE_AREAS}"
79 SUITES="$(echo ${SUITES} | sed -e 's|^ *||')"
80
81 if [ -n "${SUITES}" ]
82 then
83 Configure_apt_sources_stanza "${SUITES}" "${COMPONENTS}"
84 fi
85 }
86
87 Configure_apt_sources_stanza ()
88 {
89 SUITES="${1}"
90 COMPONENTS="${2}"
91
92 cat >> "/etc/apt/sources.list.d/${PROJECT}.sources" << EOF
93
94 Types: deb
95 URIs: ${MIRROR}
96 Suites: ${SUITES}
97 Components: ${COMPONENTS}
98 PDiffs: no
99 Signed-By: ${KEY}
100 EOF
101 }
102
103 Configure_apt_preferences ()
104 {
105 ARCHIVE="${1}"
106
107 case "${ARCHIVE}" in
108 *-backports*)
109 PIN_PRIORITY="${BACKPORTS_PRIORITY}"
110 ;;
111
112 *)
113 PIN_PRIORITY="999"
114 ;;
115 esac
116
117 cat >> "/etc/apt/preferences.d/${PROJECT}.pref" << EOF
118
119 Package: *
120 Pin: release o=${PROJECT}, n=${ARCHIVE}
121 Pin-Priority: ${PIN_PRIORITY}
122 EOF
123 }
124
125 Configure_ssh_known_hosts ()
126 {
127 KEY="$(cat /usr/share/${PROJECT}/ssh-keys/ssh.${DOMAIN}.pub)"
128
129 if [ ! -e "/etc/ssh/ssh_known_hosts" ]
130 then
131 mkdir -p /etc/ssh
132
133 cat > "/etc/ssh/ssh_known_hosts" << EOF
134 # /etc/ssh/ssh_known_hosts
135
136 @cert-authority *.${DOMAIN} ${KEY}
137 EOF
138
139 else
140 grep -v "^@cert-authority \*.${DOMAIN}" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.tmp
141
142 cat >> "/etc/ssh/ssh_known_hosts.tmp" << EOF
143 @cert-authority *.${DOMAIN} ${KEY}
144 EOF
145
146 mv -f /etc/ssh/ssh_known_hosts.tmp /etc/ssh/ssh_known_hosts
147 fi
148 }
149
150 Remove_ssh_known_hosts ()
151 {
152 if [ ! -e /etc/ssh/ssh_known_hosts ]
153 then
154 return
155 fi
156
157 # ssh cert-authority
158 grep -v "^@cert-authority \*.${DOMAIN}" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.tmp
159
160 if [ "$(md5sum /etc/ssh/ssh_known_hosts.tmp | cut -d' ' -f1)" = "2a2b4fdd70705b2029b35a24217138e6" ]
161 then
162 rm -f /etc/ssh/ssh_known_hosts.tmp
163 rm -f /etc/ssh/ssh_known_hosts
164
165 rmdir /etc/ssh > /dev/null 2>&1 || true
166 else
167 mv -f /etc/ssh/ssh_known_hosts.tmp /etc/ssh/ssh_known_hosts
168 fi
169 }
170
171 case "${1}" in
172 configure)
173 . /usr/share/debconf/confmodule
174
175 db_get ${PROJECT}/archives
176 ARCHIVES="$(echo ${RET} | sed -e 's|, | |g')" # multiselect w/ empty
177
178 db_get ${PROJECT}/archive-areas
179 ARCHIVE_AREAS="$(echo ${RET:-main} | sed -e 's|, | |g')" # string w/o empty
180
181 db_get ${PROJECT}/mirror
182 MIRROR="$(echo ${RET:-${PACKAGES}})" # string w/o empty
183
184 db_stop
185
186 BACKPORTS_PRIORITY="100"
187
188 for ARCHIVE in ${ARCHIVES}
189 do
190 case "${ARCHIVE}" in
191 horok|illuan|jicha)
192 BACKPORTS_PRIORITY="999"
193 ;;
194 esac
195 done
196
197 DEBIAN_VERSION="$(cat /etc/debian_version)"
198
199 case "${DEBIAN_VERSION}" in
200 13|13.*|trixie/sid)
201 ;;
202
203 14|14.*|forky/sid)
204 ;;
205
206 15|15.*|duke/sid)
207 ;;
208
209 *)
210 echo "W: unsupported debian release"
211
212 Remove_apt_sources
213 Remove_apt_preferences
214
215 Remove_ssh_known_hosts
216
217 exit 0
218 ;;
219 esac
220
221 # apt
222 if [ -n "${ARCHIVES}" ]
223 then
224 Install_apt_sources
225 Install_apt_preferences
226
227 Configure_apt_sources
228 else
229 Remove_apt_sources
230 Remove_apt_preferences
231 fi
232
233 # openssh-server
234 Configure_ssh_known_hosts
235 ;;
236
237 abort-upgrade|abort-remove|abort-deconfigure)
238
239 ;;
240
241 *)
242 echo "postinst called with unknown argument \`${1}'" >&2
243 exit 1
244 ;;
245 esac
246
247 #DEBHELPER#
248
249 exit 0