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

create script to install latest powershell from repositories #3608

merged 3 commits into from
Jul 26, 2017

Conversation

DarwinJS
Copy link
Contributor
@DarwinJS DarwinJS commented Apr 20, 2017

I am an intermediate-noob at bash so I would love to have some testing of the new installer before doing a pull request.

The goals and overall idea is described in #3547

Features (and fixes of download.sh):

  • Bare minimum requirements to get going (wget & sed) (attempts to install curl if not present)
  • defaults to only install PowerShell core (using repos where they are available)
  • For non-repo based installs - detects latest version from git tags
  • Optional -includeide switch installs VS Code and PowerShell Extension (using repos where they are available)
  • Fix/Cleanup: Installs on OpenSUSE using download from regular github releases page (until repo is established)
  • Removed restriction to OpenSUSE 42.1, should install 42.1 and later.
  • Removed restriction to CentOS only - should install on Redhat as well.
  • Uses brew repository for OSX.

I have it working and tested under:

  • Ubuntu Desktop 16.04
  • CentOS 7.2 with GNOME Desktop
  • OpenSUSE 42.2 with KDE Desktop

Known Issues (and Help Needed):

  • The -appimage switch just calls the pre-existing appimage.sh which did not work on any of the above test cases
  • The OSX install was pieced together from various sources and is untested.

Here is the readme: https://github.com/DarwinJS/PowerShell/blob/feature/install-powershell.sh/tools/install-powershell.readme.md

Here are the commands to kick off the install (also covered in readme):

Only Install PowerShell Core:

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

Install PowerShell Core with IDE:

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

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

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

@msftclas
Copy link

@DarwinJS,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot


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=osx
DistroBasedOn=osx
else
OS=`uname`
Copy link
Collaborator

Choose a reason for hiding this comment

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

could the rest of these comparisons all be lower case comparisons? is there a need to rerun uname?

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


#Verify The Installer Choice (for direct runs of this script)
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.

echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" [](start = 4, length = 74)

echo "$1" | tr [A-Z] [a-z]


echo
echo "*** Installing PowerShell Core for $DistroBasedOn..."
if ! hash curl 2>/dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

hash [](start = 5, length = 4)

i know this works, but would which be a better choice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure - is "which" available on all platform targets including OSX? I will tend to favor what is working over making changes to something that in theory is a better method.

echo "curl not found, installing..."
$SUDO apt-get install -y curl
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//g | sed s/,//g | sed s/\ //g`
Copy link
Collaborator

Choose a reason for hiding this comment

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

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//g | sed s/,//g | sed s/\ //g` [](start = 9, length = 172)

