-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkout-keystore
executable file
·44 lines (34 loc) · 1.22 KB
/
checkout-keystore
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
#!/usr/bin/env python3
#
# Translated from the Bash script `checkout-keystore.orig`.
#
# "TODO" comments mark things that could be improved in Pysh.
import os
import sys
import time
import click
from pysh import check_cmd_f, slurp_cmd, try_cmd_f
@click.command()
def main():
# TODO careful with fsdecode/fsencode in the right places
rootdir = os.fsdecode(slurp_cmd('git rev-parse --show-toplevel'))
cleartext = f'{rootdir}/android/release.keystore'
cryptotext = f'{rootdir}/android/release.keystore.gpg'
check_cmd_f('gpg -d -o {cleartext} {cryptotext}')
wait_min = 15
# This pattern translates `( ... ) &` -- pretty exactly, I think!
# Specifically the `if os.fork() == 0: ... sys.exit(0)`.
# TODO provide as perhaps a context manager?
# Important wrinkle when doing so: put exit in a `finally`.
# Also troublesome are any destructors that do more than
# free the memory; not sure what can be done about those.
if os.fork() == 0:
time.sleep(wait_min * 60)
try_cmd_f('rm -f {cleartext}')
sys.exit(0)
print(f'''
Wrote decrypted file: {cleartext}
This file will be deleted in {wait_min} minutes.
''', file=sys.stderr)
if __name__ == '__main__':
main()