-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conversation
No New Or Fixed Issues Found |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
Not a bad location, but I agree we should think about where we want this. (If we do keep it in the Some location ideas:
Great idea 🎉 |
…thub.com/bitwarden/sdk into sm/SM-1130/host-a-generic-install-script
@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. |
.github/workflows/version-bump.yml
Outdated
# 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
we were previously matching the first checksum for the OS due to a lazy architecture match condition
There was a problem hiding this 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
crates/bws/install.sh
Outdated
elif [ "$(uname -s)" = "Darwin" ]; then | ||
PLATFORM="apple-darwin" | ||
else | ||
error "Unsupported platform: $(uname -s)" |
There was a problem hiding this comment.
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
expected_checksum="$(grep "bws-${ARCH}-${PLATFORM}-${BWS_VERSION}.zip" "$checksum_file" | awk '{print $1}')" | ||
actual_checksum="$(sha256sum "$tmp_dir/bws.zip" | awk '{print $1}')" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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? :)
.github/workflows/version-bump.yml
Outdated
# 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 👍
@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 .\install.ps1 -Uninstall If you have greater PowerShell finesse than me, you can probably pass 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. |
There was a problem hiding this 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.
@coltonhurst, Added mention of the install scripts in the README in 035ca93 |
Yeah I think we should make sure everything is cleared so there is no trace on the users system. |
Type of change
Objective
Allow easy installation of
bws
on most systems with:curl <script-url> | sh
on Linux and macOSor
iwr <script-url> | iex
on WindowsCode changes
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.Before you submit