Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active June 10, 2016 06:14
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 chernjie/9edbf61a9ecbc555f7d8 to your computer and use it in GitHub Desktop.
Save chernjie/9edbf61a9ecbc555f7d8 to your computer and use it in GitHub Desktop.
hsg-door
#!/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