MegaBites-AI/Windows-powershell
0372
1#!/bin/bash2# Copyright (c) Microsoft Corporation.3# Licensed under the MIT License.4 5install(){6 #Companion code for the blog https://cloudywindows.com7 8 #call this code direction from the web with:9 #bash <(wget -qO - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>10 #wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh | bash -s <ARGUMENTS>11 #bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>12 13 14 #Usage - if you do not have the ability to run scripts directly from the web,15 # pull all files in this repo folder and execute, this script16 # automatically prefers local copies of sub-scripts17 18 #Completely automated install requires a root account or sudo with a password requirement19 20 #Switches21 # -includeide - installs VSCode and VSCode PowerShell extension (only relevant to machines with desktop environment)22 # -interactivetesting - do a quick launch test of VSCode (only relevant when used with -includeide)23 # -skip-sudo-check - use sudo without verifying its availability (hard to accurately do on some distros)24 # -preview - installs the latest preview release of PowerShell side-by-side with any existing production releases25 26 #gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution27 28 local VERSION="1.2.0"29 # Pin to specific commit for security (OpenSSF Scorecard requirement)30 # Pinned commit: 26bb188c8 - "Improve ValidateLength error message consistency and refactor validation tests" (2025-10-12)31 local gitreposubpath="PowerShell/PowerShell/26bb188c8be0cda6cb548ce1a12840ebf67e1331"32 local gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"33 local gitscriptname="install-powershell.psh"34 35 echo "Get-PowerShell MASTER Installer Version $VERSION"36 echo "Installs PowerShell and Optional The Development Environment"37 echo " Original script is at: $gitreposcriptroot\\$gitscriptname"38 39 echo "Arguments used: $*"40 echo ""41 42 # Let's quit on interrupt of subcommands43 trap '44 trap - INT # restore default INT handler45 echo "Interrupted"46 kill -s INT "$$"47 ' INT48 49 lowercase(){50 echo "$1" | tr "[:upper:]" "[:lower:]"51 }52 53 local OS54 OS=$(lowercase "$(uname)")55 local KERNEL56 KERNEL=$(uname -r)57 local MACH58 MACH=$(uname -m)59 local DIST60 local DistroBasedOn61 local PSUEDONAME62 local REV63 64 if [ "${OS}" == "windowsnt" ]; then65 OS=windows66 DistroBasedOn=windows67 SCRIPTFOLDER=$(dirname "$(readlink -f "$0")")68 elif [ "${OS}" == "darwin" ]; then69 OS=osx70 DistroBasedOn=osx71 # readlink doesn't work the same on macOS72 SCRIPTFOLDER=$(dirname "$0")73 else74 SCRIPTFOLDER=$(dirname "$(readlink -f "$0")")75 OS=$(uname)76 DISTRIBUTOR_ID=$(lsb_release --id 2>/dev/null | sed -E 's/^.*:[[:space:]]*//')77 if [ "${OS}" == "SunOS" ] ; then78 OS=solaris79 ARCH=$(uname -p)80 OSSTR="${OS} ${REV}(${ARCH} $(uname -v))"81 DistroBasedOn=sunos82 elif [ "${OS}" == "AIX" ] ; then83 OSSTR="${OS} $(oslevel) ($(oslevel -r))"84 DistroBasedOn=aix85 elif [ "${OS}" == "Linux" ] ; then86 if [ -f /etc/redhat-release ] ; then87 DistroBasedOn='redhat'88 DIST=$(sed s/\ release.*// < /etc/redhat-release)89 PSUEDONAME=$( (sed s/.*\(// | sed s/\)//) < /etc/redhat-release )90 REV=$( (sed s/.*release\ // | sed s/\ .*//) < /etc/redhat-release )91 elif [ -f /etc/system-release ] ; then92 DIST=$(sed s/\ release.*// < /etc/system-release)93 PSUEDONAME=$( (sed s/.*\(// | sed s/\)//) < /etc/system-release )94 REV=$( (sed s/.*release\ // | sed s/\ .*//) < /etc/system-release )95 if [[ $DIST == *"Amazon Linux"* ]] ; then96 DistroBasedOn='amazonlinux'97 else98 DistroBasedOn='redhat'99 fi100 elif [ -f /etc/mariner-release ] ; then101 DistroBasedOn='mariner'102 PSUEDONAME=$( (sed s/.*\(// | sed s/\)//) < /etc/mariner-release )103 REV=$( (sed s/.*release\ // | sed s/\ .*//) < /etc/mariner-release )104 elif [ -f /etc/mandrake-release ] ; then105 DistroBasedOn='mandrake'106 PSUEDONAME=$( (sed s/.*\(// | sed s/\)//) < /etc/mandrake-release )107 REV=$( (sed s/.*release\ // | sed s/\ .*//) < /etc/mandrake-release )108 elif [ -f /etc/azurelinux-release ] ; then109 DistroBasedOn='mariner'110 PSUEDONAME=$( (sed s/.*\(// | sed s/\)//) < /etc/azurelinux-release )111 REV=$( (sed s/.*release\ // | sed s/\ .*//) < /etc/azurelinux-release )112 elif [ -f /etc/debian_version ] ; then113 DistroBasedOn='debian'114 DIST=$(. /etc/os-release && echo $NAME)115 PSUEDONAME=$(. /etc/os-release && echo $VERSION_CODENAME)116 REV=$(. /etc/os-release && echo $VERSION_ID)117 elif [ "$DISTRIBUTOR_ID" = Gentoo ] ; then118 DistroBasedOn='gentoo'119 DIST=$(. /etc/os-release && echo $NAME)120 PSUEDONAME=$(eselect --brief profile show | sed -E 's/[[:space:]]*//g')121 REV=$( eselect --brief profile show | sed -E 's|^.*/([[:digit:].]+).*|\1|')122 fi123 if [ -f /etc/UnitedLinux-release ] ; then124 DIST="${DIST}[$( (tr "\n" ' ' | sed s/VERSION.*//) < /etc/UnitedLinux-release )]"125 fi126 osname=$(source /etc/os-release; echo $PRETTY_NAME)127 if [[ $osname = *SUSE* ]]; then128 DistroBasedOn='suse'129 REV=$(source /etc/os-release; echo $VERSION_ID)130 fi131 OS=$(lowercase $OS)132 DistroBasedOn=$(lowercase $DistroBasedOn)133 fi134 fi135 136 echo "Operating System Details:"137 echo " OS: $OS"138 echo " DIST: $DIST"139 echo " DistroBasedOn: $DistroBasedOn"140 echo " PSUEDONAME: $PSUEDONAME"141 echo " REV: $REV"142 echo " KERNEL: $KERNEL"143 echo " MACH: $MACH"144 echo " OSSTR: $OSSTR"145 146 147 case "$DistroBasedOn" in148 redhat|debian|osx|suse|amazonlinux|gentoo|mariner)149 echo "Configuring PowerShell Environment for: $DistroBasedOn $DIST $REV"150 if [ -f "$SCRIPTFOLDER/installpsh-$DistroBasedOn.sh" ]; then151 #Script files were copied local - use them152 # shellcheck source=/dev/null153 . "$SCRIPTFOLDER/installpsh-$DistroBasedOn.sh"154 else155 #Script files are not local - pull from remote156 echo "Could not find \"installpsh-$DistroBasedOn.sh\" next to this script..."157 echo "Pulling and executing it from \"$gitreposcriptroot/installpsh-$DistroBasedOn.sh\""158 if [ -n "$(command -v curl)" ]; then159 echo "found and using curl"160 bash <(curl -s $gitreposcriptroot/installpsh-"$DistroBasedOn".sh) "$@"161 elif [ -n "$(command -v wget)" ]; then162 echo "found and using wget"163 bash <(wget -qO- $gitreposcriptroot/installpsh-"$DistroBasedOn".sh) "$@"164 else165 echo "Could not find curl or wget, install one of these or manually download \"$gitreposcriptroot/installpsh-$DistroBasedOn.sh\""166 fi167 fi168 ;;169 *)170 echo "Sorry, your operating system is based on $DistroBasedOn and is not supported by PowerShell or this installer at this time."171 exit 1172 ;;173 esac174}175 176# run the install function177install "$@";178 