Last active
June 10, 2016 06:14
-
-
Save chernjie/9edbf61a9ecbc555f7d8 to your computer and use it in GitHub Desktop.
hsg-door
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
success |
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 bash | |
require () { | |
for i | |
do | |
if ! command -v $i > /dev/null | |
then | |
echo Command $i not found, please install >&2 | |
exit 1 | |
fi | |
done | |
} | |
findPin () { | |
test -z "$HSG_DOOR_PIN" && | |
test -f $0.pin && source $0.pin | |
test -z "$HSG_DOOR_PIN" && | |
while test -z "$HSG_DOOR_PIN" | |
do | |
read -p "Door Pin: " HSG_DOOR_PIN | |
echo export HSG_DOOR_PIN=$HSG_DOOR_PIN > $0.pin | |
echo Updated $0.pin >&2 | |
done | |
} | |
main () { | |
findPin | |
curl -XPOST http://door.hackerspace.sg/auth.php \ | |
--connect-timeout 3 \ | |
--silent \ | |
--data "pin=$HSG_DOOR_PIN&type=pin" $@ | json | |
} | |
require curl npm json | |
case $1 in | |
*) main $@;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment