Guest User

neocities.sh

a guest
Jul 31st, 2019
255
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. self=`basename $0`
  4. keyfile=$HOME/.neocities_key.json
  5. address="neocities.org/api"
  6.  
  7. keyfile_unusable() {
  8.   cat $keyfile
  9.   rm -f $keyfile
  10.   exit
  11. }
  12.  
  13. if [ ! -r $keyfile ]
  14. then
  15.   echo "User: $USER"
  16.   read PASS?'Password: '
  17.   curl "https://$USER:$PASS@$address/key" >$keyfile
  18.   unset PASS
  19.   chmod 600 $keyfile
  20.   if [ -z "`grep success $keyfile`" ]
  21.   then
  22.     echo "$self: Authorization failed, exiting."  
  23.     keyfile_unusable
  24.   fi
  25. fi
  26.  
  27. api_key=`grep api_key $keyfile | sed 's/^.* \"//' | sed 's/\"$//'`
  28.  
  29. if [ ${#api_key} -ne 32 ]
  30. then
  31.   echo "$self: Authorization file corrupted, exiting."
  32.   keyfile_unusable
  33. fi
  34.  
  35. curl_wrapper() {
  36.   curl -H "Authorization: Bearer $api_key" $*
  37. }
  38.  
  39. delete_filenames() {
  40.   shift
  41.   [ $1 ] && return "-d \"filenames[]=$1\" `delete_filenames $*`"
  42.   return ""
  43. }
  44.  
  45. if [ $1 ]
  46. then
  47.   url=https://$address/$1
  48.  
  49.   case $1 in
  50.      list) curl_wrapper "$url${2:+?path=$2}" ;;
  51.      info) curl_wrapper "$url${2:+?sitename=$2}" ;;
  52.    upload) [ $2 ] && curl_wrapper -F "${3:-$2}=@$2" "$url" ;;
  53.    delete) crul_wrapper `delete_filenames $*` "$url" ;;
  54.   archive) curl "https://web.archive.org/save/https://${2:-$USER}.neocities.org/" ;;
  55.   *) echo "$self: Unknown command." ;;
  56.   esac
  57. fi
RAW Paste Data