chiark / gitweb /
1d0c320067714f1f1c25d8cc79ba75e075f1d222
[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     if 'jarsigner' not in config:
44         logging.critical('Java jarsigner not found! Install in standard location or set java_paths!')
45         sys.exit(1)
46
47     repodirs = ['repo']
48     if config['archive_older'] != 0:
49         repodirs.append('archive')
50
51     signed = 0
52     for output_dir in repodirs:
53         if not os.path.isdir(output_dir):
54             logging.error("Missing output directory '" + output_dir + "'")
55             sys.exit(1)
56
57         unsigned = os.path.join(output_dir, 'index_unsigned.jar')
58         if os.path.exists(unsigned):
59
60             args = [config['jarsigner'], '-keystore', config['keystore'],
61                     '-storepass:file', config['keystorepassfile'],
62                     '-digestalg', 'SHA1', '-sigalg', 'SHA1withRSA',
63                     unsigned, config['repo_keyalias']]
64             if config['keystore'] == 'NONE':
65                 args += config['smartcardoptions']
66             else:  # smardcards never use -keypass
67                 args += ['-keypass:file', config['keypassfile']]
68             p = FDroidPopen(args)
69             if p.returncode != 0:
70                 logging.critical("Failed to sign index")
71                 sys.exit(1)
72             os.rename(unsigned, os.path.join(output_dir, 'index.jar'))
73             logging.info('Signed index in ' + output_dir)
74             signed += 1
75
76     if signed == 0:
77         logging.info("Nothing to do")
78
79 if __name__ == "__main__":
80     main()