From nobody Thu May 2 10:13:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57699+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57699+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1587440663; cv=none; d=zohomail.com; s=zohoarc; b=DLPweOL1cgYlpVQS7xOMhTZgHkk0Xoy7R8vV1G1qTl7Lgt+HSOlVNk1L1Pl+sX2fIUcI1KJy46aUOHYrbWd41Ag7KbyXPjuYfHwnjCjWQd+TPecGDvhIW057Xlycol/1u4fYP6csjjEeDgYSxBfEbYcZwQldm+AswV/wLr8t9KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587440663; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=8uEf7jtf2zEw1PuBtBPowZu8nR+KX1gIEOf1vR3E314=; b=EbvwQkK+o/ywR14sh1EXULCQsqXQukaRbzqjWuMa4gKmCGjGw/LnsdRfEM/qt80gBsNii4W7HOhiSv5DyMEpGkK2D8viD2eH3oBz9pvtPVD0MoU1hSKk7kp09cuLhvNVGAd4DLhmm+3NkdwEe7tpvnPMaqQWWyx53Hv4BeLEWpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57699+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1587440663766765.6257451645662; Mon, 20 Apr 2020 20:44:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ycIbYY1788612x1zIwXdr2rT; Mon, 20 Apr 2020 20:44:23 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.2552.1587440663039021762 for ; Mon, 20 Apr 2020 20:44:23 -0700 IronPort-SDR: OqF20OZ3Jr/hxjxHyhylCIpEL9+Sfc9vqPv52IxVlLMf0+/rp21a9O4x7UmQiKf953liepMCJI WICkQJc6CNSw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2020 20:44:22 -0700 IronPort-SDR: RNItqRMNQJqzKV2y8oY2I0xh51slXOvrYkvbqAm0cSmZJVBLDUGfTFpxSmPTmgB2fePZAm6HdN 1IQQpfH5uNtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,408,1580803200"; d="scan'208";a="255152656" X-Received: from nldesimo-desk1.amr.corp.intel.com ([10.7.159.63]) by orsmga003.jf.intel.com with ESMTP; 20 Apr 2020 20:44:22 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Ashley E Desimone , Puja Pandya , Erik Bjorge , Bret Barkelew , Prince Agyeman Subject: [edk2-devel] [PATCH] EdkRepo: Fix Linux install failures Date: Mon, 20 Apr 2020 20:44:06 -0700 Message-Id: <20200421034406.6541-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com X-Gm-Message-State: E8njyG3BZcoQ1upnPrWqaMlbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1587440663; bh=h6tN37IOm9+5zdOZhYGSHqx6ZwtbBzLyQ/z1ZunnkAk=; h=Cc:Date:From:Reply-To:Subject:To; b=XdrXG4BtXAwDbnph6mPaSNjNoJOBLRB6/T9cjU1ebLpacOCMHUJqGiQNUkydcAL+76o cVgP+Lr32YgMBtZiRqGvojkaXMGtqszteB7KkFUjiKU740Jt6bMnNWRJHEFyDuhZkPit+ 7/HSn8p2rzdvbTT3ihoBsFw4Vj2i8WuiTNA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Install script currently attempts to run EdkRepo as root, which fails. The fix ensures that EdkRepo is run under a user account. Signed-off-by: Nate DeSimone Cc: Ashley E Desimone Cc: Puja Pandya Cc: Erik Bjorge Cc: Bret Barkelew Cc: Prince Agyeman Reviewed-by: Ashley DeSimone Reviewed-by: Erik Bjorge --- edkrepo_installer/linux-scripts/install.py | 52 ++++++++++++++++------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer= /linux-scripts/install.py index feecf49..f3a9248 100755 --- a/edkrepo_installer/linux-scripts/install.py +++ b/edkrepo_installer/linux-scripts/install.py @@ -102,7 +102,7 @@ def is_prompt_customization_installed(user_home_dir): return customization_installed =20 __add_prompt_customization =3D None -def get_add_prompt_customization(args, user_home_dir): +def get_add_prompt_customization(args, username, user_home_dir): global __add_prompt_customization if __add_prompt_customization is not None: return __add_prompt_customization @@ -118,10 +118,16 @@ def get_add_prompt_customization(args, user_home_dir): return False #If the prompt has not been installed and EdkRepo >=3D 2.0.0 is instal= led, then don't install the prompt customization if shutil.which('edkrepo') is not None: - res =3D default_run(['edkrepo', '--version']) - if _check_version(res.stdout.replace('edkrepo ', '').strip(), '2.0= .0') >=3D 0: - __add_prompt_customization =3D False - return False + try: + if is_current_user_root(): + res =3D subprocess.run("echo 'edkrepo --version; exit' | s= u - {}".format(username), shell=3DTrue, universal_newlines=3DTrue, stdout= =3Dsubprocess.PIPE, stderr=3Dsubprocess.STDOUT, check=3DTrue) + else: + res =3D default_run(['edkrepo', '--version']) + if _check_version(res.stdout.replace('edkrepo ', '').strip(), = '2.0.0') >=3D 0: + __add_prompt_customization =3D False + return False + except: + pass #Show the user an advertisement to see if they want the prompt customi= zation from select import select import termios @@ -251,6 +257,12 @@ def get_site_packages_directory(): res =3D default_run([def_python, '-c', 'import site; print(site.getsit= epackages()[0])']) return res.stdout.strip() =20 +def is_current_user_root(): + res =3D default_run(['id', '-u']) + if res.stdout.strip() =3D=3D '0': + return True + return False + def set_execute_permissions(): site_packages =3D get_site_packages_directory() config =3D configparser.ConfigParser(allow_no_value=3DTrue, delimiters= =3D'=3D') @@ -457,7 +469,7 @@ def add_command_completions_to_shell(command_completion= _script, args, username, comment =3D '\n# Add EdkRepo command completions' bash_rc_file =3D os.path.join(user_home_dir, '.bashrc') add_command_comment_to_startup_script(bash_rc_file, regex, new_source_= line, comment, username) - if get_add_prompt_customization(args, user_home_dir): + if get_add_prompt_customization(args, username, user_home_dir): add_command_to_startup_script(bash_rc_file, prompt_regex, bash_pro= mpt_customization, username) zsh_rc_file =3D os.path.join(user_home_dir, '.zshrc') add_command_to_startup_script(zsh_rc_file, zsh_autoload_compinit_regex= , zsh_autoload_compinit, username) @@ -467,7 +479,7 @@ def add_command_completions_to_shell(command_completion= _script, args, username, add_command_to_startup_script(zsh_rc_file, zsh_compinit_regex, zsh_com= pinit, username) add_command_to_startup_script(zsh_rc_file, zsh_bashcompinit_regex, zsh= _bashcompinit, username) add_command_comment_to_startup_script(zsh_rc_file, regex, new_source_l= ine, comment, username) - if get_add_prompt_customization(args, user_home_dir): + if get_add_prompt_customization(args, username, user_home_dir): add_command_to_startup_script(zsh_rc_file, prompt_regex, zsh_promp= t_customization, username) =20 def do_install(): @@ -515,11 +527,11 @@ def do_install(): log.info('\nCollecting system information:') if not install_to_local and ostype !=3D MAC: try: - res =3D default_run(['id', '-u']) + user_is_root =3D is_current_user_root() except: log.info('- Failed to determine user ID') return 1 - if res.stdout.strip() !=3D '0': + if not user_is_root: log.info('- Installer must be run as root') return 1 if username is None: @@ -536,17 +548,17 @@ def do_install(): return 1 if ostype =3D=3D MAC: try: - res =3D default_run(['id', '-u']) + user_is_root =3D is_current_user_root() except: log.info('- Failed to determine user ID') return 1 - if res.stdout.strip() =3D=3D '0': + if user_is_root: log.info('- Installer must NOT be run as root') return 1 if os.path.commonprefix([user_home_dir, sys.executable]) !=3D user= _home_dir: install_to_local =3D True default_cfg_dir =3D os.path.join(user_home_dir, cfg_dir) - get_add_prompt_customization(args, user_home_dir) + get_add_prompt_customization(args, username, user_home_dir) log.info('+ System information collected') =20 # Display current system information. @@ -728,7 +740,21 @@ def do_install(): else: command_completion_script =3D os.path.join('/', 'etc', 'profil= e.d', 'edkrepo_completions.sh') try: - res =3D default_run(['edkrepo', 'generate-command-completion-s= cript', command_completion_script]) + user_is_root =3D False + try: + user_is_root =3D is_current_user_root() + except: + pass + current_home =3D None + if 'HOME' in os.environ: + current_home =3D os.environ['HOME'] + try: + if user_is_root and current_home is not None and current_h= ome !=3D user_home_dir: + os.environ['HOME'] =3D user_home_dir + res =3D default_run(['edkrepo', 'generate-command-completi= on-script', command_completion_script]) + finally: + if current_home is not None and os.environ['HOME'] !=3D cu= rrent_home: + os.environ['HOME'] =3D current_home if install_to_local or ostype =3D=3D MAC: shutil.chown(command_completion_script, user=3Dusername) os.chmod(command_completion_script, 0o644) --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#57699): https://edk2.groups.io/g/devel/message/57699 Mute This Topic: https://groups.io/mt/73165751/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-