Skip to content

Instantly share code, notes, and snippets.

@mtougeron
Created August 5, 2014 23:52
Show Gist options
  • Save mtougeron/8dc9cd42c1dd9bd566a3 to your computer and use it in GitHub Desktop.
Save mtougeron/8dc9cd42c1dd9bd566a3 to your computer and use it in GitHub Desktop.
A simple script to track your login password for scripts
1) run
./sudo_askpass.sh set
and set the password to the keychain
2) run
export SUDO_ASKPASS=/path/to/sudo_askpass.sh
3) run
/do/my/script/to/install/things.sh
4) run
./sudo_askpass.sh del
#!/bin/bash
if [ "$1" == "set" ]; then
read -s -t 30 -p "Enter your sudo password: " pw
/usr/bin/security add-generic-password -U -l scripting-account-pw -a $USER -s "scripting: $USER" -w $pw
elif [ "$1" == "del" ]; then
_tmp=$(/usr/bin/security delete-generic-password -l scripting-account-pw -a $USER -s "scripting: $USER")
else
/usr/bin/security find-generic-password -l 'scripting-account-pw' -a $USER -w
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment