From 0ff0191696723fd5885885974d47a9d54d7944bf Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Thu, 4 Oct 2018 22:10:21 +0200 Subject: [pkg] add desktop entry in debian as a workaround for snap desktop entries not being available system-wide there --- snap/Makefile | 16 +++++++++++++ snap/hooks/install | 8 +++++++ snap/pre/pack_installers | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 snap/Makefile create mode 100755 snap/pre/pack_installers diff --git a/snap/Makefile b/snap/Makefile new file mode 100644 index 0000000..f00d3f6 --- /dev/null +++ b/snap/Makefile @@ -0,0 +1,16 @@ +# Build a snap package for RiseupVPN. +# (c) LEAP Encryption Access Project, 2018 +# We have to use classic confinement because it does not seem to be another way, at the moment, +# to use policykit. + +helpers: + pre/pack_installers +build: helpers + # for speeding up build, see https://tribaal.io/making-lxd-fly-on-ubuntu-as-well.html + sudo snapcraft cleanbuild +install: + sudo snap install riseup-vpn_*.snap --dangerous --classic +deps: + sudo apt install snapcraft lxd +init-lxd: + sudo lxd init diff --git a/snap/hooks/install b/snap/hooks/install index c435f00..70301c0 100755 --- a/snap/hooks/install +++ b/snap/hooks/install @@ -4,6 +4,7 @@ # for the RiseupVPN snap. # It is generated automatically # by the script at "pkg/riseupvpn/pack_installers" +import subprocess from base64 import decodestring as decode POLKIT = b'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHBvbGljeWNv\nbmZpZyBQVUJMSUMKICItLy9mcmVlZGVza3RvcC8vRFREIFBvbGljeUtpdCBQb2xpY3kgQ29uZmln\ndXJhdGlvbiAxLjAvL0VOIgogImh0dHA6Ly93d3cuZnJlZWRlc2t0b3Aub3JnL3N0YW5kYXJkcy9Q\nb2xpY3lLaXQvMS9wb2xpY3ljb25maWcuZHRkIj4KPHBvbGljeWNvbmZpZz4KCiAgPHZlbmRvcj5M\nRUFQIFByb2plY3Q8L3ZlbmRvcj4KIC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@@ -12,3 +13,10 @@ with open('/usr/share/polkit-1/actions/se.leap.bitmask.riseupvpn.policy', 'w') a 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 lines: + cmd = 'ln -s /snap/riseup-vpn/current/snap/gui/riseup-vpn.desktop /usr/share/applications/' + subprocess.run(cmd.split(' ')) + subprocess.run(['update-desktop-database']) 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...") -- cgit v1.2.3