mirror of
https://github.com/mrrpnya/lipu-sona.git
synced 2025-02-13 16:44:39 +00:00
modified the upload script to use filelist and hashes
This commit is contained in:
parent
ff09f34628
commit
cd1f95721a
1 changed files with 70 additions and 15 deletions
85
upload.sh
85
upload.sh
|
@ -9,27 +9,82 @@ fi
|
||||||
|
|
||||||
source ./upload.pwd
|
source ./upload.pwd
|
||||||
|
|
||||||
LASTUPLOAD=`stat -c %Y upload.lasttime 2>/dev/null`
|
if [ "$1" == "-h" ]; then
|
||||||
if [[ -z $LASTUPLOAD ]]; then LASTUPLOAD=0; fi
|
echo "Usage:"
|
||||||
|
echo "$0 -f filename [filename] ... -- upload specific files"
|
||||||
|
echo "$0 -n -- upload files whose moddates are later than last upload time"
|
||||||
|
echo ""
|
||||||
|
echo "By default, the program checks neocities for a list of files,"
|
||||||
|
echo "compares their sha1sums against ones in the out directory,"
|
||||||
|
echo "and uploads whichever files differ."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
#echo "Last upload at $LASTUPLOAD"
|
#echo "Last upload at $LASTUPLOAD"
|
||||||
|
|
||||||
FILES=`find out/ -type f`
|
|
||||||
|
|
||||||
UPFILES=()
|
UPFILES=()
|
||||||
UPARGS=()
|
UPARGS=()
|
||||||
|
|
||||||
for f in $FILES; do
|
if [ "$1" == "-f" ]; then
|
||||||
MTIME=`stat -c %Y $f`
|
|
||||||
#echo "MTIME for $f: $MTIME"
|
shift
|
||||||
if [[ $MTIME -gt $LASTUPLOAD ]]; then
|
for f in "$@"; do
|
||||||
REMOTENAME="${f#out/}"
|
UPFILES+=("$f")
|
||||||
echo "File $REMOTENAME needs uploading"
|
UPARGS+=("-F" "$f=@out/$f")
|
||||||
UPFILES+=("$REMOTENAME")
|
done
|
||||||
UPARGS+=("-F" "$REMOTENAME=@$f")
|
elif [ "$1" == "-n" ]; then
|
||||||
#curl -F "$REMOTENAME=@$f" "https://$N_USER:$N_PWD@neocities.org/api/upload"
|
|
||||||
fi
|
LASTUPLOAD=`stat -c %Y upload.lasttime 2>/dev/null`
|
||||||
done
|
if [[ -z $LASTUPLOAD ]]; then LASTUPLOAD=0; fi
|
||||||
|
|
||||||
|
FILES=`find out/ -type f -name '[!.]*'`
|
||||||
|
|
||||||
|
for f in $FILES; do
|
||||||
|
MTIME=`stat -c %Y $f`
|
||||||
|
#echo "MTIME for $f: $MTIME"
|
||||||
|
if [[ $MTIME -gt $LASTUPLOAD ]]; then
|
||||||
|
REMOTENAME="${f#out/}"
|
||||||
|
echo "File $REMOTENAME needs uploading"
|
||||||
|
UPFILES+=("$REMOTENAME")
|
||||||
|
UPARGS+=("-F" "$REMOTENAME=@$f")
|
||||||
|
#curl -F "$REMOTENAME=@$f" "https://$N_USER:$N_PWD@neocities.org/api/upload"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
if ! command -v curl > /dev/null; then
|
||||||
|
echo "This program needs the 'curl' utility to perform HTTP requests."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v jq > /dev/null; then
|
||||||
|
echo "This program needs the 'jq' utility to parse JSON outputs."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Checking neocities for a file list..."
|
||||||
|
FILELIST=`curl -sS "https://$N_USER:$N_PWD@neocities.org/api/list"`
|
||||||
|
|
||||||
|
if [ `echo "$FILELIST" | jq -r ".result"` != 'success' ]; then
|
||||||
|
echo "Error while requesting file list."
|
||||||
|
echo "$FILELIST"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $FILELIST | jq -cr '.files[]|select(.is_directory == false)|[.sha1_hash,.path] | @tsv' | sed 's/\t/ /' | sort -k2 > remotehashes.txt
|
||||||
|
|
||||||
|
( cd out; find -name '[!.]*' * -type f -exec sha1sum {} + | sort -k2 ) > localhashes.txt
|
||||||
|
|
||||||
|
UPDFILES=`diff -U0 localhashes.txt remotehashes.txt | grep ^-[0-9a-f] | cut -d " " -f3`
|
||||||
|
|
||||||
|
for f in $UPDFILES; do
|
||||||
|
echo "* $f needs to be updated."
|
||||||
|
UPFILES+=("$f")
|
||||||
|
UPARGS+=("-F" "$f=@out/$f")
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ${#UPARGS[@]} -gt 0 ]]; then
|
if [[ ${#UPARGS[@]} -gt 0 ]]; then
|
||||||
curl ${UPARGS[@]} "https://$N_USER:$N_PWD@neocities.org/api/upload" && touch upload.lasttime
|
curl ${UPARGS[@]} "https://$N_USER:$N_PWD@neocities.org/api/upload" && touch upload.lasttime
|
||||||
|
|
Loading…
Add table
Reference in a new issue