~elementary-os/elementaryos/release-channel-packages-generator

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
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash

# This is script which generates a release channel package from a list of PPAs.
# It written by Sergey "Shnatsel" Davidoff

# Copyright (c) 2012 elementary Project

# 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 3 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, see <http://www.gnu.org/licenses/>.

# get channel name or output usage if none given
if [ "$1" = "" ]; then
echo "Parameters: channel-name ppa:some-team/some-ppa [ppa:some-other-team/some-other-ppa ...]
Example: ./generate_release_channel_package elementary-testing ppa:elementary-os/testing ppa:nemequ/sqlheavy" > /dev/stderr
exit 1
else
export channel="$1"
shift
fi

# sanity check
if [ "$1" = "" ]; then
echo "Error: no PPAs specified.
You must specify at least one PPA to include in the release channel." > /dev/stderr
exit 1
else
export ppa_list="$@"
fi

write_static_templates() {
# create required dirs
mkdir -p debian
mkdir -p debian/source
mkdir -p keys

# write static files
echo '3.0 (native)' > 'debian/source/format'
echo '7' > 'debian/compat'

echo '#!/usr/bin/make -f
%:
	dh $@' > debian/rules
}

get_signing_key_id_for_ppa() {
# accepts "ppa:some-person/some-ppa" sting as parameter, prints its signing key ID
ppa="$1"
tempfile=$(mktemp)
wget -nv --output-document="$tempfile" 'https://launchpad.net/~'$(echo $ppa | cut -d ':' -f 2 | sed 's|/|/+archive/|' ) || exit 1
keyID=$(grep '<code>1024R' "$tempfile" | tr -d ' ' | sed 's|<code>1024R/||' | sed 's|</code>||')
rm "$tempfile"
echo "$keyID"
}

get_debline_for_ppa() {
ppa="$1"
debline="http://ppa.launchpad.net/"$(echo $ppa | cut -d ':' -f 2)"/ubuntu "$( lsb_release -cs )" main"
echo "$debline"
}

get_sourceslist_filename_for_ppa() {
# picks a deterministic file name for the sources.list.d/ entry of the PPA, likely to be unique
# returns just the name of the file, not the full path to it
ppa="$1"
sourceslist_filename="$channel"'-channel-'$(echo $ppa | cut -d ':' -f 2 | tr '/' '-' )'-'$( lsb_release -cs )'.list'
echo "$sourceslist_filename"
}

download_public_key() {
# downloads signing key with given ID from keyserver.ubuntu.com
if ! [ -e keys/"$keyID".pub ]; then
gpg --keyserver keyserver.ubuntu.com --recv-keys 0x"$keyID"
gpg --output keys/"$keyID".pub --export "$keyID"
fi
}

write_copyright() {
echo 'This package was generated by an automated script written by:

    Sergey "Shnatsel" Davidoff <shnatsel@gmail.com>

Upstream Author(s):

    Sergey "Shnatsel" Davidoff <shnatsel@gmail.com>

Copyright:

    Copyright (C) 2012 elementary Project

License:

    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 3 of the License, or
    (at your option) any later version.

    This package 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, see <http://www.gnu.org/licenses/>.

On Debian systems, the complete text of the GNU General
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".

The Debian packaging is:

    Copyright (C) 2012 Sergey "Shnatsel" Davidoff <shnatsel@gmail.com>

and is licensed under the GPL version 3, see above.' > debian/copyright
}

write_install() {
# debian/install
echo "keys /usr/share/$channel-release-channel/" > 'debian/install'
}

write_control() {
# debian/control
(
echo 'Source: '"$channel"'-release-channel'
echo 'Section: metapackages
Priority: optional
Maintainer: Sergey "Shnatsel" Davidoff <shnatsel@gmail.com>
Build-Depends: debhelper (>= 7)
Standards-Version: 3.9.2
'
echo 'Package: '"$channel"'-release-channel'
echo 'Architecture: all
Depends: ${misc:Depends}, ppa-purge-aptdaemon
Description: '"$channel"' release channel'
echo ' <insert something meaningful here>'
) > debian/control
}

