-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpublish.sh
executable file
·35 lines (33 loc) · 1023 Bytes
/
publish.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
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: ./`basename $0` <package> <ip/hostname of gateway> <username>"
else
if [ "$(uname -s)" = 'Darwin' ]
then
checksum=`md5 $1 | cut -d ' ' -f 4`
sedcmd='sed -E'
else
checksum=`md5sum $1 | cut -d ' ' -f 1`
sedcmd='sed -r'
fi
read -s -p "Enter password: " password
echo
login=`curl -sk -X GET "https://$2/login?username=$3&password=$password"`
success=`echo $login | $sedcmd 's/(.+)"success": *([a-z]+)(.+)/\2/'`
if [ "$success" = "true" ]
then
token=`echo $login | $sedcmd 's/(.+)"token": *"([a-z,0-9]+)"(.+)/\2/'`
result=`curl -sk --form "package_data=@$1" --form md5=$checksum --form token=$token -X POST "https://$2/install_plugin"`
success=`echo $result | $sedcmd 's/(.+)"success": *([a-z]+)(.+)/\2/'`
if [ "$success" = "true" ]
then
echo "Publish succeeded"
else
error=`echo $result | $sedcmd 's/"msg": *"([^"]+)/\1/'`
echo "Publish failed: $error"
fi
else
echo "Login failed"
fi
fi