-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathupload-ipfs.sh
executable file
·100 lines (91 loc) · 2.47 KB
/
upload-ipfs.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
BRANCH=$1
OS=$2
upload_ipfs (){
filename=$1
user="[email protected]"
fingerprint="877B586E74F170BC4CF6ECABB971E2AC63D23DC9"
cdnHost=$2
extract_id()
{
id_src=$(echo $json | grep "id")
id=${id_src:10:46}
}
json=`curl -k -s -X GET ${cdnHost}/rest/v1/cdn/raw?name=$filename`
echo "Received: $json"
extract_id
echo "Previous file ID is $id"
authId="$(curl -s ${cdnHost}/rest/v1/cdn/token?fingerprint=${fingerprint})"
echo "Auth id obtained and signed $authId"
sign="$(echo ${authId} | gpg --clearsign -u ${user})"
token="$(curl -s --data-urlencode "request=${sign}" ${cdnHost}/rest/v1/cdn/token)"
echo "Token obtained $token"
echo "Uploading file..."
upl_msg="$(curl -sk -H "token: ${token}" -Ffile=@$filename -Ftoken=${token} -X POST "${cdnHost}/rest/v1/cdn/uploadRaw")"
echo "$upl_msg"
echo "Removing previous"
echo $Upload
if [[ -n "$id" ]] && [[ $upl_msg != "An object with id: $id is exist in Bazaar. Increase the file version." ]]
then
curl -k -s -X DELETE "$cdnHost/rest/v1/cdn/raw?token=${token}&id=$id"
fi
echo -e "\\nCompleted"
}
case $OS in
Linux)
BASENAME="p2p"
BIN_EXT=""
BIN_DIR="p2p/debian/subutai-p2p/usr/bin"
;;
MSYS_NT-10.0)
BASENAME="p2p.exe"
BIN_EXT=".exe"
BIN_DIR="bin"
;;
Darwin)
BASENAME="p2p_osx"
BIN_EXT="_osx"
BIN_DIR="bin"
;;
esac
case $BRANCH in
dev)
BINNAME="p2p-dev$BIN_EXT"
cd $BIN_DIR
cp $BASENAME $BINNAME
IPFSURL=https://devbazaar.subutai.io
upload_ipfs $BINNAME $IPFSURL
;;
master)
BINNAME="p2p-master$BIN_EXT"
cd $BIN_DIR
cp $BASENAME $BINNAME
IPFSURL=https://masterbazaar.subutai.io
upload_ipfs $BINNAME $IPFSURL
;;
head)
BINNAME="p2p$BIN_EXT"
if [ $OS = Linux ] || [$OS = MSYS_NT-10.0 ]
then
cd $BIN_DIR
cp $BASENAME $BINNAME
IPFSURL=https://bazaar.subutai.io
upload_ipfs $BINNAME $IPFSURL
fi
;;
HEAD)
BINNAME="subutai-p2p$PKG_EXT"
if [ $OS = Linux ] || [$OS = MSYS_NT-10.0 ]
then
cd $BIN_DIR
cp $BASENAME $BINNAME
IPFSURL=https://bazaar.subutai.io
upload_ipfs $BINNAME $IPFSURL
fi
;;
esac
echo "---------"
echo $BINNAME
echo $OS
echo $BRANCH
echo $VERSION
echo "---------"