write_changelog() {
# if there's no changelog yet, write one
if ! [ -e debian/changelog ]; then
name_and_email=$(bzr whoami)
if [ "$name_and_email" = "" ]; then
name_and_email='Your Name <name@example.com>'
fi
echo "$channel"'-release-channel (0.1) '$( lsb_release -cs )'; urgency=low

  * Initial Release.

 -- '"$name_and_email"'  '$(date -R) > debian/changelog
else
echo "debian/changelog already exists. You'll have to update it manually." > /dev/stderr
fi
}

write_preinst() {
(
echo '#!/bin/sh
# This file is auto-generated. Do not waste your time editing it.

# write sources.list entries
# we cannot simply ship them in the package because in this case they will
# be removed before we ppa-purge them (remember, ppa-purge is delayed,
# it happens AFTER postrm)'
for ppa in $ppa_list; do
debline=$(get_debline_for_ppa "$ppa")
sourceslist_filename=$(get_sourceslist_filename_for_ppa "$ppa")
echo "(
echo deb $debline
echo deb-src $debline
) > /etc/apt/sources.list.d/$sourceslist_filename"
done

echo '
# force sources.list entries to be writeable (LP: #399709)'
for ppa in $ppa_list; do
sourceslist_filename=$(get_sourceslist_filename_for_ppa "$ppa")
echo "chmod 664 /etc/apt/sources.list.d/$sourceslist_filename"
done

echo '
#DEBHELPER#'
) > debian/preinst
}

write_postinst() {
(
echo '#!/bin/sh
# This file is auto-generated. Do not waste your time editing it.

# import signing keys'
for ppa in $ppa_list; do
keyID=$(get_signing_key_id_for_ppa "$ppa")
download_public_key $keyID
echo "aptdcon --add-vendor-key /usr/share/$channel-release-channel/keys/$keyID.pub &"
done
echo '
case "$1" in
upgrade)
('
for ppa in $ppa_list; do
echo "echo $ppa"
done
echo ") > /var/tmp/$channel-release-channel/ppa-list-new.unsorted
sort /var/tmp/$channel-release-channel/ppa-list-new.unsorted > /var/tmp/$channel-release-channel/ppa-list-new
rm /var/tmp/$channel-release-channel/ppa-list-new.unsorted"
echo 'for ppa in $(comm -23 --nocheck-order /var/tmp/'"$channel"'-release-channel/ppa-list-old /var/tmp/'"$channel"'-release-channel/ppa-list-new); do
ppa-purge -r $ppa &
done'
echo 'rm /var/tmp/'"$channel"'-release-channel/ppa-list-old /var/tmp/'"$channel"'-release-channel/ppa-list-new'
echo ';;
'
echo '*)'
echo 'echo "Unrecognized action; probably nothing to do." > /dev/stderr'
echo ';;
'
echo 'esac

# enqueue repository data update
aptdcon --refresh &

#DEBHELPER#'
) > debian/postinst
}

write_postrm() {
(
echo '#!/bin/sh
# This file is auto-generated. Do not waste your time editing it.

case "$1" in'

echo 'upgrade)'
echo "mkdir -p /var/tmp/$channel-release-channel/"
echo '('
for ppa in $ppa_list; do
echo "echo $ppa"
done
echo ") > /var/tmp/$channel-release-channel/ppa-list-old.unsorted
sort /var/tmp/$channel-release-channel/ppa-list-old.unsorted > /var/tmp/$channel-release-channel/ppa-list-old
rm /var/tmp/$channel-release-channel/ppa-list-old.unsorted"
echo ';;
'
echo 'remove|purge)
# enqueue ppa-purges - requires the aptdaemon version of ppa-purge'
for ppa in $ppa_list; do
echo "ppa-purge -r $ppa &"
done
echo ';;
'
echo '*)'
echo 'echo "Unrecognized action; probably nothing to do." > /dev/stderr'
echo ';;
'
echo 'esac

#DEBHELPER#'
) > debian/postrm
}

# int main() {
write_static_templates
write_control
write_install
write_copyright
write_changelog
write_preinst
write_postinst
write_postrm
# }