Download script for portable installation
Describe the solution you'd like
Distributing official download.sh in the repository. Or it could be install.sh that take --target as parameter and copies the executable binary on a desired place.
So the end users can run something like /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/mas-cli/mas/HEAD/script/download.sh)" to get right mas binary on current folder. Just like brew.
The script would:
- Find right URL for latest release from /releases like
https://github.com/mas-cli/mas/releases/download/v1.8.2/mas-1.8.2.arm64_big_sur.bottle.tar.gzfor the currrent OS.- It would include finding major OS name (big sur, el capitan, high sierra etc.) and detecting current CPU architecture (
arm64or not). Just like inbottle.sh(maybe they can reuse the same logic?)
- It would include finding major OS name (big sur, el capitan, high sierra etc.) and detecting current CPU architecture (
- Download the archive on a local folder
I think steps above are good enough but would be nice to have with more steps in the script:
- Extract the
.tar.gz - Make the mas binary executable (
chmod +ux mas) - Remove unsigned application warning (
xattr -r -d com.apple.quarantine './mas') - 🥳 A portable
masbinary is ready to go!
Background
It's awesome that the portable edition is being distributed with mas now.
However automatically installing the right binary major version / CPU architecture is complex without any package manager, requiring some unofficial logic. The downside of consumers having their "own" script is the risk of compatibility issues with future releases of mas e.g. when a new OS platform is supported.
Providing a way to download right portable binary in an easy way for current OS would make it easy to use in automated scripts that are massively distributed. Because it would enable distributing mas without requiring a package manager or any installation in a most lightweight way possible. So consuming scripts can be non-intrusive to users' potential existing installation nor require an uninstallation logic (would simply delete the binary)
(I'd love to distribute and use mas in privacy.sexy in a reliable an future proof way to many clients. This feature request is extension of #326 where pkg solution is also discussed but it does not seem to be friendly way of distributing portable application)
Looking forward for your feedback about whether it's worth considering.
This doesn't sound very hard. As you've noticed, a lot of this logic already exists in our scripts.
The tricky part is probably figuring out the version to use. It would be easy if we only supported the "latest" version, but are you thinking people would need to download older versions?
Thanks for the quick feedback and considering it. You're right on your point.
Always fetch latest version
- Pros: Pretty straightforward to implement. We could just request to
https://github.com/mas-cli/mas/releases/latest. - Cons: When
masis heavily distributed and gets a new major version it would break the current users' scripts.- E.g. I distribute a bash script using
mas listAPI but then in next major version it changes tomas lsand it starts breaking for everyone re-running the script.
- E.g. I distribute a bash script using
So maybe a better option would be:
Allow specifying version using an environment variable
We could read an environment variable like MAS_DL_VERSION and fetch the version specified in that one. If the environment variable is not set it would fall back to latest but could be set by e.g. tag/v1.8.2 by users.
(Inspiration comes from how brew does it with HOMEBREW_BREW_GIT_REMOTE, see install.sh)
(An idea for future): Even more complex but valuable implementation would be allowing a wildcard like 1.*.*, 1.x.x or ~1.8.2 like in package.json (i.e. I want the latest non-breaking API) and it would find the latest major version. However this is much harder to implement as GitHub lacks a good API for it. It could be done in a potential future iteration.
How does it sound? I mean checking for an environment variable like MAS_DL_VERSION to build download URL and falling back to latest if none given?
I can send a PR for the second option if it sounds good