From 41ef8eb9863a01e52d18cb4c1147be7d8e2f0ef4 Mon Sep 17 00:00:00 2001 From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:43:02 +0000 Subject: [PATCH] Latest --- .../universal/run_before_02-homebrew.sh.tmpl | 5 +---- home/dot_config/shell/profile.sh.tmpl | 5 +++++ home/dot_local/bin/executable_sudo-askpass | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 home/dot_local/bin/executable_sudo-askpass diff --git a/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl b/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl index 2f769639..5c500508 100644 --- a/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl @@ -132,6 +132,7 @@ upgradeDarwin() { ### Run upgrade process logg info 'Applying OS upgrades (if available)' + logg info 'This may take awhile..' expect -c "set timeout -1 spawn sudo softwareupdate -i -a --agree-to-license expect \"Password:\" @@ -165,10 +166,6 @@ upgradeDarwin() { ### Reboot logg info 'Reboot required' && exit 140 - # gtimeout 60 osascript -e 'tell application "Finder" to shut down' || OSASCRIPT_EXIT_CODE=$? - # if [ -n "$OSASCRIPT_EXIT_CODE" ]; then - # logg info 'Reboot required and failed to gracefully shutdown within 1 minute, so forcing reboot' && sudo sh -c 'shutdown -r now' - # fi else logg info 'No reboot required for softwareupdate' fi diff --git a/home/dot_config/shell/profile.sh.tmpl b/home/dot_config/shell/profile.sh.tmpl index 9acbdf2a..3ca32c02 100644 --- a/home/dot_config/shell/profile.sh.tmpl +++ b/home/dot_config/shell/profile.sh.tmpl @@ -97,6 +97,11 @@ if [ "$BASH_SUPPORT" = 'true' ]; then if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/motd.sh" ]; then . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/motd.sh" fi + + ### SUDO_ASKPASS + if [ -d /Applications ] && [ -d /System ]; then + SUDO_ASKPASS="$HOME/.local/bin/sudo-askpass" + fi fi ### Cargo diff --git a/home/dot_local/bin/executable_sudo-askpass b/home/dot_local/bin/executable_sudo-askpass new file mode 100644 index 00000000..2c6b21a1 --- /dev/null +++ b/home/dot_local/bin/executable_sudo-askpass @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# @file Sudo Password Helper +# @brief Integrates sudo password entry with native system dialogs for `SUDO_ASKPASS` +# @description +# Many programs allow you to define the `SUDO_ASKPASS` environment variable to handle passing in +# sudo privileges. For more details, check out [this StackOverflow post](https://stackoverflow.com/questions/12608293/how-to-setup-a-sudo-askpass-environment-variable). + +if [ -z "$SUDO_PASSWORD" ]; then + if [ -d /Applications ] && [ -d /System ]; then + ### macOS + SUDO_PASSWORD="$(osascript -e 'Tell application "System Events" to display dialog "Administrator Password:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null)" + else + ### Linux + SUDO_PASSWORD="TODO" + fi +fi +echo "$SUDO_PASSWORD"