+ Working neocities upload script
This commit is contained in:
parent
f2cba8e856
commit
beddd84836
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
upload_file() {
|
upload_file() {
|
||||||
|
set -e
|
||||||
file_path="$1"
|
file_path="$1"
|
||||||
uri_path="${file_path:6}"
|
uri_path="${file_path:6}"
|
||||||
|
|
||||||
@ -15,12 +16,13 @@ upload_file() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
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 gives us the exit code for this sub-routine's exit code
|
||||||
curl \
|
curl -s \
|
||||||
-H "Authorization: Bearer ${API_KEY}" \
|
-H "Authorization: Bearer ${API_KEY}" \
|
||||||
-F "${uri_path}=@${file_path}"
|
-F "${uri_path}=@${file_path}" \
|
||||||
|
'https://neocities.org/api/upload'
|
||||||
|
|
||||||
|
return $!
|
||||||
}
|
}
|
||||||
|
|
||||||
feed_files() {
|
feed_files() {
|
||||||
@ -34,20 +36,34 @@ feed_files() {
|
|||||||
# Main uploading section
|
# Main uploading section
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
if upload_file "$line"; then
|
if upload_file "$line"; then
|
||||||
echo Uploaded $line
|
echo "Pass $line"
|
||||||
else
|
else
|
||||||
echo Failed $line >&2
|
echo "Failed $line" > /dev/stderr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep $SLEEP_TIME
|
sleep $SLEEP_TIME
|
||||||
done < /dev/stdin
|
done < /dev/stdin
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -d public/ ];then
|
verify_api_key() {
|
||||||
echo Found public directory
|
if [ -z "$API_KEY" ];then
|
||||||
# Upload all files that we wish to upload
|
echo '$API_KEY env var is not set' > /dev/stderr
|
||||||
find public/ -type f | grep '\.[a-z]*' | feed_files
|
|
||||||
else
|
|
||||||
echo No public directory found
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
verify_public_dir() {
|
||||||
|
# Check that the public directory is present
|
||||||
|
if [ ! -d public/ ];then
|
||||||
|
echo 'No public directory found!' > /dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pre flight checks to make sure we don't try uploading without
|
||||||
|
# the required keys/files in place
|
||||||
|
verify_public_dir; verify_api_key
|
||||||
|
|
||||||
|
# Only upload items that have an extension(files) in the case
|
||||||
|
# of data generated by hugo
|
||||||
|
find public/ -type f | \
|
||||||
|
grep '\.[a-z]*' | \
|
||||||
|
feed_files
|
||||||
|
Loading…
Reference in New Issue
Block a user