8000 create script to install latest powershell from repositories by DarwinJS · Pull Request #3608 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

create script to install latest powershell from repositories #3608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,10 @@ WebRequest
win7-x86
WindowsVersion
XPath
alpha.18
behavioral
MiaRomero
TheFlyingCorpse
Youtube
- test/tools/CodeCoverageAutomation/README.md
CodeCoverage.zip
Expand All @@ -914,3 +918,6 @@ post-6
- CODE_OF_CONDUCT.md
opencode
microsoft.com
- ./tools/install-powershell.readme.md
includeide
sed
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ addons:

install:
- pushd tools
- ./download.sh
- ./install-powershell.sh
- popd
# Default 2.0.0 Ruby is buggy
# Default bundler version is buggy
Expand Down
1 change: 1 addition & 0 deletions test/common/markdown/markdown.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Describe 'Common Tests - Validate Markdown Files' -Tag 'CI' {
'./docs/maintainers/README.md'
'./demos/SSHRemoting/*.md'
'./docker/*.md'
'./tools/*.md'
)
$filter = ($docsToTest -join ',')
&"gulp" test-mdsyntax --silent `
Expand Down
66 changes: 66 additions & 0 deletions tools/install-powershell-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# install-powershell.sh

## Features of install-powershell.sh

* can be called directly from git
* optionally installs vs code and vs powershell extension (aka PowerShell IDE) using optional `-includeide` switch
* defaults to completely automated operation (if appropriate permissions are available)
* automatically looks up latest version via git tags
* automatic selection of appropriate install sub-script
* configures software installs for repositories when repositories are in place, otherwise pulls files from git releases. As repository versions are made available, script will be updated to take advantage.
* user permission checking
* sub-installers called from local file system if they exist, otherwise pulled from git
* sub-installers can be called directly if auto-selection is not needed

## Minimum Requirements for install-powershell.sh

* bash shell
* `sed`
* native package manager available
* `curl` (auto-installed if missing)

## Usage

### Direct from Github

```bash
bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>

wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh | bash -s <ARGUMENTS>
```

### Local Copy

```bash
bash install-powershell.sh <ARGUMENTS>
```

## Examples

### Only Install PowerShell Core

```bash
bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh)
```

### Install PowerShell Core with IDE

```bash
bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -includeide
```

### Install PowerShell Core with IDE and do tests that require a human to interact with the installation process

```bash
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)
141 changes: 141 additions & 0 deletions tools/install-powershell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

#Companion code for the blog https://cloudywindows.com

#call this code direction from the web with:
#bash <(wget -O - https://raw.githubu 10000 sercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
#wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh | bash -s <ARGUMENTS>
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>


#Usage - if you do not have the ability to run scripts directly from the web,
# pull all files in this repo folder and execute, this script
# automatically prefers local copies of sub-scripts

#Completely automated install requires a root account or sudo with a password requirement

#Switches
# -includeide - the script is being run headless, do not perform actions that require response from the console
# -interactivetesting - requires a human user in front of the machine - loads a script into the ide to test with F5 to ensure the IDE can run scripts
# -appimage - does appimage instead of native install

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

VERSION="1.1.0"
gitreposubpath="PowerShell/PowerShell/master"
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
gitscriptname="install-powershell.psh"

echo "Get-PowerShell Core MASTER Installer Version $VERSION"
echo "Installs PowerShell Core and Optional The Development Environment"
echo " Original script is at: $gitreposcriptroot\$gitscriptname"

echo "Arguments used: $*"
echo ""

# Let's quit on interrupt of subcommands
trap '
trap - INT # restore default INT handler
echo "Interrupted"
kill -s INT "$$"
' INT

lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be more easily done as
echo "$*" | tr [A-Z] [a-z]

Copy link
Contributor Author
@DarwinJS DarwinJS Apr 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesWTruher - this came over from download.sh. Do you know if "tr" universally available on al platform targets? The methods in the script will have to favor universal availability of the tools used over elegant implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok did some research and it seems like anything in the posix command set should be considered universal and "tr" is on the list: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html


OS=`lowercase \`uname\``
KERNEL=`uname -r`
MACH=`uname -m`

if [ "${OS}" == "windowsnt" ]; then
OS=windows
DistroBasedOn=windows
SCRIPTFOLDER=$(dirname $(readlink -f $0))
elif [ "${OS}" == "darwin" ]; then
OS=osx
DistroBasedOn=osx
# readlink doesn't work the same on macOS
SCRIPTFOLDER=$(dirname $0)
else
SCRIPTFOLDER=$(dirname $(readlink -f $0))
OS=`uname`
if [ "${OS}" == "SunOS" ] ; then
OS=solaris
ARCH=`uname -p`
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
DistroBasedOn=sunos
elif [ "${OS}" == "AIX" ] ; then
OSSTR="${OS} `oslevel` (`oslevel -r`)"
DistroBasedOn=aix
elif [ "${OS}" == "Linux" ] ; then
if [ -f /etc/redhat-release ] ; then
DistroBasedOn='redhat'
DIST=`cat /etc/redhat-release |sed s/\ release.*//`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that cat is unneeded. sed and grep all take a file so this could just be
DIST=$(sed /s\ release.*// /etc/redhat-release)

Copy link
Member
@TravisEz13 TravisEz13 May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is easier to read to me

PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn='suse'
PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
REV=`cat /etc/SuSE-release | grep 'VERSION' | sed s/.*=\ //`
elif [ -f /etc/mandrake-release ] ; then
DistroBasedOn='mandrake'
PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/debian_version ] ; then
DistroBasedOn='debian'
DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'`
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
fi
OS=`lowercase $OS`
DistroBasedOn=`lowercase $DistroBasedOn`
readonly OS
readonly DIST
readonly DistroBasedOn
readonly PSUEDONAME
readonly REV
readonly KERNEL
readonly MACH
fi

fi

echo "Operating System Details:"
echo " OS: $OS"
echo " DIST: $DIST"
echo " DistroBasedOn: $DistroBasedOn"
echo " PSUEDONAME: $PSUEDONAME"
echo " REV: $REV"
echo " KERNEL: $KERNEL"
echo " MACH: $MACH"



if [[ "'$*'" =~ appimage ]] ; then
if [ -f $SCRIPTFOLDER/appimage.sh ]; then
#Script files were copied local - use them
. $SCRIPTFOLDER/appimage.sh
else
#Script files are not local - pull from remote
echo "Could not find \"appimage.sh\" next to this script..."
echo "Pulling it from \"$gitreposcriptroot/appimage.sh\""
bash <(wget -qO- $gitreposcriptroot/appimage.sh) $@
fi
elif [ "$DistroBasedOn" == "redhat" ] || [ "$DistroBasedOn" == "debian" ] || [ "$DistroBasedOn" == "osx" ] || [ "$DistroBasedOn" == "suse" ]; then
echo "Configuring PowerShell Core Enviornment for: $DistroBasedOn $DIST $REV"
if [ -f $SCRIPTFOLDER/installpsh-$DistroBasedOn.sh ]; then
#Script files were copied local - use them
. $SCRIPTFOLDER/installpsh-$DistroBasedOn.sh
else
#Script files are not local - pull from remote
echo "Could not find \"installpsh-$DistroBasedOn.sh\" next to this script..."
echo "Pulling it from \"$gitreposcriptroot/installpsh-$DistroBasedOn.sh\""
bash <(wget -qO- $gitreposcriptroot/installpsh-$DistroBasedOn.sh) $@
fi
else
echo "Sorry, your operating system is based on $DistroBasedOn and is not supported by PowerShell Core or this installer at this time."
fi
Loading
0