Skip to content

Make install scripts more consistent over different operating systems #9071

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 17 commits into from
Mar 8, 2019

Conversation

Geweldig
Copy link
Contributor

@Geweldig Geweldig commented Mar 6, 2019

PR Summary

I noticed a couple of inconsistencies when reading through the install bash scripts.

  • Make documentation for switches consistent over all files.
  • Replace all sed implementations of lowercase with a more maintainable tr implementation.
  • Set the OS variable in every install script, making it so previously unused checks are actually used.
  • Exit with a non-zero exit code when the script reaches an illegal state.

PR Context

A lot of people, including myself, read the install scripts before executing them. While doing so I noticed they contained inconsistencies. For example, certain flags you can pass to the install script were either undocumented or had an incorrect description. This PR fixes some of these inconsistencies, which should make them easier to maintain and easier to read.

PR Checklist

@msftclas
Copy link

msftclas commented Mar 6, 2019

CLA assistant check
All CLA requirements met.

@Geweldig Geweldig changed the title Make install scripts more consistent over different operating systems WIP: Make install scripts more consistent over different operating systems Mar 6, 2019
@Geweldig Geweldig changed the title WIP: Make install scripts more consistent over different operating systems Make install scripts more consistent over different operating systems Mar 6, 2019
@Geweldig Geweldig changed the title Make install scripts more consistent over different operating systems WIP: Make install scripts more consistent over different operating systems Mar 6, 2019
@Geweldig
Copy link
Contributor Author

Geweldig commented Mar 6, 2019

I used ShellCheck as a linter locally, as it seemed to create the same output as Codacy. I also noticed some of the files contained invalid bash (if then if instead of if then fi), which has also been resolved.

@Geweldig Geweldig changed the title WIP: Make install scripts more consistent over different operating systems Make install scripts more consistent over different operating systems Mar 6, 2019
Copy link
Contributor

@RDIL RDIL left a comment

Choose a reason for hiding this comment

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

@iSazonov iSazonov added the CL-Tools Indicates that a PR should be marked as a tools change in the Change Log label Mar 6, 2019
@Geweldig
Copy link
Contributor Author

Geweldig commented Mar 6, 2019

@iSazonov thanks for the great suggestions! I was not entirely sure about the correct casing for Visual Studio Code, as I could find it as VSCode, vscode and VS Code. Because of this I decided to just leave it all lowercase. I have implemented your suggestions, thanks for the review!

@Geweldig
Copy link
Contributor Author

Geweldig commented Mar 6, 2019

It appears the connection to windowsitpro.com has timed out, which is why the static analysis has failed. The next connection to it however does finish successfully. Should the CI be restarted or is this not an issue?

@iSazonov
Copy link
Collaborator

iSazonov commented Mar 6, 2019

Restart CI-static-analysis.

@TravisEz13
Copy link
Member

@DarwinJS Would you mind giving this a first pass?

@TravisEz13 TravisEz13 self-assigned this Mar 8, 2019
@TravisEz13 TravisEz13 force-pushed the clean_install_scripts branch from 478a6d6 to 9b9b36b Compare March 8, 2019 03:05
@TravisEz13
Copy link
Member

Okay... I tried to add support to the CI for a representative portion of the distros.

