Browse Source

Initial commit

master
TheOtherUnknown 1 week ago
commit
00b8028911
3 changed files with 34 additions and 0 deletions
  1. 7
    0
      LICENSE
  2. 11
    0
      README.md
  3. 16
    0
      zippleback.sh

+ 7
- 0
LICENSE View File

@@ -0,0 +1,7 @@
Copyright 2019 TheOtherUnknown

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 11
- 0
README.md View File

@@ -0,0 +1,11 @@
# Zippleback
Zippleback is a Bash command line client for the [BarfAndBel.ch API](https://barfandbel.ch/p/api/).

It uses [jq](https://stedolan.github.io/jq/) or Python 3 to parse the JSON from the API, in that order.
## How to use Zippleback as your server MOTD
### Debian/Ubuntu users
Copy the script file to `/etc/update-motd.d` and `chmod +x`. You may need to rename the file to add the run priority to the beginning.
### Others
Try putting the script in `/etc/profile.d`.
## Acknowledgements
Thanks to Iantje for providing the world's primier DaaS (Dragons-as-a-service) API.

+ 16
- 0
zippleback.sh View File

@@ -0,0 +1,16 @@
#!/bin/bash
json="$(curl -m 5 -s https://barfandbel.ch/api/v2/quote.php)"
if [ $? -gt 0 ]; then
echo 'Failed to get quote from remote server!'
exit 1
else
command -v jq > /dev/null
if [ $? -eq 0 ]; then # Is the JQ binary present? https://stedolan.github.io/jq/tutorial/
echo "$(echo $json | jq '.quote')" # I guess that's how you do that
echo " - $(echo $json | jq '.character' | tr -d '"'), $(echo $json | jq '.source' | tr -d '"')" # tr removes all double quotes
else #No jq? Then we'll use Python to parse the JSON
echo "\"$(echo $json | python3 -c "import sys, json; print(json.load(sys.stdin)['quote'])")\""
# I am mildy ashamed of this next line
echo " - $(echo $json | python3 -c "import sys, json; j=json.load(sys.stdin); print(j['character'] + ', ' + j['source'])")"
fi
fi

Loading…
Cancel
Save