+#!/bin/sh -ex
+
+SRV=${SRV:-cloud.seafile.com}
+CURL=${CURL:-curl}
+JQ=${JQ:-gojq}
+JO=${JO:-gjo}
+
+fn="$1"
+[ -n "$fn" ]
+
+auth=`grep "machine $SRV" ${NETRC:-$HOME/.netrc}`
+[ -n "$auth" ]
+auth_name=`echo $auth | sed 's/^.*login \([^ ]*\).*$/\1/'`
+auth_pass=`echo $auth | sed 's/^.*password \([^ ]*\).*$/\1/'`
+
+SRV="https://$SRV"
+CURL="$CURL --fail"
+JQ="$JQ --raw-output"
+
+token=$($CURL --silent --data "username=${auth_name}&password=${auth_pass}" \
+ $SRV/api2/auth-token/ | $JQ .token)
+[ -n "$token" ]
+repoId=$($CURL --silent --header "Authorization: Token $token" \
+ $SRV/api2/default-repo/ | $JQ .repo_id)
+[ -n "$repoId" ]
+uploadLink=$($CURL --silent --header "Authorization: Token $token" \
+ $SRV/api2/repos/${repoId}/upload-link/ | $JQ .)
+[ -n "$uploadLink" ]
+fileId=$($CURL --progress-bar --header "Authorization: Token $token" \
+ --form file=@${fn} --form parent_dir=/ $uploadLink)
+[ -n "$fileId" ]
+fn="$(basename "$fn")"
+req=$($JO repo_id=$repoId "path=/$fn" permissions="$($JO can_edit=false can_download=true)")
+$CURL --silent --header "Authorization: Token $token" \
+ --header "Content-type: application/json" --data "$req" \
+ $SRV/api/v2.1/share-links/ | $JQ .link
+
+# $CURL -H "Authorization: Token $token" -X DELETE "$SRV/api/v2.1/share-links/LINK/"
+# $CURL -H "Authorization: Token $token" -X DELETE "$SRV/api2/repos/$repoId/file/?p=/$fn