From d45bc20ff6cdc752ee4b40603c351109a8ee0100 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sat, 6 Apr 2019 20:22:57 +1300 Subject: [PATCH] add sudo password. Fixes #1588 --- autoProcessMedia.cfg.spec | 2 ++ core/__init__.py | 3 +++ core/transcoder.py | 28 ++++++++++++++++++++-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 6829d6b2f..d8e1a5a69 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -32,6 +32,8 @@ safe_mode = 1 # Turn this on to disable additional extraction attempts for failed downloads. Default = 0 will attempt to extract and verify if media is present. no_extract_failed = 0 + # Set the sudo password for any functions that require root permissions (e.g. mounting .iso images for transcoding) + sudo_password = [Posix] ### Process priority setting for External commands (Extractor and Transcoder) on Posix (Unix/Linux/OSX) systems. diff --git a/core/__init__.py b/core/__init__.py index d9cad1fd0..4cd4014c6 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -127,6 +127,7 @@ LOG_GIT = None SYS_ENCODING = None FAILED = False +SUDO_PASS = None AUTO_UPDATE = None NZBTOMEDIA_VERSION = __version__ @@ -365,6 +366,7 @@ def configure_general(): global CHECK_MEDIA global SAFE_MODE global NOEXTRACTFAILED + global SUDO_PASS # Set Version and GIT variables VERSION_NOTIFY = int(CFG['General']['version_notify']) @@ -378,6 +380,7 @@ def configure_general(): CHECK_MEDIA = int(CFG['General']['check_media']) SAFE_MODE = int(CFG['General']['safe_mode']) NOEXTRACTFAILED = int(CFG['General']['no_extract_failed']) + SUDO_PASS = CFG['General']['sudo_password'] def configure_updates(): diff --git a/core/transcoder.py b/core/transcoder.py index dee303f78..932f907f0 100644 --- a/core/transcoder.py +++ b/core/transcoder.py @@ -678,10 +678,16 @@ def mount_iso(item, new_dir, bitbucket): #Currently only supports Linux Mount wh return [] mount_point = os.path.join(os.path.dirname(os.path.abspath(item)),'temp') make_dir(mount_point) - cmd = ['mount', '-o', 'loop', item, mount_point] - print_cmd(cmd) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket) - out, err = proc.communicate() + if core.SUDO_PASS: + cmd = ['sudo', '-S', 'mount', '-o', 'loop', item, mount_point] + print_cmd(cmd) + proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=bitbucket) + out, err = proc.communicate(core.SUDO_PASS + '\n') + else: + cmd = ['mount', '-o', 'loop', item, mount_point] + print_cmd(cmd) + proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=bitbucket) + out, err = proc.communicate() core.MOUNTED = mount_point # Allows us to verify this has been done and then cleanup. for root, dirs, files in os.walk(mount_point): for file in files: @@ -962,11 +968,17 @@ def transcode_directory(dir_name): # this will be 0 (successful) it all are successful, else will return a positive integer for failure. final_result = final_result + result if core.MOUNTED: # In case we mounted an .iso file, unmount here. - cmd = ['umount', '-l', core.MOUNTED] # currently for Linux only. - print_cmd(cmd) time.sleep(5) # play it safe and avoid failing to unmount. - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket) - out, err = proc.communicate() + if core.SUDO_PASS: + cmd = ['sudo', '-S', 'umount', '-l', core.MOUNTED] + print_cmd(cmd) + proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=bitbucket) + out, err = proc.communicate(core.SUDO_PASS + '\n') + else: + cmd = ['umount', '-l', core.MOUNTED] + print_cmd(cmd) + proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=bitbucket) + out, err = proc.communicate() time.sleep(5) os.rmdir(core.MOUNTED) core.MOUNTED = None