AmazonLinux image failed because it was missing adduser. (I'll ask in the docker repo if we want to add this to get this scenario working.)

OpenSUSE failed because it Azure DevOps could not find pwsh (I can fix this later)

@TravisEz13
Copy link
Member

So CentOS testing was the only distro added. cc @adityapatwardhan

@DarwinJS
Copy link
Contributor

DarwinJS commented Mar 8, 2019

Travis - Amazon optimizes every purpose specific use of Amazon Linux and of course specifically the one for containers.

Since the size of the Amazon built Amazon Linux containers affects their server density globally across all customers, it will likely be necessary to add back what you need to get CI running.

PS For my local testing of Amazon Linux 2 - I have actually created some antipattern containers that have the entire EC2 build version: https://cloudywindows.io/post/three-amazon-linux-2-containers-for-testing/

@DarwinJS
Copy link
Contributor

DarwinJS commented Mar 8, 2019

@Geweldig - did you test your changes on the major distros?
@TravisEz13 - how do we know what distros these install scripts are tested on - is there a manifest somewhere?

@Geweldig
Copy link
Contributor Author

Geweldig commented Mar 8, 2019

@DarwinJS I have verified it to be working for the following operating systems:

  • Centos7
  • Ubuntu 18.04
  • Debian 9 (Assuming lsb-release has been shipped with it, might be worthwhile to look at an alternative check as it is not always included)
  • Fedora 29
  • macOS 12

Which should cover the major distros. I have tried the installer on openSUSE Leap 15 (as 42.3 is reaching EOL in July) where I have not been able to get it to work. However, when trying to run the script which is currently on master I couldn't get it to work either. This problem is twofold, as the OS is not recognized by the main script and the openSUSE installer which is currently provided contains invalid bash. Unfortunately I am not familiar with openSUSE and would need some time to figure out why it currently is not recognized by the script on master and find a robust solution to recognize the operating system.




if [[ "'$*'" =~ appimage ]] ; then
if [ -f $SCRIPTFOLDER/appimage.sh ]; then
if [ -f "$SCRIPTFOLDER/appimage.sh" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

We have not produced an appimage in a long time. This in not blocking, but I think this code can either go, or be replaced with a check for snapd and then use snapd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a check for snapd sounds like a good replacement, but might not be very robust as snapd is not yet standard in a lot of distributions (I believe it's currently only shipped with Ubuntu). Because of this I would argue that deleting the code for appimage would make more sense, and implementing a snap install when Snappy is more mature/widely used.

@TravisEz13 TravisEz13 merged commit 7031954 into PowerShell:master Mar 8, 2019
@TravisEz13
Copy link
Member

@DarwinJS The CI YML for testing these scripts is here:

pool: Hosted Ubuntu 1604
# amazonlinux was missing adduser
- template: templates/install-ps-phase.yml
parameters:
scriptName: ./tools/install-powershell.sh
jobName: InstallPowerShellCentOS
pool: Hosted Ubuntu 1604
container: mcr.microsoft.com/powershell:centos-7
# VSTS could not find pwsh in:
# mcr.microsoft.com/powershell:opensuse-42.3
# could not repo locally
- template: templates/install-ps-phase.yml
parameters:
scriptName: ./tools/install-powershell.sh
jobName: InstallPowerShellMacOS
pool: Hosted macOS

NOTE: where a container is listed, it overrides the pool. Like on line 54, to switch to CentOS.

Currently Ubuntu 16.04, CentOS 7, and macOS Mojave are in the list.

@Geweldig Geweldig mentioned this pull request Mar 9, 2019
11 tasks
@Geweldig Geweldig deleted the clean_install_scripts branch March 12, 2019 07:53
@DarwinJS
Copy link
Contributor

Is it ok if I reverse these changes?
Amazon Linux 2 install is not working whether using the stand alone script or the main one. I'm not sure how many more are doing that?

@iSazonov
Copy link
Collaborator

Why revert? Do you know the issue root cause? Is it possible to fix?

@DarwinJS
Copy link
Contributor

DarwinJS commented Jun 20, 2019

I don't know the root cause, but I let this slip through without realizing the distro fingerprinting had been altered to DEPEND on the parent script being called for each distro specific script. I had specifically designed it to not depend - the parent script was a convenience when wanting to target distros homogenously.

But then I wanted to get off using my original merge branch for linuxmint support which still works for Amazon Linux - and this one does not. (I use it here to create Amazon LInux 2 containers that have PowerShell: https://gitlab.com/DarwinJS/amazon-linux-2-container-with-powershell/blob/master/Dockerfile#L4)

So this all points to the changes not being comprehensively tested - something I was doing whenever I made broad-based changes.

Since these changes seemed to be mainly making the code prettier - not more functional - I'd rather revert to a known working state that I had tested across all distros - than try to fix and retest on all distros. I really don't have the time for the latter.

@iSazonov
Copy link
Collaborator

@Geweldig @TravisEz13 Thoughts?

@DarwinJS
Copy link
Contributor

@DarwinJS I have verified it to be working for the following operating systems:

  • Centos7
  • Ubuntu 18.04
  • Debian 9 (Assuming lsb-release has been shipped with it, might be worthwhile to look at an alternative check as it is not always included)
  • Fedora 29
  • macOS 12

Which should cover the major distros. I have tried the installer on openSUSE Leap 15 (as 42.3 is reaching EOL in July) where I have not been able to get it to work. However, when trying to run the script which is currently on master I couldn't get it to work either. This problem is twofold, as the OS is not recognized by the main script and the openSUSE installer which is currently provided contains invalid bash. Unfortunately I am not familiar with openSUSE and would need some time to figure out why it currently is not recognized by the script on master and find a robust solution to recognize the operating system.

OK, then maybe the solution is to consider Amazon Linux 2 a major distro and test and debug for it. Not only is Amazon treating it this way, but it was the first distro to have prebuilt cloud image template (AMIs) from the cloud provider with .NET Core and PowerShell Core preinstalled. That is a full Ec2 image, I want to use amazon linux 2 w/ PowerShell Core under Gitlab CI on Linux containers - so still need installation support.

@Geweldig
Copy link
Contributor Author

@DarwinJS I indeed didn't test the install script on Amazon Linux 2, as I did not have access to a build environment for it. However, I believe the changes made to the install script shouldn't have broken anything as they only cleaned up unused and broken variables, but I'm obviously wrong. All changes which I believe could break the build on Linux, should also break all other scripts which we have tested to be working.

Do you have a specific error so we can pinpoint where the script goes wrong?

@iSazonov
Copy link
Collaborator

I have concerns about the rollback since the PR has been merged for a long time (we have a release after that).

I did not have access to a build environment for it.

Maybe you could cooperate with @DarwinJS directly?

@DarwinJS
Copy link
Contributor

The following Docker commands will let you easily test:

# This Works:
docker run -v -it amazonlinux /bin/bash -c "curl -s https://raw.githubusercontent.com/DarwinJS/PowerShell/installpsh-debian-support-for-linuxmint/tools/installpsh-amazonlinux.sh | bash ; pwsh"

# This Does Not:
docker run -v -it amazonlinux /bin/bash -c "curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-amazonlinux.sh | bash ; pwsh"

@Geweldig
Copy link
Contributor Author

Ah I see what the problem is, I rewrote the OS checks in a single script and copied them over all other scripts. However, the script I originally based it on seems to not have included the check for amazonlinux. Not sure how I missed that, but it shouldn't be difficult to fix.

@Geweldig Geweldig mentioned this pull request Jun 20, 2019
11 tasks
@Geweldig
Copy link
Contributor Author

@DarwinJS I have opened #9967 to fix this issue, I'm currently verifying the install scripts again on all different operating systems. This has resolved the problem for amazon linux.

@TravisEz13
Copy link
Member

@iSazonov @DarwinJS @Geweldig We have started to move the packaging/installation tools into separate repos that are maintained by the people that care about that tool. Honestly, long term I think we should do the same thing here. We could keep the main script with a warning to migrate.

cc @SteveL-MSFT

@iSazonov
Copy link
Collaborator

@TravisEz13 Could you please reference the new repo?

@TravisEz13
Copy link
Member

@iSazonov This is a concept. There is no current. But Docker and Snap have been separated, if that is what you are talking about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-Tools Indicates that a PR should be marked as a tools change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants