Skip to content
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

[SM-1130] - add install scripts #645

Merged
merged 22 commits into from
Jun 28, 2024

Conversation

tangowithfoxtrot
Copy link
Contributor

@tangowithfoxtrot tangowithfoxtrot commented Mar 1, 2024

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Allow easy installation of bws on most systems with:

curl <script-url> | sh on Linux and macOS
or
iwr <script-url> | iex on Windows

Code changes

  • crates/bws/scripts/install.(sh|ps1): added install scripts that will download bws from GitHub Releases, validate the checksums, and install it. I am unsure if this is the best place to house these scripts and would welcome suggestions for other places these might belong.
  • .github/workflows/version-bump.yml: added version bumps for the install scripts

Before you submit

  • Please add unit tests where it makes sense to do so

@bitwarden-bot
Copy link

bitwarden-bot commented Mar 1, 2024

Logo
Checkmarx One – Scan Summary & Detailsb77dac5c-a984-4807-8833-fe7a82afa5f9

No New Or Fixed Issues Found

Copy link

codecov bot commented Mar 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.86%. Comparing base (00b2120) to head (3ff5cde).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #645   +/-   ##
=======================================
  Coverage   59.86%   59.86%           
=======================================
  Files         189      189           
  Lines       12457    12457           
=======================================
  Hits         7457     7457           
  Misses       5000     5000           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coltonhurst
Copy link
Member

coltonhurst commented Jun 7, 2024

Not a bad location, but I agree we should think about where we want this. (If we do keep it in the bws crate I think it should definitely be in some type of subdirectory rather than the crate root.)

Some location ideas:

  • Separate directory, like crates/bws/scripts/<here>
  • GitHub Gist
  • Somewhere else?

Great idea 🎉

@tangowithfoxtrot
Copy link
Contributor Author

@coltonhurst, yeah, I'm beginning to think that the first option you provided is probably the way to go to avoid cluttering things too much. I don't think a GitHub gist will do though because we'll need to be able to automatically bump the version numbers in the install scripts.

I'll wait to see if any other ideas come up before moving them there, just to give other people the chance to chime-in.

Comment on lines 115 to 118
# bump the version in install.sh
sed -i 's/BWS_VERSION="${BWS_VERSION:-[0-9]\+\.[0-9]\+\.[0-9]\+}"/BWS_VERSION="${BWS_VERSION:-${{ inputs.version_number }}}"/' ./crates/bws/install.sh
# bump the version in install.ps1
sed -i 's/{ \$env:bwsVersion } else { "[0-9]\+\.[0-9]\+\.[0-9]\+" }/\{ \$env:bwsVersion } else { "${{ inputs.version_number }}" }/' ./crates/bws/install.ps1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These sed expressions worked when I tested them locally, but there doesn't appear to be a way to test this in the workflow, so I would appreciate some scrutiny here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated with simpler regex matches in 2dba059.

@tangowithfoxtrot tangowithfoxtrot marked this pull request as ready for review June 11, 2024 21:10
@tangowithfoxtrot tangowithfoxtrot requested a review from a team as a code owner June 11, 2024 21:10
we were previously matching the first checksum for the OS due to a lazy architecture match condition
@tangowithfoxtrot tangowithfoxtrot requested a review from a team June 12, 2024 13:08
Copy link
Member

@coltonhurst coltonhurst left a comment

Choose a reason for hiding this comment

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

I know we were waiting on other reviews, but some additional brief thoughts. I can do a deeper dive once it's fully ready again.

Note: We might want to consider adding a way to uninstall as well, and make sure nothing is left on the user's system.

Note 2: Is there a ticket for this? If not we will want one and definitely will want QA to review these

elif [ "$(uname -s)" = "Darwin" ]; then
PLATFORM="apple-darwin"
else
error "Unsupported platform: $(uname -s)"
Copy link
Member

Choose a reason for hiding this comment

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

We could potentially point people to the GitHub SDK repository if they want to create an issue for us to look into supporting their platform.

crates/bws/install.sh Outdated Show resolved Hide resolved
Comment on lines 99 to 100
expected_checksum="$(grep "bws-${ARCH}-${PLATFORM}-${BWS_VERSION}.zip" "$checksum_file" | awk '{print $1}')"
actual_checksum="$(sha256sum "$tmp_dir/bws.zip" | awk '{print $1}')"
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this get the expected and actual checksum from the same downloaded zip?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This greps for the string "bws-${ARCH}-${PLATFORM}-${BWS_VERSION}.zip" in the checksum file and uses awk to return just the checksum value.

Like this:

bash-5.2$ grep bws-aarch64-apple-darwin-0.5.0.zip ~/Downloads/bws-sha256-checksums-0.5.0.txt
aeac01edbd7cdfb8e75e9143d13d69221e6e0bff0fd9f8de69b85c3108a4e986 bws-aarch64-apple-darwin-0.5.0.zip
bash-5.2$ grep bws-aarch64-apple-darwin-0.5.0.zip ~/Downloads/bws-sha256-checksums-0.5.0.txt | awk '{print $1}'
aeac01edbd7cdfb8e75e9143d13d69221e6e0bff0fd9f8de69b85c3108a4e986

Copy link
Contributor

@mzieniukbw mzieniukbw left a comment

Choose a reason for hiding this comment

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

Nice scripts!
I have concern with the checksums on powershell though - did you had a chance to test it out on Windows? :)

# bump the version in install.sh
sed -i 's/BWS_VERSION="${BWS_VERSION:-[0-9]\+\.[0-9]\+\.[0-9]\+}"/BWS_VERSION="${BWS_VERSION:-${{ inputs.version_number }}}"/' ./crates/bws/scripts/install.sh
# bump the version in install.ps1
sed -i 's/{ \$env:bwsVersion } else { "[0-9]\+\.[0-9]\+\.[0-9]\+" }/\{ \$env:bwsVersion } else { "${{ inputs.version_number }}" }/' ./crates/bws/scripts/install.ps1
Copy link
Contributor

@mzieniukbw mzieniukbw Jun 17, 2024

Choose a reason for hiding this comment

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

i wonder if it wouldn't be just easier to define something likeDEFAULT_BWS_VERSION for both scripts.
Then in the install.sh this would look like this:

DEFAULT_BWS_VERSION=0.5.0
BWS_VERSION=${BWS_VERSION:-$DEFAULT_BWS_VERSION}

then from regex perspective it's much easier and consistent for both scripts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 2dba059

$expectedChecksum = (Get-Content $checksumFile | Where-Object { $_ -match "bws-$arch-pc-windows-msvc-$bwsVersion.zip" }).Split(" ")[0]
$actualChecksum = (Get-FileHash -Algorithm SHA256 -Path $zipPath).Hash

if ($actualChecksum -ne $expectedChecksum) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think the Hash from Get-FileHash is uppercase, while the GH checksum file is lowercase, so they would not match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can tell, PowerShell is case-insensitive, where possible. I found this, which says that this is also the case for comparison operators, so the comparison should return true, despite being in different cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding testing on Windows: I have tested it sparingly in a VM a few times throughout updating the script using iwr <url-for-raw-file> | iex, and it seems to be working.

I haven't been able to test it much on x86_64 though, as the only Windows machine in my house is a VM on my M2 Mac.

Copy link
Contributor

Choose a reason for hiding this comment

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

Windows as always have to be unique. Indeed it seems that string comparison is case insensitive, which is mind blowing to me 🤯
Thank you for the insights into testing, i wondered how do you test out Windows on Mac. 👍

@tangowithfoxtrot
Copy link
Contributor Author

@coltonhurst, I added an uninstallation arg in 24e0e98.

It's pretty easy to invoke in Linux/macOS with:

curl https://raw.githubusercontent.com/bitwarden/sdk/2dba059c1ee17366debb9535cff34fda767c3ff9/crates/bws/scripts/install.sh | sh -s -- --uninstall

However, I can't figure out a straightforward way to pass the -Uninstall arg through Invoke-Expression in PowerShell, so the best way to perform an uninstallation on Windows will require downloading the install script locally and passing the arg directly, like this:

.\install.ps1 -Uninstall

If you have greater PowerShell finesse than me, you can probably pass the -Uninstall arg through the

iex https://raw.githubusercontent.com/bitwarden/sdk/2dba059c1ee17366debb9535cff34fda767c3ff9/crates/bws/scripts/install.ps1 | iex # not sure how to pass args to the script through this???

one-liner, but I haven't been successful in doing so.

mzieniukbw
mzieniukbw previously approved these changes Jun 17, 2024
Copy link
Contributor

@mzieniukbw mzieniukbw left a comment

Choose a reason for hiding this comment

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

Approved, but would like to know other's feedback @coltonhurst on whether uninstalling should also remove .bws config directory - i am personally fine with it.

@tangowithfoxtrot tangowithfoxtrot changed the title add install scripts [SM-1130] - add install scripts Jun 20, 2024
@tangowithfoxtrot
Copy link
Contributor Author

@coltonhurst, Added mention of the install scripts in the README in 035ca93

@coltonhurst
Copy link
Member

Approved, but would like to know other's feedback @coltonhurst on whether uninstalling should also remove .bws config directory - i am personally fine with it.

Yeah I think we should make sure everything is cleared so there is no trace on the users system.

@coltonhurst coltonhurst merged commit 56547d7 into main Jun 28, 2024
105 checks passed
@coltonhurst coltonhurst deleted the sm/SM-1130/host-a-generic-install-script branch June 28, 2024 19:02
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