Skip to content

Instantly share code, notes, and snippets.

@etuttle
Last active July 6, 2020 08:58
Show Gist options
  • Save etuttle/9cb2871459d2b3e6f4027b36558eb1d2 to your computer and use it in GitHub Desktop.
Save etuttle/9cb2871459d2b3e6f4027b36558eb1d2 to your computer and use it in GitHub Desktop.
.bash_profile function to keep touchbar sudo setup (especially after an OS upgrade has undone it)
(psudo=/etc/pam.d/sudo;
if test -e "$psudo" \
&& ! grep --silent pam_tid.so "$psudo" \
&& test -t 0; then
false
fi) || function sudo() {
set -e
sudo_=$(which sudo)
if ! test -t 0; then
# no tty, just pass the sudo call through
$sudo_ "$@"
else
echo "Enabling touchbar authentication for sudo"
psudo=/etc/pam.d/sudo
$sudo_ --validate
(set -x
$sudo_ chmod 0644 "$psudo"
$sudo_ sed -i '' '2i\
auth sufficient pam_tid.so
' "$psudo"
$sudo_ chmod 0444 "$psudo")
unset -f sudo
echo "Touchbar sudo is setup, calling sudo for your original purpose..."
sudo "$@" || true
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment