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

Install bash scripts improvements #413

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eberna
Copy link

@eberna eberna commented Nov 29, 2024

Hello, while installing autorestic (thank you for the amazing projects) i took the liberty to do some changes to the installation script. If it's ran as no root user it will leverage the sudo command to run it in elevated mode, the if statement changed with case and other minors changes. I hope it can be of use.
Thanks

Copy link

vercel bot commented Nov 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
autorestic ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 3, 2024 5:20pm

install.sh Outdated
@@ -1,36 +1,41 @@
#!/bin/bash
# Check if the script is running as root
[ "$EUID" -eq 0 ] || exec sudo bash "$0" "$@"
Copy link
Contributor

Choose a reason for hiding this comment

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

  • I'm pretty sure the os detection and the wget really don't benefit from being run as root.
  • Also, some bsd machines dont have sudo by default.

It might make more sense to just wrap the sudo around autorestic install... and maybe only after checking there is a sudo in the first place?

Copy link
Author

@eberna eberna Dec 3, 2024

Choose a reason for hiding this comment

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

Hi, I made some changes to handle elevation to root with sudo or su, and only commands that need to write to /usr/local/bin are executed as root.

[ "$EUID" -eq 0 ] || exec sudo bash "$0" "$@"
# Initialize the elevated variable to ensure we can run commands as root
if [ "$EUID" -eq 0 ]; then
elevated="bash -c" # No need for sudo or su if running as root
Copy link
Contributor

Choose a reason for hiding this comment

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

elevated=""

Setting it to the empty string means it just goes away - setting it to bash means a whole new shell.

Copy link
Author

Choose a reason for hiding this comment

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

have you tested it? thanks

install.sh Outdated
bzip2 -cd "${TMP_FILE}.bz2" > "${OUT_FILE}"
chmod +x ${OUT_FILE}
rm "${TMP_FILE}.bz2"
$elevated "bzip2 -cd ${TMP_FILE}.bz2 > ${OUT_FILE}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Your redirect (>)won't happen as root

Copy link
Author

Choose a reason for hiding this comment

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

have you tested it? thanks

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.

2 participants