From 92100ef14e8fd6c7ef3e1e581aeb7a8f33f9ee82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20M=C3=B6sner?= Date: Wed, 14 Dec 2022 15:18:05 +0100 Subject: [PATCH 1/2] Fix install Scoop --- wingetui/__init__.py | 9 ++++----- wingetui/resources/install_scoop.cmd | 7 +------ wingetui/resources/install_scoop.ps1 | 10 ++++++++++ wingetui/resources/uninstall_scoop.cmd | 7 +++---- wingetui/scoopHelpers.py | 2 ++ 5 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 wingetui/resources/install_scoop.ps1 diff --git a/wingetui/__init__.py b/wingetui/__init__.py index 7c8dd5b22e..499607b9ed 100644 --- a/wingetui/__init__.py +++ b/wingetui/__init__.py @@ -199,7 +199,7 @@ def detectWinget(self): def detectScoop(self): try: self.callInMain.emit(lambda: self.loadingText.setText(_("Locating Scoop..."))) - o = subprocess.run(f"powershell -Command scoop -v", shell=True, stdout=subprocess.PIPE) + o = subprocess.run(f"{scoopHelpers.scoop} -v", shell=True, stdout=subprocess.PIPE) print(o.stdout) print(o.stderr) globals.componentStatus["scoopFound"] = o.returncode == 0 @@ -211,14 +211,13 @@ def detectScoop(self): try: if not getSettings("DisableUpdateIndexes"): self.callInMain.emit(lambda: self.loadingText.setText(_("Clearing Scoop cache..."))) - p = subprocess.Popen(f"powershell -Command scoop cache rm *", shell=True, stdout=subprocess.PIPE) - + p = subprocess.Popen(f"{scoopHelpers.scoop} cache rm *", shell=True, stdout=subprocess.PIPE) p.wait() except Exception as e: print(e) try: if(getSettings("EnableScoopCleanup")): - p2 = subprocess.Popen(f"powershell -Command scoop cleanup --all", shell=True, stdout=subprocess.PIPE) + p2 = subprocess.Popen(f"{scoopHelpers.scoop} cleanup --all", shell=True, stdout=subprocess.PIPE) p2.wait() except Exception as e: report(e) @@ -226,7 +225,7 @@ def detectScoop(self): try: if not getSettings("DisableUpdateIndexes"): self.callInMain.emit(lambda: self.loadingText.setText(_("Updating Scoop sources..."))) - o = subprocess.run(f"powershell -Command scoop update", shell=True, stdout=subprocess.PIPE) + o = subprocess.run(f"{scoopHelpers.scoop} update", shell=True, stdout=subprocess.PIPE) self.callInMain.emit(lambda: self.loadingText.setText(_("Updated Scoop sources"))) except Exception as e: print(e) diff --git a/wingetui/resources/install_scoop.cmd b/wingetui/resources/install_scoop.cmd index 01aa6f2b94..469a8e5057 100644 --- a/wingetui/resources/install_scoop.cmd +++ b/wingetui/resources/install_scoop.cmd @@ -1,10 +1,5 @@ @echo off echo This script will install Scoop and the dependencies required by WingetUI. pause -powershell -NoProfile -Command "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser" -echo Installing scoop... -powershell -NoProfile -Command "iex ""& {$(irm get.scoop.sh)} -RunAsAdmin""" -echo Installing git... -powershell -NoProfile -Command "scoop install git" -echo Done! +powershell -ExecutionPolicy ByPass -File "%~dp0\install_scoop.ps1" pause diff --git a/wingetui/resources/install_scoop.ps1 b/wingetui/resources/install_scoop.ps1 new file mode 100644 index 0000000000..3af34b18a7 --- /dev/null +++ b/wingetui/resources/install_scoop.ps1 @@ -0,0 +1,10 @@ +Write-Output "Installing scoop..." + +Invoke-Expression "& {$(Invoke-RestMethod get.scoop.sh)}" + +If (-Not (Get-Command git -ErrorAction SilentlyContinue)) { + Write-Output "Installing git..." + scoop install git +} + +Write-Output "Done!" diff --git a/wingetui/resources/uninstall_scoop.cmd b/wingetui/resources/uninstall_scoop.cmd index b3489a18fe..c9abc3b9d3 100644 --- a/wingetui/resources/uninstall_scoop.cmd +++ b/wingetui/resources/uninstall_scoop.cmd @@ -2,9 +2,8 @@ echo This script will remove scoop from your machine. echo Removing scoop implies removing all scoop installed packages, buckets and preferences, and might also erase valuable user data related to the affected packages echo|set/p="Press to continue or CLOSE this window to abort this process"&runas/u: "">NUL -echo Installing scoop... -powershell -NoProfile -Command "scoop uninstall -p scoop" -echo Reverting ExecutionPolicy -powershell -NoProfile -Command "Set-ExecutionPolicy Restricted -Scope CurrentUser" +echo. +echo Uninstalling scoop... +powershell -ExecutionPolicy ByPass -Command "scoop uninstall -p scoop" echo Done! pause diff --git a/wingetui/scoopHelpers.py b/wingetui/scoopHelpers.py index 2e7de769c0..7cebd42101 100644 --- a/wingetui/scoopHelpers.py +++ b/wingetui/scoopHelpers.py @@ -6,6 +6,8 @@ ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') +scoop = "powershell -ExecutionPolicy ByPass -Command scoop" + def searchForPackage(signal: Signal, finishSignal: Signal) -> None: print("🟢 Starting scoop search...") p = subprocess.Popen(' '.join(["powershell", "-Command", "scoop", "search"]), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, cwd=os.getcwd(), env=os.environ, shell=True) From db3caee9ea1744fcbcce5f5dfbc5c45ec7657762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Fri, 16 Dec 2022 16:22:48 +0100 Subject: [PATCH 2/2] Update install_scoop.ps1 --- wingetui/resources/install_scoop.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wingetui/resources/install_scoop.ps1 b/wingetui/resources/install_scoop.ps1 index 3af34b18a7..657a9cd343 100644 --- a/wingetui/resources/install_scoop.ps1 +++ b/wingetui/resources/install_scoop.ps1 @@ -1,6 +1,6 @@ Write-Output "Installing scoop..." -Invoke-Expression "& {$(Invoke-RestMethod get.scoop.sh)}" +iex "& {$(irm get.scoop.sh)} -RunAsAdmin" If (-Not (Get-Command git -ErrorAction SilentlyContinue)) { Write-Output "Installing git..."