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