diff options
Diffstat (limited to 'snap/pre/pack_installers')
-rwxr-xr-x | snap/pre/pack_installers | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/snap/pre/pack_installers b/snap/pre/pack_installers new file mode 100755 index 0000000..9c46efc --- /dev/null +++ b/snap/pre/pack_installers @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# TODO move to local/ folder. +import os +import subprocess +from base64 import encodestring as encode + +# we expect to find bitmask-dev cloned in the parent folder for this repo +# we will clone it if not +PARENT = '../../' +BITMASK_FOLDER = PARENT + 'bitmask-dev/' +BITMASK_GIT = 'https://0xacab.org/leap/bitmask-dev' +HELPDIR = BITMASK_FOLDER + 'src/leap/bitmask/vpn/helpers/linux/' +INSTALL = 'hooks/install' +POLKIT_FILE = 'se.leap.bitmask.riseupvpn.policy' +APP_NAME = 'riseup-vpn' + +if not os.path.isdir(BITMASK_FOLDER): + print('[+] Cloning bitmask-dev repo to get helpers...') + cmd = 'cd ../.. && git clone %s' % (BITMASK_GIT, ) + os.system(cmd) +else: + print('[+] Updating bitmask-dev repo to get helpers...') + cmd = 'cd ' + BITMASK_FOLDER + ' && git pull' + os.system(cmd) + +with open(os.path.join(HELPDIR, POLKIT_FILE)) as polkit: + b64_polkit = encode(polkit.read().encode()) + +with open(INSTALL, 'w') as install: + install.write('#!/usr/bin/env python3\n') + install.write('# DO NOT MODIFY MANUALLY\n') + install.write('# This helper installs the polkit policy file\n') + install.write('# for the RiseupVPN snap.\n') + install.write('# It is generated automatically\n') + install.write('# by the script at "pkg/riseupvpn/pack_installers" \n') + install.write('import subprocess\n') + install.write('from base64 import decodestring as decode\n') + install.write(""" +POLKIT = {polkit} + +with open('/usr/share/polkit-1/actions/{polkit_file}', 'w') as polkit: + lines = decode(POLKIT).split(b"\\n") + for line in lines: + polkit.write(line.decode() + "\\n") + +release = subprocess.run(['cat', '/etc/os-release'], stdout=subprocess.PIPE).stdout +# this is a workaround for the fact that debian does not place snap desktop entries in a system+wide path. +if b'ID=debian' in release: + cmd = 'ln -s /snap/{app_name}/current/snap/gui/{app_name}.desktop /usr/share/applications/' + subprocess.run(cmd.split(' ')) + subprocess.run(['update-desktop-database']) +""".format( + polkit=b64_polkit, + polkit_file=POLKIT_FILE, + app_name=APP_NAME)) + +subprocess.Popen(["chmod", "+x", INSTALL]) +print("[+] Done packing installers into the snap install hook...") |