-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·56 lines (48 loc) · 1.29 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh -l
HOST=$1
PASSWORD=$2
SHARING_ID=$3
UPLOADER_NAME=$4
FILE=$5
if [ -z "$HOST" ]
then
echo "Invalid host"
exit 1
fi
if [ -z "$SHARING_ID" ]
then
echo "Invalid sharing ID"
exit 1
fi
if [ -z "$FILE" ]
then
echo "Invalid file"
exit 1
fi
if [ -z "$UPLOADER_NAME" ]
then
echo "Invalid uploader name"
exit 1
fi
if [ ! -z "$PASSWORD" ]
then
echo "Login to synology file share..."
curl -s -L -X POST "$HOST/sharing/webapi/entry.cgi/SYNO.Core.Sharing.Login" \
-j -c /tmp/syno_file_upload_cookies \
-d "api=SYNO.Core.Sharing.Login&method=login&version=1&sharing_id=%22$SHARING_ID%22&password=%22$PASSWORD%22" > /dev/null
else
echo "Initialize connection..."
curl -s -L "$HOST/sharing/$SHARING_ID" \
-j -c /tmp/syno_file_upload_cookies > /dev/null
fi
echo "Uploading the file..."
FILE_LAST_MODIFIED=$(date -r $FILE +%s%3N)
curl -s -L -X POST "$HOST/webapi/entry.cgi?api=SYNO.FileStation.Upload&method=upload&version=2&_sharing_id=%22$SHARING_ID%22" \
-b /tmp/syno_file_upload_cookies \
-F "overwrite=\"true\"" \
-F "mtime=\"$FILE_LAST_MODIFIED\"" \
-F "sharing_id=\"$SHARING_ID\"" \
-F "uploader_name=\"$UPLOADER_NAME\"" \
-F "size=\"undefined\"" \
-F "file=@\"$FILE\"" > /dev/null
rm -f /tmp/syno_file_upload_cookies