2 # -*- coding: utf-8 -*-
4 # gpgsign.py - part of the FDroid server tools
5 # Copyright (C) 2015, Ciaran Gultnieks, ciaran@ciarang.com
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.
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.
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/>.
22 from argparse import ArgumentParser
26 from common import FDroidPopen
34 global config, options
36 # Parse command line...
37 parser = ArgumentParser(usage="%(prog)s [options]")
38 common.setup_global_opts(parser)
39 options = parser.parse_args()
41 config = common.read_config(options)
43 if not 'jarsigner' in config:
44 logging.critical('Java jarsigner not found! Install in standard location or set java_paths!')
48 if config['archive_older'] != 0:
49 repodirs.append('archive')
52 for output_dir in repodirs:
53 if not os.path.isdir(output_dir):
54 logging.error("Missing output directory '" + output_dir + "'")
57 unsigned = os.path.join(output_dir, 'index_unsigned.jar')
58 if os.path.exists(unsigned):
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']]
70 logging.critical("Failed to sign index")
72 os.rename(unsigned, os.path.join(output_dir, 'index.jar'))
73 logging.info('Signed index in ' + output_dir)
77 logging.info("Nothing to do")
79 if __name__ == "__main__":