From 04d527c98ac8c1b0d5e82593886ba8ee90afdea8 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 10 Jul 2022 20:51:27 +0200 Subject: [PATCH 1/3] 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) } From aa71f0dfa12c5d462b2e653a4f6ea3a3ff4be15e Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 10 Jul 2022 21:05:51 +0200 Subject: [PATCH 2/3] Set wget --- scripts/bootstrap/bootstrap-haskell | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/bootstrap/bootstrap-haskell b/scripts/bootstrap/bootstrap-haskell index a4f3c28..c095592 100755 --- a/scripts/bootstrap/bootstrap-haskell +++ b/scripts/bootstrap/bootstrap-haskell @@ -375,6 +375,16 @@ download_ghcup() { # shellcheck disable=SC1090 edo . "${GHCUP_DIR}"/env + case "${BOOTSTRAP_HASKELL_DOWNLOADER}" in + "curl") + ;; + "wget") + eghcup config set downloader Wget + ;; + *) + die "Unknown downloader: ${BOOTSTRAP_HASKELL_DOWNLOADER}" + ;; + esac eghcup upgrade } From 256e1942f241f5c7804f7d76581dc0d6b35f3a87 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 10 Jul 2022 21:17:35 +0200 Subject: [PATCH 3/3] More stuff --- docs/guide.md | 10 ++++++---- docs/index.md | 2 +- scripts/bootstrap/bootstrap-haskell | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/guide.md b/docs/guide.md index c855a3e..b78e0d4 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -327,18 +327,20 @@ This will execute vscode with GHC set to 8.10.7 and all other tools to their lat # Troubleshooting -## The script immediately exits on windows +## 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" +## C compiler cannot create executables + +### Darwin 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) +## Certificate authority errors (curl) If your certificates are outdated or improperly configured, curl may be unable to download ghcup. @@ -350,6 +352,6 @@ There are two known workarounds: On windows, you can disable curl like so: -``` +```pwsh 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/docs/index.md b/docs/index.md index 2773b55..b78a438 100644 --- a/docs/index.md +++ b/docs/index.md @@ -57,7 +57,7 @@ hide:

- Need help? Ask on + Need help? Check the Troubleshooting section or ask on diff --git a/scripts/bootstrap/bootstrap-haskell b/scripts/bootstrap/bootstrap-haskell index c095592..bdbb826 100755 --- a/scripts/bootstrap/bootstrap-haskell +++ b/scripts/bootstrap/bootstrap-haskell @@ -326,9 +326,11 @@ download_ghcup() { MSYS*|MINGW*) case "${BOOTSTRAP_HASKELL_DOWNLOADER}" in "curl") + # shellcheck disable=SC2086 edo curl -Lf ${GHCUP_CURL_OPTS} "${_url}" > "${GHCUP_BIN}"/ghcup.exe ;; "wget") + # shellcheck disable=SC2086 edo wget -O /dev/stdout ${GHCUP_WGET_OPTS} "${_url}" > "${GHCUP_BIN}"/ghcup.exe ;; *) @@ -340,9 +342,11 @@ download_ghcup() { *) case "${BOOTSTRAP_HASKELL_DOWNLOADER}" in "curl") + # shellcheck disable=SC2086 edo curl -Lf ${GHCUP_CURL_OPTS} "${_url}" > "${GHCUP_BIN}"/ghcup ;; "wget") + # shellcheck disable=SC2086 edo wget -O /dev/stdout ${GHCUP_WGET_OPTS} "${_url}" > "${GHCUP_BIN}"/ghcup ;; *) @@ -377,6 +381,7 @@ download_ghcup() { edo . "${GHCUP_DIR}"/env case "${BOOTSTRAP_HASKELL_DOWNLOADER}" in "curl") + eghcup config set downloader Curl ;; "wget") eghcup config set downloader Wget