+ New script for neocities
This commit is contained in:
53
scripts/neocities.sh
Normal file
53
scripts/neocities.sh
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# This script takes care of uploading all artifacts in the public/ directory
|
||||
# To neocities via its API, This script is meant to be used in CI only
|
||||
# however it may occasionally be tested elsewhere
|
||||
|
||||
|
||||
upload_file() {
|
||||
file_path="$1"
|
||||
uri_path="${file_path:6}"
|
||||
|
||||
if [ -z "$file_path" ];then
|
||||
echo ERROR: upload_file Received an empty parameter exiting now >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Sub-routine uploads a single file for
|
||||
base='https://neocities.org/api/upload'
|
||||
# Curl gives us the exit code for this sub-routine's exit code
|
||||
curl \
|
||||
-H "Authorization: Bearer ${API_KEY}" \
|
||||
-F "${uri_path}=@${file_path}"
|
||||
}
|
||||
|
||||
feed_files() {
|
||||
# 2 seconds between API hits to ease up on Neocities
|
||||
SLEEP_TIME=2
|
||||
|
||||
if [ ! -z "$CUSTOM_SLEEP_TIME" ]; then
|
||||
SLEEP_TIME=$CUSTOM_SLEEP_TIME
|
||||
fi
|
||||
|
||||
# Main uploading section
|
||||
while read -r line; do
|
||||
if upload_file "$line"; then
|
||||
echo Uploaded $line
|
||||
else
|
||||
echo Failed $line >&2
|
||||
fi
|
||||
|
||||
sleep $SLEEP_TIME
|
||||
done < /dev/stdin
|
||||
}
|
||||
|
||||
if [ -d public/ ];then
|
||||
echo Found public directory
|
||||
# Upload all files that we wish to upload
|
||||
find public/ -type f | grep '\.[a-z]*' | feed_files
|
||||
else
|
||||
echo No public directory found
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user