Skip to content

feat: smarter installation script for Clipper#18

Merged
supitsdu merged 1 commit intomainfrom
feature/install-script
Jun 25, 2024
Merged

feat: smarter installation script for Clipper#18
supitsdu merged 1 commit intomainfrom
feature/install-script

Conversation

@supitsdu
Copy link
Copy Markdown
Owner

  • 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.

- 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.
@supitsdu supitsdu self-assigned this Jun 25, 2024
@supitsdu supitsdu added the installation Changes related to the installation process or scripts involved label Jun 25, 2024
@supitsdu supitsdu merged commit 4330ab2 into main Jun 25, 2024
@supitsdu supitsdu deleted the feature/install-script branch June 25, 2024 04:51

# Clean up temporary directory
rm -rf "$TMP_DIR"
cleanup
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Owner Author

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.

Copy link
Copy Markdown
Contributor

@ccoVeille ccoVeille Jun 25, 2024

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know these tools?

They can help a lot when writing shell script

Copy link
Copy Markdown
Owner Author

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.

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Owner Author

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!

Copy link
Copy Markdown
Contributor

@ccoVeille ccoVeille Jun 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

installation Changes related to the installation process or scripts involved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants