diff options
author | gretchen <gretchen@gnar.cool> | 2019-11-18 16:58:52 -0800 |
---|---|---|
committer | gretchen <gretchen@gnar.cool> | 2019-11-18 16:58:52 -0800 |
commit | f40f6e25fe294df19bf09c1e7afbb73bea95a896 (patch) | |
tree | 3478d43a9abc2cdaf0ad8fbdd589a02be9ce37aa /norns_upload | |
parent | 7c5252d65ddcc94ed69da489c9ca068981db7e28 (diff) | |
download | norns-etc-f40f6e25fe294df19bf09c1e7afbb73bea95a896.tar.gz norns-etc-f40f6e25fe294df19bf09c1e7afbb73bea95a896.zip |
Make intermediate directorieS
Diffstat (limited to 'norns_upload')
-rwxr-xr-x[-rw-r--r--] | norns_upload | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/norns_upload b/norns_upload index 37817ea..c67ea6c 100644..100755 --- a/norns_upload +++ b/norns_upload @@ -5,17 +5,22 @@ if [[ $# -ne 2 ]]; then exit 1 fi -# TODO: make directories - HOST="${NORNS:-norns.local}" API="/api/v1" BASE="/dust/code/" PROJECT="$1" FILE="$2" - -LOCAL_FILE="$FILE" +# make directories +# TODO if there's already a directory with a filename this probably +# doesn't do the right thing, but maybe that's the best we can do... +DIR="$PROJECT/" +if [[ "$(dirname "$FILE")" != "." ]]; then + DIR+="$(dirname "$FILE")" +fi +DIR_URL="http://$HOST$API$BASE$DIR?kind=directory" URL="http://$HOST$API$BASE$PROJECT/$FILE" + TEMP="$(mktemp)" BOUNDARY="----$(head -c70 < <(tr -dc '\101-\132\141-\172' < /dev/urandom))" @@ -25,7 +30,14 @@ function finish { trap finish EXIT echo "--$BOUNDARY"$'\r\nContent-Disposition: form-data; name="value"; filename="blob"\r\nContent-Type: text/utf-8\r\n\r' > $TEMP -cat < "$LOCAL_FILE" >> $TEMP +cat < "$FILE" >> $TEMP echo $'\r\n'"--$BOUNDARY--"$'\r\n' >> $TEMP + +# this is idempotent *and* creates all of the intermediate directories +# thanks monome >:) +curl -XPUT "$DIR_URL" --silent > /dev/null + +# TODO this should exit 1 if this doesn't work +# looks like we need to parse this. curl "$URL" -X PUT -H "Content-Type: multipart/form-data; boundary=$BOUNDARY" --data-binary @$TEMP --compressed --silent > /dev/null |