~ubuntu-system-image/ubuntu-system-image/server

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
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2013 Canonical Ltd.
# Author: Stéphane Graber <stgraber@ubuntu.com>

# 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; version 3 of the License.
#
# 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/>.

import os
import sys
import time
sys.path.insert(0, 'lib')

from systemimage import config
from systemimage import gpg
from systemimage import tools

conf = config.Config()

# archive-master keyring
if os.path.exists(os.path.join(conf.gpg_key_path, "archive-master")):
    archive_master = gpg.Keyring(conf, "archive-master")
    archive_master.set_metadata("archive-master")
    archive_master.import_keys(os.path.join(conf.gpg_key_path,
                                            "archive-master"))
    path = archive_master.generate_tarball()
    tools.xz_compress(path)
    os.remove(path)
    gpg.sign_file(conf, "archive-master", "%s.xz" % path)

# image-master keyring
if os.path.exists(os.path.join(conf.gpg_key_path, "image-master")) and \
        os.path.exists(os.path.join(conf.gpg_key_path, "archive-master")):
    image_master = gpg.Keyring(conf, "image-master")
    image_master.set_metadata("image-master")
    image_master.import_keys(os.path.join(conf.gpg_key_path, "image-master"))
    path = image_master.generate_tarball()
    tools.xz_compress(path)
    os.remove(path)
    gpg.sign_file(conf, "archive-master", "%s.xz" % path)

# image-signing keyring
if os.path.exists(os.path.join(conf.gpg_key_path, "image-signing")) and \
        os.path.exists(os.path.join(conf.gpg_key_path, "image-master")):
    image_signing = gpg.Keyring(conf, "image-signing")
    image_signing.set_metadata("image-signing",
                               int(time.strftime("%s",
                                                 time.localtime())) + 63072000)
    image_signing.import_keys(os.path.join(conf.gpg_key_path, "image-signing"))
    path = image_signing.generate_tarball()
    tools.xz_compress(path)
    os.remove(path)
    gpg.sign_file(conf, "image-master", "%s.xz" % path)

# device-signing keyring
if os.path.exists(os.path.join(conf.gpg_key_path, "device-signing")) and \
        os.path.exists(os.path.join(conf.gpg_key_path, "image-signing")):
    device_signing = gpg.Keyring(conf, "device-signing")
    device_signing.set_metadata("device-signing",
                                int(time.strftime("%s",
                                                  time.localtime())) + 2678400)
    device_signing.import_keys(os.path.join(conf.gpg_key_path,
                                            "device-signing"))
    path = device_signing.generate_tarball()
    tools.xz_compress(path)
    os.remove(path)
    gpg.sign_file(conf, "image-signing", "%s.xz" % path)

# blacklist keyring
if os.path.exists(os.path.join(conf.gpg_key_path, "blacklist")) and \
        os.path.exists(os.path.join(conf.gpg_key_path, "image-master")):
    blacklist = gpg.Keyring(conf, "blacklist")
    blacklist.set_metadata("blacklist")
    path = blacklist.generate_tarball()
    tools.xz_compress(path)
    os.remove(path)
    gpg.sign_file(conf, "image-master", "%s.xz" % path)