-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make some improvements to the passwordless sudo logic and add cache t…
…o github actions
- Loading branch information
Showing
6 changed files
with
59 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
home/.chezmoiscripts/run_once_after_00-passwordless_sudo.sh.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{{ if eq (env "dev") "true" -}} | ||
{{ template "common" . -}} | ||
|
||
if [[ ! "$LOGNAME" =~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]]; then | ||
echo "Error: LOGNAME contains invalid characters." | ||
exit 1 | ||
fi | ||
if ! sudo -nv > /dev/null 2>&1 ;then | ||
echo "Please provide your sudo password:" | ||
sudo -v | ||
fi | ||
# Keep-alive: update existing sudo time stamp until the script has finished | ||
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | ||
# Do we need to ask for sudo password or is it already passwordless? | ||
if ! sudo grep -q 'NOPASSWD: ALL' /etc/sudoers.d/$LOGNAME > /dev/null 2>&1 ;then | ||
echo "no sudoer file" | ||
|
||
bot "Enabling passwordless sudo can reduce security. Are you sure you want to proceed?" | ||
|
||
answer=$(prompt "Make sudo passwordless?") | ||
|
||
if [[ $answer =~ ^[Yy]$ ]];then | ||
{{ if eq .osid "darwin" -}} | ||
if ! sudo grep -q "#includedir /private/etc/sudoers.d" /etc/sudoers; then | ||
echo '#includedir /private/etc/sudoers.d' | sudo tee -a /etc/sudoers > /dev/null | ||
fi | ||
[ ! -d "/private/etc/sudoers.d" ] && sudo mkdir /private/etc/sudoers.d | ||
TMPFILE=$(mktemp) | ||
echo -e "Defaults:$LOGNAME !requiretty\n$LOGNAME ALL=(ALL) NOPASSWD: ALL" > "$TMPFILE" | ||
sudo visudo -cf "$TMPFILE" && sudo mv "$TMPFILE" /private/etc/sudoers.d/$LOGNAME || { echo "Error in sudoers file"; rm "$TMPFILE"; exit 1; } | ||
echo "You can now run sudo commands without password!" | ||
{{ else -}} | ||
if ! sudo grep -q "@includedir /etc/sudoers.d" /etc/sudoers; then | ||
echo '@includedir /etc/sudoers.d' | sudo tee -a /etc/sudoers > /dev/null | ||
fi | ||
echo -e "Defaults:$LOGNAME !requiretty\n$LOGNAME ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$LOGNAME | ||
echo "You can now run sudo commands without password!" | ||
{{ end -}} | ||
fi | ||
fi | ||
{{ end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
home/.chezmoiscripts/run_once_before_01-install-homebrew.sh.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.