-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: smarter installation script for Clipper #18
Conversation
- Add check for necessary tools (`curl`, `sudo`) before proceeding. - Implement version check to fetch the latest release version from GitHub. - Include comparison of installed and latest version to determine if an upgrade is needed. - Add user prompts for confirmation to proceed with installation or upgrade. - Implement uninstallation functionality. - Add command line options: `-y` for auto-confirmation, `-h` for help message, `-r` for uninstallation, `-v` for version check. - Ensure /usr/local/bin is in PATH before installing. - Enhance error handling and provide consistent and informative error messages. - Implement cleanup of temporary files after script execution.
set_binary_url | ||
download_binary | ||
make_executable | ||
install_binary | ||
verify_installation | ||
|
||
# Clean up temporary directory | ||
rm -rf "$TMP_DIR" | ||
cleanup |
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.
The way you call cleanup everywhere is a proof you should use trap
at the very beginning of your script
trap is the shell version of the Go's depher
Please have a look at man trap
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.
Thanks mate! I had no clue about the existence of trap. This is game changing for me! Thanks a ton, really! I will work on implementing this for sure.
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.
trap is amazing if you consider a CTRL+C or an error caught with pipefail won't call the cleanup part otherwise
The only issue with trap is the fact it's always called. So the code called should consider the current state is unsure.
Here is an example
You create a tempfile, trap cleanup was defined before.
If the code fails to create tempfile, but cleanup delete tempfile
cleanup should consider tempfile might be missing
Meaning a rm tempfile might fail
So here the good solution is either to test file exists, or use rm tempfile || true
@@ -1,26 +1,63 @@ | |||
#!/bin/sh |
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.
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 do, I've been using shellcheck for a while now. Thanks for the suggestions.
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 thing then
These are game changers
Do you use shfmt?
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 was looking into it... and mate what a discovery this is! I've been writing shell script for years as a hobby, but this is amazing! It also allows you to minify shell script code?! Language dialect selection and much more?! Mate, you opened a new world right now!
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.
You're welcome.
Dev is a drug, I'm happy to support you getting worst or better (it's never easy to decide)
My moto is somehow:
Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime
curl
,sudo
) before proceeding.-y
for auto-confirmation,-h
for help message,-r
for uninstallation,-v
for version check.