|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Install PowerShell from the official Linux x64 tarball (CI + Dev Containers). |
| 3 | +# Usage: install-pwsh-linux.sh [version] |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +pwsh_version="${1:-7.4.7}" |
| 7 | +install_root="/opt/microsoft/powershell/$(echo "${pwsh_version}" | cut -d. -f1,2)" |
| 8 | +tarball="powershell-${pwsh_version}-linux-x64.tar.gz" |
| 9 | +download_url="https://github.com/PowerShell/PowerShell/releases/download/v${pwsh_version}/${tarball}" |
| 10 | + |
| 11 | +install_deps_arch() { |
| 12 | + pacman -Syu --noconfirm |
| 13 | + pacman -S --noconfirm \ |
| 14 | + git \ |
| 15 | + icu \ |
| 16 | + openssl \ |
| 17 | + curl \ |
| 18 | + ca-certificates \ |
| 19 | + tar \ |
| 20 | + gzip \ |
| 21 | + which \ |
| 22 | + less \ |
| 23 | + sudo \ |
| 24 | + base-devel |
| 25 | +} |
| 26 | + |
| 27 | +install_deps_debian() { |
| 28 | + export DEBIAN_FRONTEND=noninteractive |
| 29 | + apt-get update |
| 30 | + apt-get install -y --no-install-recommends \ |
| 31 | + ca-certificates \ |
| 32 | + curl \ |
| 33 | + git \ |
| 34 | + tar \ |
| 35 | + gzip \ |
| 36 | + less \ |
| 37 | + sudo \ |
| 38 | + locales \ |
| 39 | + openssl |
| 40 | + |
| 41 | + # ICU / OpenSSL SONAME packages differ across Ubuntu releases (and t64 transition). |
| 42 | + local icu_pkg ssl_pkg |
| 43 | + icu_pkg="$(apt-cache search --names-only '^libicu[0-9]+t64$|^libicu[0-9]+$' 2>/dev/null | awk '{print $1}' | sort -V | tail -1 || true)" |
| 44 | + if [[ -n "${icu_pkg}" ]]; then |
| 45 | + apt-get install -y --no-install-recommends "${icu_pkg}" |
| 46 | + fi |
| 47 | + for ssl_pkg in libssl3t64 libssl3; do |
| 48 | + if apt-cache show "${ssl_pkg}" >/dev/null 2>&1; then |
| 49 | + apt-get install -y --no-install-recommends "${ssl_pkg}" |
| 50 | + break |
| 51 | + fi |
| 52 | + done |
| 53 | + |
| 54 | + rm -rf /var/lib/apt/lists/* |
| 55 | +} |
| 56 | + |
| 57 | +if [[ -f /etc/arch-release ]]; then |
| 58 | + install_deps_arch |
| 59 | +elif [[ -f /etc/debian_version ]]; then |
| 60 | + install_deps_debian |
| 61 | +else |
| 62 | + echo "Unsupported distro for install-pwsh-linux.sh (need Arch or Debian/Ubuntu)" >&2 |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +mkdir -p "${install_root}" |
| 67 | +curl -fsSL -o "/tmp/${tarball}" "${download_url}" |
| 68 | +tar -xzf "/tmp/${tarball}" -C "${install_root}" |
| 69 | +rm -f "/tmp/${tarball}" |
| 70 | + |
| 71 | +# Tar extract can leave the entrypoint non-executable in some images (exit 126). |
| 72 | +chmod a+x "${install_root}/pwsh" |
| 73 | +find "${install_root}" -type f -name '*.so*' -exec chmod a+x {} + |
| 74 | + |
| 75 | +# Prefer /usr/local/bin so PATH does not resolve through Arch usr-merge /usr/sbin. |
| 76 | +ln -sfn "${install_root}/pwsh" /usr/local/bin/pwsh |
| 77 | +ln -sfn "${install_root}/pwsh" /usr/bin/pwsh |
| 78 | + |
| 79 | +command -v pwsh |
| 80 | +pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' |
0 commit comments