lipu-sona/upload.sh

41 lines
925 B
Bash
Raw Normal View History

2020-03-14 09:03:43 +03:00
#!/bin/sh
if ! [[ -f upload.pwd ]]; then
echo "You need a file named upload.pwd with the following format:"
echo "N_USER=[your neocities username]"
echo "N_PWD=[your neocities password]"
exit 1
fi
source ./upload.pwd
LASTUPLOAD=`stat -c %Y upload.lasttime 2>/dev/null`
if [[ -z $LASTUPLOAD ]]; then LASTUPLOAD=0; fi
2020-03-14 20:27:53 +03:00
#echo "Last upload at $LASTUPLOAD"
2020-03-14 09:03:43 +03:00
FILES=`find out/ -type f`
2020-03-14 20:27:53 +03:00
UPFILES=()
UPARGS=()
2020-03-14 09:03:43 +03:00
for f in $FILES; do
MTIME=`stat -c %Y $f`
#echo "MTIME for $f: $MTIME"
if [[ $MTIME -gt $LASTUPLOAD ]]; then
REMOTENAME="${f#out/}"
2020-03-14 20:27:53 +03:00
echo "File $REMOTENAME needs uploading"
UPFILES+=("$REMOTENAME")
UPARGS+=("-F" "$REMOTENAME=@$f")
#curl -F "$REMOTENAME=@$f" "https://$N_USER:$N_PWD@neocities.org/api/upload"
2020-03-14 09:03:43 +03:00
fi
done
2020-03-14 20:27:53 +03:00
if [[ ${#UPARGS[@]} -gt 0 ]]; then
curl ${UPARGS[@]} "https://$N_USER:$N_PWD@neocities.org/api/upload" && touch upload.lasttime
else
echo "No files need to be uploaded."
fi
2020-03-14 09:03:43 +03:00