Skip to content

Commit 53e6ec6

Browse files
DarwinJSTravisEz13
authored andcommitted
install-powershell.sh filter prereleases (when available), params documentation (PowerShell#6849)
Fixed PowerShell#6815 by adding -allowprereleases parameter Fixed PowerShell#6405 by adding -allowprereleases parameter Added parameters to documentation Ready for prerelease repositories if Microsoft starts providing them Added -skip-sudo-check for all distros Fixed -interactivetesting should do nothing if -includeide was not used
1 parent ffca008 commit 53e6ec6

8 files changed

Lines changed: 124 additions & 118 deletions

.spelling

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,3 +1066,8 @@ NTLM
10661066
NumberBytes
10671067
ResponseHeaders
10681068
#endregion
1069+
includeide
1070+
interactivetesting
1071+
allowprerelease
1072+
prereleases
1073+
url

tools/install-powershell-readme.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
* native package manager available
2020
* `curl` (auto-installed if missing)
2121

22+
## Parameters
23+
24+
* -includeide - installs vscode and vscode powershell extension (only relevant to machines with desktop environment)
25+
* -interactivetesting - do a quick launch test of vscode - only relevant when used with -includeide
26+
* -skip-sudo-check - use sudo without verifying it's availability (hard to accurately do on some distros)
27+
* -allowprerelease - includes prereleases of powershell core when selection allows this. Repository based installs take the latest on the repo url regardless of this switch.
28+
2229
## Usage
2330

2431
### Direct from Github
@@ -55,12 +62,6 @@ bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/
5562
bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -includeide -interactivetesting
5663
```
5764

58-
### Install AppImage
59-
60-
```bash
61-
bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -appimage
62-
```
63-
6465
### Installation To do list
6566

66-
* Detect and wait when package manager is busy/locked? - at least Ubuntu (CentOS does this internally)
67+
* Detect and wait when package manager is busy/locked? - at least Ubuntu (CentOS does this internally)

tools/install-powershell.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ install(){
2222

2323
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
2424

25-
local VERSION="1.1.1"
25+
local VERSION="1.2.0"
2626
local gitreposubpath="PowerShell/PowerShell/master"
2727
local gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
2828
local gitscriptname="install-powershell.psh"

tools/installpsh-amazonlinux.sh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
1919

2020

21-
VERSION="1.1.2"
21+
VERSION="1.2.0"
2222
gitreposubpath="PowerShell/PowerShell/master"
2323
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
2424
thisinstallerdistro=amazonlinux
@@ -120,19 +120,20 @@ fi
120120

121121
## Check requirements and prerequisites
122122

123-
#Only do SUDO if we are not root
124-
SUDO=''
125-
if (( $EUID != 0 )); then
126-
SUDO='sudo'
123+
#Check for sudo if not root
124+
if [[ "${CI}" == "true" ]]; then
125+
echo "Running on CI (as determined by env var CI set to true), skipping SUDO check."
126+
set -- "$@" '-skip-sudo-check'
127127
fi
128128

129-
#Check that sudo is available
130-
if [[ "$SUDO" -eq "sudo" ]]; then
131-
132-
$SUDO -v
133-
if [ $? -ne 0 ]; then
134-
echo "ERROR: You must either be root or be able to use sudo" >&2
135-
exit 5
129+
SUDO=''
130+
if (( $EUID != 0 )); then
131+
#Check that sudo is available
132+
if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then
133+
SUDO='sudo'
134+
else
135+
echo "ERROR: You must either be root or be able to use sudo" >&2
136+
#exit 5
136137
fi
137138
fi
138139

@@ -155,7 +156,17 @@ $SUDO yum install -y \
155156

156157
echo
157158
echo "*** Installing PowerShell Core for $DistroBasedOn..."
158-
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`
159+
160+
echo "ATTENTION: As of version 1.2.0 this script no longer uses pre-releases unless the '-allowprereleases' switch is used"
161+
162+
if [[ "'$*'" =~ allowprerelease ]] ; then
163+
echo
164+
echo "-allowprerelease was used, prereleases will be included in the retrieval of the latest version"
165+
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`
166+
else
167+
echo "Finding the latest release production release"
168+
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)
169+
if
159170

160171
#DIRECT DOWNLOAD
161172
pwshlink=/usr/bin/pwsh
@@ -210,7 +221,7 @@ fi
210221

211222
if [[ "'$*'" =~ -interactivetesting ]] ; then
212223
echo
213-
echo "Amazon Linux does not have a desktop manager to support vscode, ignoring -includeide"
224+
echo "Amazon Linux does not have a desktop manager to support vscode, ignoring -interactivetesting"
214225
fi
215226

216227
if [[ "$repobased" == true ]] ; then

tools/installpsh-debian.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
2020

21-
VERSION="1.1.2"
21+
VERSION="1.2.0"
2222
gitreposubpath="PowerShell/PowerShell/master"
2323
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
2424
thisinstallerdistro=debian
@@ -87,19 +87,20 @@ fi
8787

8888
## Check requirements and prerequisites
8989

90-
#Only do SUDO if we are not root
91-
SUDO=''
92-
if (( $EUID != 0 )); then
93-
SUDO='sudo'
90+
#Check for sudo if not root
91+
if [[ "${CI}" == "true" ]]; then
92+
echo "Running on CI (as determined by env var CI set to true), skipping SUDO check."
93+
set -- "$@" '-skip-sudo-check'
9494
fi
9595

96-
#Check that sudo is available
97-
if [[ "$SUDO" == "sudo" && ! ("'$*'" =~ skip-sudo-check) ]]; then
98-
99-
$SUDO -v
100-
if [ $? -ne 0 ]; then
101-
echo "ERROR: You must either be root or be able to use sudo" >&2
102-
exit 5
96+
SUDO=''
97+
if (( $EUID != 0 )); then
98+
#Check that sudo is available
99+
if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then
100+
SUDO='sudo'
101+
else
102+
echo "ERROR: You must either be root or be able to use sudo" >&2
103+
#exit 5
103104
fi
104105
fi
105106

@@ -120,6 +121,12 @@ if ! hash curl 2>/dev/null; then
120121
echo "curl not found, installing..."
121122
$SUDO apt-get install -y curl
122123
fi
124+
125+
if [[ "'$*'" =~ allowprerelease ]] ; then
126+
echo
127+
echo "-allowprerelease was used, but since $DistroBasedOn uses repositories - selection of releases will depend on the repository contents."
128+
fi
129+
123130
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`
124131

125132
echo "*** Current version on git is: $currentversion, repo version may differ slightly..."
@@ -188,12 +195,11 @@ if [[ "'$*'" =~ includeide ]] ; then
188195
echo
189196
echo "*** Installing VS Code PowerShell Extension"
190197
code --install-extension ms-vscode.PowerShell
191-
fi
192-
193-
if [[ "'$*'" =~ -interactivetesting ]] ; then
194-
echo "*** Loading test code in VS Code"
195-
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
196-
code ./testpowershell.ps1
198+
if [[ "'$*'" =~ -interactivetesting ]] ; then
199+
echo "*** Loading test code in VS Code"
200+
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
201+
code ./testpowershell.ps1
202+
fi
197203
fi
198204

199205
if [[ "$repobased" == true ]] ; then

tools/installpsh-osx.sh

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,12 @@ fi
8686

8787
## Check requirements and prerequisites
8888

89-
#Only do SUDO if we are not root
90-
SUDO=''
91-
if (( $EUID != 0 )); then
92-
SUDO='sudo'
93-
fi
94-
95-
#Check that sudo is available
96-
#if [[ "$SUDO" -eq "sudo" ]]; then
97-
# $SUDO -v
98-
# if [ $? -ne 0 ]; then
99-
# echo "ERROR: You must either be root or be able to use sudo" >&2
100-
# exit 5
101-
# fi
102-
#fi
103-
104-
#END Collect any variation details if required for this distro
105-
106-
#If there are known incompatible versions of this distro, put the test, message and script exit here:
107-
108-
#END Verify The Installer Choice
109-
110-
##END Check requirements and prerequisites
111-
11289
echo "*** Installing PowerShell Core for $DistroBasedOn..."
11390

114-
#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`
91+
if [[ "'$*'" =~ allowprerelease ]] ; then
92+
echo
93+
echo "-allowprerelease was used, but since $DistroBasedOn uses repositories - selection of releases will depend on the repository contents."
94+
fi
11595

11696
if ! hash brew 2>/dev/null; then
11797
echo "Homebrew is not found, installing..."
@@ -176,8 +156,14 @@ if [[ "'$*'" =~ includeide ]] ; then
176156

177157
echo "*** Installing VS Code PowerShell Extension"
178158
code --install-extension ms-vscode.PowerShell
159+
if [[ "'$*'" =~ -interactivetesting ]] ; then
160+
echo "*** Loading test code in VS Code"
161+
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
162+
code ./testpowershell.ps1
163+
fi
179164
fi
180165

166+
181167
pwsh -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME.
182168
Run `"pwsh`" to start a PowerShell session."'
183169

@@ -188,12 +174,6 @@ if [[ "$success" != 0 ]]; then
188174
exit "$success"
189175
fi
190176

191-
if [[ "'$*'" =~ -interactivetesting ]] ; then
192-
echo "*** Loading test code in VS Code"
193-
$SUDO curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
194-
code ./testpowershell.ps1
195-
fi
196-
197177
if [[ "$repobased" == true ]] ; then
198178
echo "*** NOTE: Run your regular package manager update cycle to update PowerShell Core"
199179
fi

tools/installpsh-redhat.sh

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
2020

2121

22-
VERSION="1.1.2"
22+
VERSION="1.2.0"
2323
gitreposubpath="PowerShell/PowerShell/master"
2424
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
2525
thisinstallerdistro=redhat
@@ -90,33 +90,29 @@ fi
9090

9191
## Check requirements and prerequisites
9292

93-
#Only do SUDO if we are not root
94-
SUDO=''
95-
if (( $EUID != 0 )); then
96-
SUDO='sudo'
93+
#Check for sudo if not root
94+
if [[ "${CI}" == "true" ]]; then
95+
echo "Running on CI (as determined by env var CI set to true), skipping SUDO check."
96+
set -- "$@" '-skip-sudo-check'
9797
fi
9898

99-
#Check that sudo is available
100-
if [[ "$SUDO" == "sudo" && ! ("'$*'" =~ skip-sudo-check) ]]; then
101-
102-
$SUDO -v
103-
if [ $? -ne 0 ]; then
104-
echo "ERROR: You must either be root or be able to use sudo" >&2
105-
exit 5
99+
SUDO=''
100+
if (( $EUID != 0 )); then
101+
#Check that sudo is available
102+
if [[ ("'$*'" =~ skip-sudo-check) && ("$(whereis sudo)" == *'/'* && "$(sudo -nv 2>&1)" != 'Sorry, user'*) ]]; then
103+
SUDO='sudo'
104+
else
105+
echo "ERROR: You must either be root or be able to use sudo" >&2
106+
#exit 5
106107
fi
107108
fi
108109

109-
#Collect any variation details if required for this distro
110-
111-
#END Collect any variation details if required for this distro
112-
113-
#If there are known incompatible versions of this distro, put the test, message and script exit here:
114-
115-
#END Verify The Installer Choice
116-
117-
##END Check requirements and prerequisites
110+
if [[ "'$*'" =~ allowprerelease ]] ; then
111+
echo
112+
echo "-allowprerelease was used, but since $DistroBasedOn uses repositories - selection of releases will depend on the repository contents."
113+
fi
118114

119-
echo
115+
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
120116
echo "*** Installing PowerShell Core for $DistroBasedOn..."
121117
if ! hash curl 2>/dev/null; then
122118
echo "curl not found, installing..."
@@ -152,12 +148,11 @@ if [[ "'$*'" =~ includeide ]] ; then
152148
echo
153149
echo "*** Installing VS Code PowerShell Extension"
154150
code --install-extension ms-vscode.PowerShell
155-
fi
156-
157-
if [[ "'$*'" =~ -interactivetesting ]] ; then
158-
echo "*** Loading test code in VS Code"
159-
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
160-
code ./testpowershell.ps1
151+
if [[ "'$*'" =~ -interactivetesting ]] ; then
152+
echo "*** Loading test code in VS Code"
153+
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
154+
code ./testpowershell.ps1
155+
fi
161156
fi
162157

163158
if [[ "$repobased" == true ]] ; then

0 commit comments

Comments
 (0)