Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- self=`basename $0`
- keyfile=$HOME/.neocities_key.json
- address="neocities.org/api"
- keyfile_unusable() {
- cat $keyfile
- rm -f $keyfile
- exit
- }
- if [ ! -r $keyfile ]
- then
- echo "User: $USER"
- read PASS?'Password: '
- curl "https://$USER:$PASS@$address/key" >$keyfile
- unset PASS
- chmod 600 $keyfile
- if [ -z "`grep success $keyfile`" ]
- then
- echo "$self: Authorization failed, exiting."
- keyfile_unusable
- fi
- fi
- api_key=`grep api_key $keyfile | sed 's/^.* \"//' | sed 's/\"$//'`
- if [ ${#api_key} -ne 32 ]
- then
- echo "$self: Authorization file corrupted, exiting."
- keyfile_unusable
- fi
- curl_wrapper() {
- curl -H "Authorization: Bearer $api_key" $*
- }
- delete_filenames() {
- shift
- [ $1 ] && return "-d \"filenames[]=$1\" `delete_filenames $*`"
- return ""
- }
- if [ $1 ]
- then
- url=https://$address/$1
- case $1 in
- list) curl_wrapper "$url${2:+?path=$2}" ;;
- info) curl_wrapper "$url${2:+?sitename=$2}" ;;
- upload) [ $2 ] && curl_wrapper -F "${3:-$2}=@$2" "$url" ;;
- delete) crul_wrapper `delete_filenames $*` "$url" ;;
- archive) curl "https://web.archive.org/save/https://${2:-$USER}.neocities.org/" ;;
- *) echo "$self: Unknown command." ;;
- esac
- fi
Advertisement
Add Comment
Please, Sign In to add comment