there's all sorts of ways to do this. here's an alternative:
curl -q [https://api.github.com/repos/powershell/powershell/releases/latest](https://api.github.com/repos/powershell/powershell/releases/latest) 2>/dev/null | awk ' /tag_name/ { print $2 }' | sed "s/[\",]//g"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sure there are a lot of ways any given thing could be done - really looking for the smallest possible toolset dependencies to get the practical result.

KERNEL=`uname -r`
MACH=`uname -m`

if [ "{$OS}" == "windowsnt" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

"{ [](start = 5, length = 2)

this should be "${OS}" I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

if [ "{$OS}" == "windowsnt" ]; then
OS=windows
DistroBasedOn=windows
elif [ "{$OS}" == "darwin" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

{$OS} [](start = 8, length = 5)

"${OS}"


echo
echo "*** Installing PowerShell Core for $DistroBasedOn..."
if ! hash curl 2>/dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

curl [](start = 10, length = 4)

should you also check for wget?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my googling on it seemed that wget is pretty universal - this was also born out by the original download.sh. But I like the idea, because if someone replicates the repo or copies the script set manually - that is a scenario where I can't assume wget was used to pull the script in the first place.


#Verify The Installer Choice (for direct runs of this script)
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.

sed [](start = 16, length = 3)

tr

lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}
if [ "{$OS}" == "windowsnt" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

"${OS}"

if [ "{$OS}" == "windowsnt" ]; then
OS=windows
DistroBasedOn=windows
elif [ "{$OS}" == "darwin" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

$OS [](start = 9, length = 3)

"${OS}"

gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
thisinstallerdistro=suse
repobased=true
gitscriptname="installpsh-redhat.psh"
Copy link
Collaborator

Choose a reason for hiding this comment

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

redhat [](start = 26, length = 6)

suse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch - thanks!

@@ -0,0 +1,56 @@

## Features of install-powershell.sh
Copy link
Member

Choose a reason for hiding this comment

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

There are syntax errors in the markdown. Can you please enable these files in this test and fix the syntax errors)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TravisEz13 - I'm not sure what you mean. "##" is level two heading.

I also don't know what you mean by "Can you please enable these files in this test..." - how would I do this?

Please point me to a markdown validator where I can reproduce the syntax errors or the failed test report.

Thanks,
D.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TravisEz13 - I have tried to run the markdown syntax test locally. I have installed node-js and gulp as per the instructions in the script you linked, but it does not recognize 'test-mdsyntax' and I don't find it in the repo. I'm on Windows 10.

@DarwinJS
Copy link
Contributor Author
DarwinJS commented Apr 24, 2017

@TravisEz13 - I read the contributing information for pull requests and it says "clean up your commit history"

I did that by rebasing - but now I'm wondering if the idea is to keep at least one new commit for each update to the PR?

Let me know whether I should be squashing into my originally submitted commit or something else.

@iSazonov
Copy link
Collaborator
iSazonov commented Apr 24, 2017

@DarwinJS We must preserve the history, we should avoid rebaseing for already published commits. For new commits we should do one commit per one logical work piece: puttin 10000 g 10 commits with removing extra lines is bad.

@DarwinJS
Copy link
Contributor Author

@TravisEz13 - I added to spelling exceptions to the repo root's .spelling - but they seem to be ignored when checking my .md in the tools subfolder.

Should I create a .spelling in the tools subfolder - or is there something that has to be adjusted about the calling to the spelling checker?

@iSazonov
Copy link
Collaborator

@DarwinJS Maybe you can do spell checking on WSL.

@DarwinJS
Copy link
Contributor Author

@iSazonov - I neglected to mention I ran spell checking locally with the exact same code as used by CI and generated two spelling exceptions which it automatically added to .spelling in the repo root. However, when travis runs the build it does not seem to pickup on that .spelling file when it is processing the tools folder - so just trying to figure our the correct next step.

@DarwinJS
Copy link
Contributor Author

@joeyaiello - this PR is being blocked by the "spelling errors" on 'sed' and '-includeide' in the md help document I put together.

I have these exceptions in the main .spelling exception file and copied the .spelling file to the tools subfolder - still won't make it through.

What else might I do to pass the checks?

The command "powershell -File tools/travis.ps1" exited with 0.
1.83s$ if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mdspell '/*.md' '!powershell//*.md' --ignore-numbers --ignore-acronyms --report; fi
tools/install-powershell.readme.md
6 | werShell IDE) using optional -includeide switch
18 | * sed

@iSazonov
Copy link
Collaborator

@DarwinJS You added "includeide" - try "-includeide".
For "sed": 1. try add Newline after "sed" 2. Try "* sed"

@DarwinJS
Copy link
Contributor Author

@iSazonov - I have tried you solutions in both .spelling files. There already was a newline after sed and the original additions to the file was done by interactively running mdspell.

@iSazonov
Copy link
Collaborator

We can wrap "-includeide" with apostrophes `` in line 6 (and remove from .spelling)
But I dont understand that problem with "sed". Maybe use apostrophes too.

@DarwinJS
Copy link
Contributor Author
DarwinJS commented Apr 27, 2017

mdspell runs clean on that file on my local system (windows 10) with the exact same .spelling file:

image

Is the version running in CI the latest?

I am out of ideas :(

@iSazonov
Copy link
Collaborator

@DarwinJS It seems a mdspell issue. Did you try to use apostrophes?

@DarwinJS
Copy link
Contributor Author

@TravisEz13 and @iSazonov - Phew - Finally!

Copy link
Member
@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

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

I left a couple of comments.

@TravisEz13
Copy link
Member

Also, what is the plan on download.sh?

@DarwinJS
Copy link
Contributor Author
DarwinJS commented Jul 5, 2017

I no longer understand what is holding up this PR - can someone please enlighten me? Thanks!

@iSazonov
Copy link
Collaborator
iSazonov commented Jul 5, 2017

Please resolve file conflicting.

DarwinJS added 2 commits July 21, 2017 10:59
updating for pull request comments
OSX Install script updated to use repositories

Using TR, use curl rather than wget since we ensured it is on the system
Update comments in install-powershell.sh
install-powershell.sh
rename md to have only one period
fix md spelling mistakes
Fixes to markdown to follow strict syntax
create readme
@TravisEz13
Copy link
Member
TravisEz13 commented Jul 21, 2017

I forked this here: https://github.com/travisez13/powershell/tree/feature/install-powershell.sh and cleaned up the history, and re-based it against the current code.
Tests are running here: https://travis-ci.org/TravisEz13/PowerShell/builds/256155006
and here:
https://ci.appveyor.com/project/TravisEz13/powershell/build/6.0.0-beta.4-543

@DarwinJS
Copy link
Contributor Author

@TravisEz13 - I am interested in being listed as a contributor in this repo - will that still be the case with the actions you've taken?

@TravisEz13
Copy link
Member
TravisEz13 commented Jul 21, 2017

@DarwinJS , Yup, Only one commit I had to merge by hand got rewritten completely. You can see on 2 of the 3 remaining commits, you are listed as the main contributor:
https://github.com/TravisEz13/PowerShell/commits/feature/install-powershell.sh

@DarwinJS
Copy link
Contributor Author

Thanks for your explanation and for your help @TravisEz13 !

@TravisEz13
Copy link
Member

@DarwinJS, I'll see if GitHub will let me update your PR (force push to your branch) once the tests pass. If that doesn't work, you are also welcome to pull my branch, then push it to your fork and submit the PR yourself, but it matters very little which of us submits the PR.

@TravisEz13
Copy link
Member

@DarwinJS I reviewed the PR again. I enabled some tests on the markdown you added and fixed the issues it found and changed the default installer for PowerShell in our CI system to the one you wrote. I found the script didn't have execute permissions, I added them, and now I'm waiting for the tests again.

@TravisEz13
Copy link
Member
TravisEz13 commented Jul 21, 2017

@DarwinJS I think I have macOS working. I removed the openSSL because we already have code in start-psbootstrap to do this. There is a syntax error on line 99 of the macOS script, but it doesn't cause an issue, so, I'm not going to touch it for now. Using brew take about 150-160 seconds to install on the mac while download.sh took about 40 seconds. But bootstrapping is quicker by about the same time, So, I think this is acceptable.

@DarwinJS
Copy link
Contributor Author

@TravisEz13 - thanks for all the fixups - exactly what I was asking for in one of the previous conference calls!

@TravisEz13 TravisEz13 changed the title Feature/install powershell.sh create script to install latest powershell from repositories Jul 25, 2017
@TravisEz13 TravisEz13 requested a review from daxian-dbw July 25, 2017 01:51
@TravisEz13
Copy link
Member

I'm going to merge this soon... Please don't touch the branch. I'm going to clean-up the history first.

@DarwinJS
Copy link
Contributor Author

@TravisEz13 - maybe this should just call install-powershell.sh now?

@TravisEz13
Copy link
Member

@DarwinJS What is this?

@TravisEz13
Copy link
Member

If you are talking about our CI systems, I mention previously, that I changed install-powershell.sh to be used in CI in this PR. See https://github.com/DarwinJS/PowerShell/blob/e4dc9387320ec0107f3efecb25f2cdadebcdadbe/.travis.yml#L24

@DarwinJS
Copy link
Contributor Author

@TravisEz13 - apologies got this confused with one for download.sh

@TravisEz13 TravisEz13 merged commit f3dd2f0 into PowerShell:master Jul 26, 2017
@TravisEz13
Copy link
Member

@DarwinJS No Problem, This is merged. Thanks for your help.

@TravisEz13
Copy link
Member

@DarwinJS FYI, Your commits are here: fdabe86 and here: c31f274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0