diff --git a/.spelling b/.spelling index ee4262fbdd5..4df10c3fb88 100644 --- a/.spelling +++ b/.spelling @@ -1115,3 +1115,8 @@ NTLM NumberBytes ResponseHeaders #endregion +includeide +interactivetesting +allowprerelease +prereleases +url diff --git a/tools/install-powershell-readme.md b/tools/install-powershell-readme.md index 08c7bddfdac..73109c151f1 100644 --- a/tools/install-powershell-readme.md +++ b/tools/install-powershell-readme.md @@ -19,6 +19,13 @@ * native package manager available * `curl` (auto-installed if missing) +## Parameters + +* -includeide - installs vscode and vscode powershell extension (only relevant to machines with desktop environment) +* -interactivetesting - do a quick launch test of vscode - only relevant when used with -includeide +* -skip-sudo-check - use sudo without verifying it's availability (hard to accurately do on some distros) +* -allowprerelease - includes prereleases of powershell core when selection allows this. Repository based installs take the latest on the repo url regardless of this switch. + ## Usage ### Direct from Github @@ -55,12 +62,6 @@ bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/ bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -includeide -interactivetesting ``` -### Install AppImage - -```bash -bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -appimage -``` - ### Installation To do list -* Detect and wait when package manager is busy/locked? - at least Ubuntu (CentOS does this internally) \ No newline at end of file +* Detect and wait when package manager is busy/locked? - at least Ubuntu (CentOS does this internally) diff --git a/tools/install-powershell.sh b/tools/install-powershell.sh index 26114ee5f65..2e6991417c4 100755 --- a/tools/install-powershell.sh +++ b/tools/install-powershell.sh @@ -22,7 +22,7 @@ install(){ #gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution - local VERSION="1.1.1" + local VERSION="1.2.0" local gitreposubpath="PowerShell/PowerShell/master" local gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools" local gitscriptname="install-powershell.psh" diff --git a/tools/installpsh-amazonlinux.sh b/tools/installpsh-amazonlinux.sh index aa7066643fd..8aa3d69b2a9 100644 --- a/tools/installpsh-amazonlinux.sh +++ b/tools/installpsh-amazonlinux.sh @@ -18,7 +18,7 @@ #gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution -VERSION="1.1.2" +VERSION="1.2.0" gitreposubpath="PowerShell/PowerShell/master" gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools" thisinstallerdistro=amazonlinux @@ -120,19 +120,20 @@ fi ## Check requirements and prerequisites -#Only do SUDO if we are not root -SUDO='' -if (( $EUID != 0 )); then - SUDO='sudo' +#Check for sudo if not root +if [[ "${CI}" == "true" ]]; then + echo "Running on CI (as determined by env var CI set to true), skipping SUDO check." + set -- "$@" '-skip-sudo-check' fi -#Check that sudo is available -if [[ "$SUDO" -eq "sudo" ]]; then - - $SUDO -v - if [ $? -ne 0 ]; then - echo "ERROR: You must either be root or be able to use sudo" >&2 - exit 5 +SUDO='' +if (( $EUID != 0 )); then + #Check that sudo is available + if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then + SUDO='sudo' + else + echo "ERROR: You must either be root or be able to use sudo" >&2 + #exit 5 fi fi @@ -155,7 +156,17 @@ $SUDO yum install -y \ echo echo "*** Installing PowerShell Core for $DistroBasedOn..." -release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g` + +echo "ATTENTION: As of version 1.2.0 this script no longer uses pre-releases unless the '-allowprereleases' switch is used" + +if [[ "'$*'" =~ allowprerelease ]] ; then + echo + echo "-allowprerelease was used, prereleases will be included in the retrieval of the latest version" + release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g` +else + echo "Finding the latest release production release" + release=$(curl https://api.github.com/repos/PowerShell/PowerShell/releases | grep -Po '"tag_name":(\d*?,|.*?[^\\]",)' | grep -Po '\d+.\d+.\d+[\da-z.-]*' | grep -v '[a-z]' | sort | tail -n1) +if #DIRECT DOWNLOAD pwshlink=/usr/bin/pwsh @@ -210,7 +221,7 @@ fi if [[ "'$*'" =~ -interactivetesting ]] ; then echo - echo "Amazon Linux does not have a desktop manager to support vscode, ignoring -includeide" + echo "Amazon Linux does not have a desktop manager to support vscode, ignoring -interactivetesting" fi if [[ "$repobased" == true ]] ; then diff --git a/tools/installpsh-debian.sh b/tools/installpsh-debian.sh index 857bb9f64d9..b763e45b0d8 100755 --- a/tools/installpsh-debian.sh +++ b/tools/installpsh-debian.sh @@ -18,7 +18,7 @@ #gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution -VERSION="1.1.2" +VERSION="1.2.0" gitreposubpath="PowerShell/PowerShell/master" gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools" thisinstallerdistro=debian @@ -87,19 +87,20 @@ fi ## Check requirements and prerequisites -#Only do SUDO if we are not root -SUDO='' -if (( $EUID != 0 )); then - SUDO='sudo' +#Check for sudo if not root +if [[ "${CI}" == "true" ]]; then + echo "Running on CI (as determined by env var CI set to true), skipping SUDO check." + set -- "$@" '-skip-sudo-check' fi -#Check that sudo is available -if [[ "$SUDO" == "sudo" && ! ("'$*'" =~ skip-sudo-check) ]]; then - - $SUDO -v - if [ $? -ne 0 ]; then - echo "ERROR: You must either be root or be able to use sudo" >&2 - exit 5 +SUDO='' +if (( $EUID != 0 )); then + #Check that sudo is available + if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then + SUDO='sudo' + else + echo "ERROR: You must either be root or be able to use sudo" >&2 + #exit 5 fi fi @@ -120,6 +121,12 @@ if ! hash curl 2>/dev/null; then echo "curl not found, installing..." $SUDO apt-get install -y curl fi + +if [[ "'$*'" =~ allowprerelease ]] ; then + echo + echo "-allowprerelease was used, but since $DistroBasedOn uses repositories - selection of releases will depend on the repository contents." +fi + release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g` echo "*** Current version on git is: $currentversion, repo version may differ slightly..." @@ -188,12 +195,11 @@ if [[ "'$*'" =~ includeide ]] ; then echo echo "*** Installing VS Code PowerShell Extension" code --install-extension ms-vscode.PowerShell -fi - -if [[ "'$*'" =~ -interactivetesting ]] ; then - echo "*** Loading test code in VS Code" - curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 - code ./testpowershell.ps1 + if [[ "'$*'" =~ -interactivetesting ]] ; then + echo "*** Loading test code in VS Code" + curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 + code ./testpowershell.ps1 + fi fi if [[ "$repobased" == true ]] ; then diff --git a/tools/installpsh-osx.sh b/tools/installpsh-osx.sh index 9bdc6035d5e..88f20086082 100755 --- a/tools/installpsh-osx.sh +++ b/tools/installpsh-osx.sh @@ -86,32 +86,12 @@ fi ## Check requirements and prerequisites -#Only do SUDO if we are not root -SUDO='' -if (( $EUID != 0 )); then - SUDO='sudo' -fi - -#Check that sudo is available -#if [[ "$SUDO" -eq "sudo" ]]; then -# $SUDO -v -# if [ $? -ne 0 ]; then -# echo "ERROR: You must either be root or be able to use sudo" >&2 -# exit 5 -# fi -#fi - -#END Collect any variation details if required for this distro - -#If there are known incompatible versions of this distro, put the test, message and script exit here: - -#END Verify The Installer Choice - -##END Check requirements and prerequisites - echo "*** Installing PowerShell Core for $DistroBasedOn..." -#release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g` +if [[ "'$*'" =~ allowprerelease ]] ; then + echo + echo "-allowprerelease was used, but since $DistroBasedOn uses repositories - selection of releases will depend on the repository contents." +fi if ! hash brew 2>/dev/null; then echo "Homebrew is not found, installing..." @@ -176,8 +156,14 @@ if [[ "'$*'" =~ includeide ]] ; then echo "*** Installing VS Code PowerShell Extension" code --install-extension ms-vscode.PowerShell + if [[ "'$*'" =~ -interactivetesting ]] ; then + echo "*** Loading test code in VS Code" + curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 + code ./testpowershell.ps1 + fi fi + pwsh -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME. Run `"pwsh`" to start a PowerShell session."' @@ -188,12 +174,6 @@ if [[ "$success" != 0 ]]; then exit "$success" fi -if [[ "'$*'" =~ -interactivetesting ]] ; then - echo "*** Loading test code in VS Code" - $SUDO curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 - code ./testpowershell.ps1 -fi - if [[ "$repobased" == true ]] ; then echo "*** NOTE: Run your regular package manager update cycle to update PowerShell Core" fi diff --git a/tools/installpsh-redhat.sh b/tools/installpsh-redhat.sh index e581593a2c3..6449ffab639 100755 --- a/tools/installpsh-redhat.sh +++ b/tools/installpsh-redhat.sh @@ -19,7 +19,7 @@ #gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution -VERSION="1.1.2" +VERSION="1.2.0" gitreposubpath="PowerShell/PowerShell/master" gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools" thisinstallerdistro=redhat @@ -90,33 +90,29 @@ fi ## Check requirements and prerequisites -#Only do SUDO if we are not root -SUDO='' -if (( $EUID != 0 )); then - SUDO='sudo' +#Check for sudo if not root +if [[ "${CI}" == "true" ]]; then + echo "Running on CI (as determined by env var CI set to true), skipping SUDO check." + set -- "$@" '-skip-sudo-check' fi -#Check that sudo is available -if [[ "$SUDO" == "sudo" && ! ("'$*'" =~ skip-sudo-check) ]]; then - - $SUDO -v - if [ $? -ne 0 ]; then - echo "ERROR: You must either be root or be able to use sudo" >&2 - exit 5 +SUDO='' +if (( $EUID != 0 )); then + #Check that sudo is available + if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then + SUDO='sudo' + else + echo "ERROR: You must either be root or be able to use sudo" >&2 + #exit 5 fi fi -#Collect any variation details if required for this distro - -#END Collect any variation details if required for this distro - -#If there are known incompatible versions of this distro, put the test, message and script exit here: - -#END Verify The Installer Choice - -##END Check requirements and prerequisites +if [[ "'$*'" =~ allowprerelease ]] ; then + echo + echo "-allowprerelease was used, but since $DistroBasedOn uses repositories - selection of releases will depend on the repository contents." +fi -echo +release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g`echo echo "*** Installing PowerShell Core for $DistroBasedOn..." if ! hash curl 2>/dev/null; then echo "curl not found, installing..." @@ -152,12 +148,11 @@ if [[ "'$*'" =~ includeide ]] ; then echo echo "*** Installing VS Code PowerShell Extension" code --install-extension ms-vscode.PowerShell -fi - -if [[ "'$*'" =~ -interactivetesting ]] ; then - echo "*** Loading test code in VS Code" - curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 - code ./testpowershell.ps1 + if [[ "'$*'" =~ -interactivetesting ]] ; then + echo "*** Loading test code in VS Code" + curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 + code ./testpowershell.ps1 + fi fi if [[ "$repobased" == true ]] ; then diff --git a/tools/installpsh-suse.sh b/tools/installpsh-suse.sh index b5bf82c9d33..0867cb6afc0 100755 --- a/tools/installpsh-suse.sh +++ b/tools/installpsh-suse.sh @@ -19,7 +19,7 @@ #gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution -VERSION="1.1.2" +VERSION="1.2.0" gitreposubpath="PowerShell/PowerShell/master" gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools" thisinstallerdistro=suse @@ -88,19 +88,20 @@ fi ## Check requirements and prerequisites -#Only do SUDO if we are not root -SUDO='' -if (( $EUID != 0 )); then - SUDO='sudo' +#Check for sudo if not root +if [[ "${CI}" == "true" ]]; then + echo "Running on CI (as determined by env var CI set to true), skipping SUDO check." + set -- "$@" '-skip-sudo-check' fi -#Check that sudo is available -if [[ "$SUDO" == "sudo" && ! ("'$*'" =~ skip-sudo-check) ]]; then - - $SUDO -v - if [ $? -ne 0 ]; then - echo "ERROR: You must either be root or be able to use sudo" >&2 - exit 5 +SUDO='' +if (( $EUID != 0 )); then + #Check that sudo is available + if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then + SUDO='sudo' + else + echo "ERROR: You must either be root or be able to use sudo" >&2 + #exit 5 fi fi @@ -137,8 +138,17 @@ $SUDO zypper --non-interactive install \ echo echo "*** Installing PowerShell Core for $DistroBasedOn..." -release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g` +echo "ATTENTION: As of version 1.2.0 this script no longer uses pre-releases unless the '-allowprereleases' switch is used" + +if [[ "'$*'" =~ allowprerelease ]] ; then + echo + echo "-allowprerelease was used, prereleases will be included in the retrieval of the latest version" + release=`curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v// | sed s/,//g | sed s/\ //g` +else + echo "Finding the latest release production release" + release=$(curl https://api.github.com/repos/PowerShell/PowerShell/releases | grep -Po '"tag_name":(\d*?,|.*?[^\\]",)' | grep -Po '\d+.\d+.\d+[\da-z.-]*' | grep -v '[a-z]' | sort | tail -n1) +if #REPO BASED (Not ready yet) #echo "*** Setting up PowerShell Core repo..." #echo "*** Current version on git is: $release, repo version may differ slightly..." @@ -208,13 +218,11 @@ if [[ "'$*'" =~ includeide ]] ; then echo echo "*** Installing VS Code PowerShell Extension" code --install-extension ms-vscode.PowerShell -fi - - -if [[ "'$*'" =~ -interactivetesting ]] ; then - echo "*** Loading test code in VS Code" - curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 - code ./testpowershell.ps1 + if [[ "'$*'" =~ -interactivetesting ]] ; then + echo "*** Loading test code in VS Code" + curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1 + code ./testpowershell.ps1 + fi fi if [[ "$repobased" == true ]] ; then