From 83a2a5b4937441b55431db3e7cd476c94f1adc25 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Fri, 28 Jun 2019 17:11:00 +0200 Subject: [bug] use python3, newest ubuntu does not ship python bin --- snap/Makefile | 2 +- snap/hooks/install | 4 +-- snap/local/pre/pack_installers | 61 +++++++++++++++++++++++++++++++++++++++++ snap/pre/pack_installers | 62 ------------------------------------------ 4 files changed, 64 insertions(+), 65 deletions(-) create mode 100755 snap/local/pre/pack_installers delete mode 100755 snap/pre/pack_installers diff --git a/snap/Makefile b/snap/Makefile index f00d3f6..0d76a6f 100644 --- a/snap/Makefile +++ b/snap/Makefile @@ -4,7 +4,7 @@ # to use policykit. helpers: - pre/pack_installers + local/pre/pack_installers build: helpers # for speeding up build, see https://tribaal.io/making-lxd-fly-on-ubuntu-as-well.html sudo snapcraft cleanbuild diff --git a/snap/hooks/install b/snap/hooks/install index 98469fe..c34abf4 100755 --- a/snap/hooks/install +++ b/snap/hooks/install @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # DO NOT MODIFY MANUALLY # This helper installs the polkit policy file # for the RiseupVPN snap. @@ -22,5 +22,5 @@ if 'ID=debian' in release: desktop_path = "/usr/share/applications/riseup-vpn.desktop" if os.path.exists(desktop_path): os.remove(desktop_path) - os.symlink("/snap/riseup-vpn/current/snap/gui/riseup-vpn.desktop", desktop_path) + os.symlink("/snap/riseup-vpn/current/snap/meta/gui/riseup-vpn.desktop", desktop_path) subprocess.call(['update-desktop-database']) diff --git a/snap/local/pre/pack_installers b/snap/local/pre/pack_installers new file mode 100755 index 0000000..9cf7b15 --- /dev/null +++ b/snap/local/pre/pack_installers @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +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 "snap/local/pre/pack_installers"\n') + install.write('import subprocess\n') + install.write('import os\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") + +with open('/etc/os-release') as f: + release = f.read() +# this is a workaround for the fact that debian does not place snap desktop entries in a system+wide path. +if 'ID=debian' in release: + desktop_path = "/usr/share/applications/{app_name}.desktop" + if os.path.exists(desktop_path): + os.remove(desktop_path) + os.symlink("/snap/{app_name}/current/snap/meta/gui/{app_name}.desktop", desktop_path) + subprocess.call(['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...") diff --git a/snap/pre/pack_installers b/snap/pre/pack_installers deleted file mode 100755 index 827d16e..0000000 --- a/snap/pre/pack_installers +++ /dev/null @@ -1,62 +0,0 @@ -#!/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 python\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 "snap/pre/pack_installers"\n') - install.write('import subprocess\n') - install.write('import os\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") - -with open('/etc/os-release') as f: - release = f.read() -# this is a workaround for the fact that debian does not place snap desktop entries in a system+wide path. -if 'ID=debian' in release: - desktop_path = "/usr/share/applications/{app_name}.desktop" - if os.path.exists(desktop_path): - os.remove(desktop_path) - os.symlink("/snap/{app_name}/current/snap/gui/{app_name}.desktop", desktop_path) - subprocess.call(['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...") -- cgit v1.2.3