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

self-updating runit file #500

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion scripts/auto-cpufreq-runit
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
#!/bin/sh
exec /usr/local/bin/auto-cpufreq --daemon
# test for update
if git -c advice.detachedHead=false pull -v https://github.com/AdnanHodzic/auto-cpufreq.git | grep -q -v '^\s*\(Updating\|Already up-to-date\|From\s\)\s'; then
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no guarantee that git exists. The script should check for dependencies like git and sudo mentioned below and act approprietly.

Where is git pulling to exactly?

exit
else
# install the update
echo "i" | sudo ~/auto-cpufreq/auto-cpufreq-installer && \
Copy link
Contributor

Choose a reason for hiding this comment

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

A runit service is run as root (unless it is a user service, which are rare, not enabled by default, a bit difficult to set up and the least common way services are used in runit).

Using sudo doesn't make sense here, the service is already root. It also adds a dependency on sudo, which doesn't have to be installed. Some people also use doas or other things.

Where is ~? You can't use things like ~ in service scripts without having a deep thought about where, how and by which user will the script be run. I have a suspicion that this script is really tailored to be a user service, because a lot of these things don't make sense otherwise. If that is the case, it should be clearly stated (for example in the line after shebang in a comment).

Why is && \ used everywhere? set +o errexit or something similar should be sufficient.

notify-send -a "auto-cpufreq" "Update installed" && \
Copy link
Contributor

Choose a reason for hiding this comment

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

notify-send doesn't work in (root) services. It shouldn't be run as root and it depends on environment variables that aren't available to runit.

# wait a bit to make sure its ready
sleep 1000
fi

# run the daemon
exec /usr/bin/auto-cpufreq --daemon 2>&1