@@ -152,14 +152,25 @@ def _parse_chromeos_offset(self, bin_path):
152
152
self ._log ('Failed to calculate losetup offset.' )
153
153
return False
154
154
155
- def _run_cmd (self , cmd ):
155
+ def _run_cmd (self , cmd , sudo = False , ask = True ):
156
+ dialog = xbmcgui .Dialog ()
157
+ if ask and not dialog .yesno (self ._language (30001 ), self ._language (30030 ), yeslabel = self ._language (30029 ), nolabel = self ._language (30028 )):
158
+ self ._log ('User refused to give sudo permissions.' )
159
+ return cmd
160
+ if sudo and os .getuid () != 0 and self ._cmd_exists ('sudo' ):
161
+ cmd .insert (0 , 'sudo' )
162
+
156
163
try :
157
164
subprocess .check_output (cmd )
158
165
self ._log ('{0} cmd executed successfully.' .format (cmd ))
159
- return True
166
+ success = True
160
167
except subprocess .CalledProcessError , error :
161
168
self ._log ('cmd failed with output: {0}' .format (error .output ))
162
- return False
169
+ success = False
170
+ if 'sudo' in cmd :
171
+ subprocess .check_output (['sudo -k' ]) # reset timestamp
172
+
173
+ return success
163
174
164
175
def _set_loop_dev (self ):
165
176
"""Set an unused loop device that's available for use."""
@@ -171,7 +182,7 @@ def _set_loop_dev(self):
171
182
def _losetup (self , bin_path ):
172
183
"""Setup Chrome OS loop device."""
173
184
cmd = ['losetup' , self ._loop_dev , bin_path , '-o' , self ._parse_chromeos_offset (bin_path )]
174
- success = self ._run_cmd (cmd )
185
+ success = self ._run_cmd (cmd , sudo = True , ask = True )
175
186
if success :
176
187
self ._attached_loop_dev = True
177
188
return True
@@ -180,15 +191,8 @@ def _losetup(self, bin_path):
180
191
181
192
def _mnt_loop_dev (self ):
182
193
"""Mount loop device to self._mnt_path()"""
183
- dialog = xbmcgui .Dialog ()
184
194
cmd = ['mount' , '-t' , 'ext2' , self ._loop_dev , '-o' , 'ro' , self ._mnt_path ()]
185
- if os .getuid () != 0 and self ._cmd_exists ('sudo' ): # ask for permission to wrap cmd in sudo
186
- if dialog .yesno (self ._language (30001 ), self ._language (30030 ), yeslabel = self ._language (30029 ), nolabel = self ._language (30028 )):
187
- cmd .insert (0 , 'sudo' )
188
- else :
189
- self ._log ('User refused to give sudo permission.' )
190
-
191
- success = self ._run_cmd (cmd )
195
+ success = self ._run_cmd (cmd , sudo = True , ask = False )
192
196
if success :
193
197
self ._mounted = True
194
198
return True
@@ -495,14 +499,12 @@ def _cleanup(self):
495
499
"""Clean up after Widevine DRM installation."""
496
500
if self ._mounted :
497
501
cmd = ['umount' , self ._mnt_path ()]
498
- if os .getuid () != 0 and self ._cmd_exists ('sudo' ): # no need to ask for permission again
499
- cmd .insert (0 , 'sudo' )
500
- unmount_success = self ._run_cmd (cmd )
502
+ unmount_success = self ._run_cmd (cmd , sudo = True , ask = False )
501
503
if unmount_success :
502
504
self ._mounted = False
503
505
if self ._attached_loop_dev :
504
506
cmd = ['losetup' , '-d' , self ._loop_dev ]
505
- unattach_success = self ._run_cmd (cmd )
507
+ unattach_success = self ._run_cmd (cmd , sudo = True , ask = False )
506
508
if unattach_success :
507
509
self ._loop_dev = False
508
510
0 commit comments