Skip to content

Instantly share code, notes, and snippets.

@kwhitefoot
Forked from rchrd2/upload_site.sh
Last active May 20, 2017 20:08
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 kwhitefoot/34f6966bde992319c4ed82fe892ae5d0 to your computer and use it in GitHub Desktop.
Save kwhitefoot/34f6966bde992319c4ed82fe892ae5d0 to your computer and use it in GitHub Desktop.
Neocities Upload
#!/bin/bash
# Neocities provides an API for uploading files from ./public_html to
# your site.
#
# Example Usage:
# $ USERNAME=username PASS=secret_pass bash upload_site.sh path_to_local_web_root
# or
# $ export USERNAME=username
# $ export PASS=secret_pass
# $ ./upload_site.sh path_to_local_web_root
# All files will be uploaded to the same directory structure except
# for files matching common backup file patterns. Files with names
# matching these globs will be excluded: '*#*', '*~*', '.*'. This
# means that Emacs temporary files, Emacs local versions, and any dot
# files will be omitted.
# From:
# https://gist.github.com/kwhitefoot/34f6966bde992319c4ed82fe892ae5d0
# Original from:
# https://gist.github.com/rchrd2/4fb3198053d107a81430e35a85a9e363
# Fail immediately on error
set -e
#set -x
# Name the source directory
src=$1
# Note that this is not a very secure way to upload because the
# password and username are part of the URL. And also visible to
# anyone who can see the curl command line in the process list.
function upload_file {
fullName=$1
# Remove the ./ from the beginning of the file name.
shortName=${fullName:2}
echo "Uploading: ${fullName}"
curl -F "$shortName"="@$fullName" https://$USERNAME:$PASS@neocities.org/api/upload
}
# Change directory to the source so that we can easily get names
# relative to that directory.
cd "$src"
uploaded=0
# Now find all the files except for the backups, etc., and upload
# them.
find ./* ! -name '*~*' ! -name '*#*' ! -name '.*' -type f | while read file
do
if [ -f "$file" ]
then
upload_file "$file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment