Skip to content

Commit 7230c35

Browse files
Wrap mount command in sudo if required
1 parent acac626 commit 7230c35

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/inputstreamhelper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,16 @@ def _losetup(self, bin_path):
153153

154154
def _mnt_loop_dev(self):
155155
"""Mount loop device to self._mnt_path()"""
156+
dialog = xbmcgui.Dialog()
156157
cmd = ['mount', '-t', 'ext2', self._loop_dev, '-o', 'ro', self._mnt_path()]
158+
if not os.getuid() == 0 and self._cmd_exists('sudo'): # ask for permission to wrap cmd in sudo
159+
if dialog.yesno(self._language(30001), self._language(30030), yeslabel=self._language(30029), nolabel=self._language(30028)):
160+
cmd.insert(0, 'sudo')
161+
else:
162+
self._log('User refused to give sudo permission.')
163+
else:
164+
self._log('User do not have root permissions and/or sudo installed.')
165+
157166
subprocess.check_output(cmd)
158167
self._mounted = True
159168
return True
@@ -452,6 +461,8 @@ def _cleanup(self):
452461
"""Clean up after Widevine DRM installation."""
453462
if self._mounted:
454463
cmd = ['umount', self._mnt_path()]
464+
if not os.getuid() == 0 and self._cmd_exists('sudo'): # no need to ask for permission again
465+
cmd.insert(0, 'sudo')
455466
subprocess.check_call(cmd)
456467
self._mounted = False
457468
if self._attached_loop_dev:

resources/language/resource.language.de_de/strings.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ msgstr "Ich akzeptiere die Bedingungen"
124124
msgctxt "#30028"
125125
msgid "Cancel"
126126
msgstr "Abbrechen"
127+
128+
msgctxt "#30029"
129+
msgid "OK"
130+
msgstr ""
131+
132+
msgctxt "#30030"
133+
msgid "Administrative rights ([B]sudo[/B]) is required to mount the Chrome OS image. Press OK to grant the installation permission to run the mount command as [B]sudo[/B]."
134+
msgstr ""

resources/language/resource.language.en_gb/strings.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ msgstr ""
124124
msgctxt "#30028"
125125
msgid "Cancel"
126126
msgstr ""
127+
128+
msgctxt "#30029"
129+
msgid "OK"
130+
msgstr ""
131+
132+
msgctxt "#30030"
133+
msgid "Administrative rights ([B]sudo[/B]) is required to mount the Chrome OS image. Press OK to grant the installation permission to run the mount command as [B]sudo[/B]."
134+
msgstr ""

0 commit comments

Comments
 (0)