#!/usr/bin/env python3 import os import subprocess from base64 import encodestring as encode HELPDIR = '../../src/leap/bitmask/vpn/helpers/linux/' INSTALL = '../../snap/hooks/install' POLKIT_FILE = 'se.leap.bitmask.riseupvpn.policy' 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('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") """.format(polkit=b64_polkit, polkit_file=POLKIT_FILE)) subprocess.Popen(["chmod", "+x", INSTALL]) print("done packing installers into the snap install hook...")