Created
March 29, 2019 01:39
-
-
Save grahamc/9e6df6e7bc1137e8b97c0895789d290f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env nix-shell | |
#!nix-shell -i bash -p openssl | |
interactive() { | |
true | |
} | |
cd /sys/bus/thunderbolt/devices/ | |
find . | |
new_authorizations=0 | |
for d in $(find . -name '*-*'); do | |
( | |
echo "$d" | |
cd "$d" | |
if [ "$(cat authorized)" -eq 1 ]; then | |
echo "$d: already authorized" | |
continue | |
fi | |
if [ "$(sudo cat key)" = "" ]; then | |
echo "$d: empty key" | |
# nothing seems to remember keys on this dell xps 9380. | |
#if interactive; then | |
# echo -n "create key? [y/N]: " | |
# read x | |
# if [ "$x" = "y" ]; then | |
# openssl rand -hex 32 \ | |
# | sudo tee ./key > /dev/null | |
# echo "Please update this script with the new key." | |
# echo "(new key is at $(pwd)/key)" | |
# fi | |
#fi | |
fi | |
case "$(sudo cat key)" in | |
aaa) | |
;; | |
aaa) | |
;; | |
*) | |
echo "$d: unknown key" | |
if interactive; then | |
echo -n "authorize anyway? [y/N]: " | |
read x | |
if [ "$x" = "y" ]; then | |
echo "" | |
else | |
continue | |
fi | |
else | |
continue | |
fi | |
esac | |
echo "$d: authorizing" | |
echo 1 | sudo tee ./authorized | |
) | |
new_authorizations=1 | |
done | |
new_authorizations=0 | |
echo "$new_authorizations" | |
cd - | |
if [ "$new_authorizations" -eq 0 ] && interactive; then | |
echo "no new authorizations." | |
echo -n "unload, reload thunderbolt, and try again? [y/N]: " | |
read x | |
if [ "$x" = "y" ]; then | |
sudo modprobe -r thunderbolt | |
sudo modprobe thunderbolt | |
"$0" | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment