Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created March 29, 2019 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamc/9e6df6e7bc1137e8b97c0895789d290f to your computer and use it in GitHub Desktop.
Save grahamc/9e6df6e7bc1137e8b97c0895789d290f to your computer and use it in GitHub Desktop.
#!/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