chiark / gitweb /
makebuildserver: explicitly set debian_mirror by default
[fdroidserver.git] / fdroidserver / signindex.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 #
4 # gpgsign.py - part of the FDroid server tools
5 # Copyright (C) 2015, Ciaran Gultnieks, ciaran@ciarang.com
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 import sys
21 import os
22 from argparse import ArgumentParser
23 import logging
24
25 import common
26 from common import FDroidPopen
27
28 config = None
29 options = None
30
31
32 def main():
33
34     global config, options
35
36     # Parse command line...
37     parser = ArgumentParser(usage="%(prog)s [options]")
38     common.setup_global_opts(parser)
39     options = parser.parse_args()
40
41     config = common.read_config(options)
42
43     repodirs = ['repo']
44     if config['archive_older'] != 0:
45         repodirs.append('archive')
46
47     signed = 0
48     for output_dir in repodirs:
49         if not os.path.isdir(output_dir):
50             logging.error("Missing output directory '" + output_dir + "'")
51             sys.exit(1)
52
53         unsigned = os.path.join(output_dir, 'index_unsigned.jar')
54         if os.path.exists(unsigned):
55
56             args = ['jarsigner', '-keystore', config['keystore'],
57                     '-storepass:file', config['keystorepassfile'],
58                     '-digestalg', 'SHA1', '-sigalg', 'SHA1withRSA',
59                     unsigned, config['repo_keyalias']]
60             if config['keystore'] == 'NONE':
61                 args += config['smartcardoptions']
62             else:  # smardcards never use -keypass
63                 args += ['-keypass:file', config['keypassfile']]
64             p = FDroidPopen(args)
65             if p.returncode != 0:
66                 logging.critical("Failed to sign index")
67                 sys.exit(1)
68             os.rename(unsigned, os.path.join(output_dir, 'index.jar'))
69             logging.info('Signed index in ' + output_dir)
70             signed += 1
71
72     if signed == 0:
73         logging.info("Nothing to do")
74
75 if __name__ == "__main__":
76     main()