]> Sergey Matveev's repositories - sfloader.git/blob - sf-ul
Initial commit
[sfloader.git] / sf-ul
1 #!/bin/sh -ex
2
3 SRV=${SRV:-cloud.seafile.com}
4 CURL=${CURL:-curl}
5 JQ=${JQ:-gojq}
6 JO=${JO:-gjo}
7
8 fn="$1"
9 [ -n "$fn" ]
10
11 auth=`grep "machine $SRV" ${NETRC:-$HOME/.netrc}`
12 [ -n "$auth" ]
13 auth_name=`echo $auth | sed 's/^.*login \([^ ]*\).*$/\1/'`
14 auth_pass=`echo $auth | sed 's/^.*password \([^ ]*\).*$/\1/'`
15
16 SRV="https://$SRV"
17 CURL="$CURL --fail"
18 JQ="$JQ --raw-output"
19
20 token=$($CURL --silent --data "username=${auth_name}&password=${auth_pass}" \
21     $SRV/api2/auth-token/ | $JQ .token)
22 [ -n "$token" ]
23 repoId=$($CURL --silent --header "Authorization: Token $token" \
24     $SRV/api2/default-repo/ | $JQ .repo_id)
25 [ -n "$repoId" ]
26 uploadLink=$($CURL --silent --header "Authorization: Token $token" \
27     $SRV/api2/repos/${repoId}/upload-link/ | $JQ .)
28 [ -n "$uploadLink" ]
29 fileId=$($CURL --progress-bar --header "Authorization: Token $token" \
30     --form file=@${fn} --form parent_dir=/ $uploadLink)
31 [ -n "$fileId" ]
32 fn="$(basename "$fn")"
33 req=$($JO repo_id=$repoId "path=/$fn" permissions="$($JO can_edit=false can_download=true)")
34 $CURL --silent --header "Authorization: Token $token" \
35     --header "Content-type: application/json" --data "$req" \
36     $SRV/api/v2.1/share-links/ | $JQ .link
37
38 # $CURL -H "Authorization: Token $token" -X DELETE "$SRV/api/v2.1/share-links/LINK/"
39 # $CURL -H "Authorization: Token $token" -X DELETE "$SRV/api2/repos/$repoId/file/?p=/$fn