From 04d527c98ac8c1b0d5e82593886ba8ee90afdea8 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 10 Jul 2022 20:51:27 +0200 Subject: [PATCH] Add DisableCurl powershell switch --- docs/guide.md | 31 ++++++++++++++++++++++++- scripts/bootstrap/bootstrap-haskell.ps1 | 19 +++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/docs/guide.md b/docs/guide.md index 0b15fa5..c855a3e 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -310,7 +310,7 @@ gpg-setting: GPGLax # GPGStrict | GPGLax | GPGNone In `GPGStrict` mode, ghcup will fail if verification fails. In `GPGLax` mode it will just print a warning. You can also pass the mode via `ghcup --gpg `. - + # Tips and tricks ## ghcup run @@ -324,3 +324,32 @@ ghcup run --ghc 8.10.7 --cabal latest --hls latest --stack latest --install -- c ``` This will execute vscode with GHC set to 8.10.7 and all other tools to their latest version. + +# Troubleshooting + +## The script immediately exits on windows + +There are two possible reasons: + +1. your company blocks the script (some have a whitelist)... ask your administrator +2. your Antivirus or Windows Defender interfere with the installation. Disable them temporarily. + +## Darwin "C compiler cannot create executables" + +You need to update your XCode command line tools, e.g. [like this](https://stackoverflow.com/questions/34617452/how-to-update-xcode-from-command-line). + +## I get certificate authority errors (or similar) + +If your certificates are outdated or improperly configured, curl may be unable +to download ghcup. + +There are two known workarounds: + +1. Tell curl to ignore certificate errors (dangerous): `curl -k https://gitlab.haskell.org/haskell/ghcup-hs/-/raw/master/scripts/bootstrap/bootstrap-haskell | GHCUP_CURL_OPTS="-k" sh` +2. Try to use wget instead: `wget -O /dev/stdout https://gitlab.haskell.org/haskell/ghcup-hs/-/raw/master/scripts/bootstrap/bootstrap-haskell | BOOTSTRAP_HASKELL_DOWNLOADER=wget sh` + +On windows, you can disable curl like so: + +``` +Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true +``` diff --git a/scripts/bootstrap/bootstrap-haskell.ps1 b/scripts/bootstrap/bootstrap-haskell.ps1 index 8057058..8587789 100644 --- a/scripts/bootstrap/bootstrap-haskell.ps1 +++ b/scripts/bootstrap/bootstrap-haskell.ps1 @@ -36,7 +36,9 @@ param ( # Instead of installing a new MSys2, use an existing installation [string]$ExistingMsys2Dir, # Specify the cabal root directory (default: '$InstallDir\cabal') - [string]$CabalDir + [string]$CabalDir, + # Whether to disable use of curl.exe + [switch]$DisableCurl ) $Silent = !$Interactive @@ -425,7 +427,7 @@ if (!(Test-Path -Path ('{0}' -f $MsysDir))) { $archive = 'msys2-x86_64-latest.sfx.exe' $archivePath = ('{0}\{1}' -f ([IO.Path]::GetTempPath()), "$archive") - if (Get-Command -Name 'curl.exe' -ErrorAction SilentlyContinue) { + if ((Get-Command -Name 'curl.exe' -ErrorAction SilentlyContinue) -and !($DisableCurl)) { Exec "curl.exe" '-o' "$archivePath" ('https://repo.msys2.org/distrib/{0}' -f "$archive") } else { Get-FileWCSynchronous -url ('https://repo.msys2.org/distrib/{0}' -f $archive) -destinationFolder ([IO.Path]::GetTempPath()) -includeStats @@ -591,10 +593,17 @@ if ($Minimal) { $MinimalExport = 'export BOOTSTRAP_HASKELL_MINIMAL=1 ;' } -if ((Get-Process -ID $PID).ProcessName.StartsWith("bootstrap-haskell") -Or $InBash) { - Exec "$Bash" '-lc' ('{4} {6} {7} {8} {9} [ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -m ''{1}'') ; [ -n ''{2}'' ] && export GHCUP_INSTALL_BASE_PREFIX=$(cygpath -m ''{2}/'') ; export PATH=$(cygpath -u ''{3}/bin''):$PATH ; export CABAL_DIR=''{5}'' ; [[ ''{0}'' = https* ]] && curl --proto ''=https'' --tlsv1.2 -sSf {0} | bash || cat $(cygpath -m ''{0}'') | bash' -f $BootstrapUrl, $MsysDir, $GhcupBasePrefix, $GhcupDir, $SilentExport, $CabalDirFull, $StackInstallExport, $HLSInstallExport, $AdjustCabalConfigExport, $MinimalExport) +if ($DisableCurl) { + $BootstrapDownloader = 'export BOOTSTRAP_HASKELL_DOWNLOADER=wget ;' + $DownloadScript = 'wget -O /dev/stdout' } else { - Exec "$Msys2Shell" '-mingw64' '-mintty' '-c' ('{4} {6} {7} {8} {9} [ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -m ''{1}'') ; [ -n ''{2}'' ] && export GHCUP_INSTALL_BASE_PREFIX=$(cygpath -m ''{2}/'') ; export PATH=$(cygpath -u ''{3}/bin''):$PATH ; export CABAL_DIR=''{5}'' ; trap ''echo Press any key to exit && read -n 1 && exit'' 2 ; [[ ''{0}'' = https* ]] && curl --proto ''=https'' --tlsv1.2 -sSf {0} | bash || cat $(cygpath -m ''{0}'') | bash ; echo ''Press any key to exit'' && read -n 1' -f $BootstrapUrl, $MsysDir, $GhcupBasePrefix, $GhcupDir, $SilentExport, $CabalDirFull, $StackInstallExport, $HLSInstallExport, $AdjustCabalConfigExport, $MinimalExport) + $DownloadScript = 'curl --proto ''=https'' --tlsv1.2 -sSf' +} + +if ((Get-Process -ID $PID).ProcessName.StartsWith("bootstrap-haskell") -Or $InBash) { + Exec "$Bash" '-lc' ('{4} {6} {7} {8} {9} {10} [ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -m ''{1}'') ; [ -n ''{2}'' ] && export GHCUP_INSTALL_BASE_PREFIX=$(cygpath -m ''{2}/'') ; export PATH=$(cygpath -u ''{3}/bin''):$PATH ; export CABAL_DIR=''{5}'' ; [[ ''{0}'' = https* ]] && {11} {0} | bash || cat $(cygpath -m ''{0}'') | bash' -f $BootstrapUrl, $MsysDir, $GhcupBasePrefix, $GhcupDir, $SilentExport, $CabalDirFull, $StackInstallExport, $HLSInstallExport, $AdjustCabalConfigExport, $MinimalExport, $BootstrapDownloader, $DownloadScript) +} else { + Exec "$Msys2Shell" '-mingw64' '-mintty' '-c' ('{4} {6} {7} {8} {9} {10} [ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -m ''{1}'') ; [ -n ''{2}'' ] && export GHCUP_INSTALL_BASE_PREFIX=$(cygpath -m ''{2}/'') ; export PATH=$(cygpath -u ''{3}/bin''):$PATH ; export CABAL_DIR=''{5}'' ; trap ''echo Press any key to exit && read -n 1 && exit'' 2 ; [[ ''{0}'' = https* ]] && {11} {0} | bash || cat $(cygpath -m ''{0}'') | bash ; echo ''Press any key to exit'' && read -n 1' -f $BootstrapUrl, $MsysDir, $GhcupBasePrefix, $GhcupDir, $SilentExport, $CabalDirFull, $StackInstallExport, $HLSInstallExport, $AdjustCabalConfigExport, $MinimalExport, $BootstrapDownloader, $DownloadScript) }