Thomas Vachuska
Committed by Gerrit Code Review

Simplified onos-app reinstall usage to extract app name from the oar file.

Change-Id: I7e5efc2af4f2b0ced41caeeef67bc456243ddc62
...@@ -11,43 +11,57 @@ export URL=http://$node:8181/onos/v1/applications ...@@ -11,43 +11,57 @@ export URL=http://$node:8181/onos/v1/applications
11 export HDR="-HContent-Type:application/octet-stream" 11 export HDR="-HContent-Type:application/octet-stream"
12 export curl="curl -sS" 12 export curl="curl -sS"
13 13
14 +# Prints usage help
14 function usage { 15 function usage {
15 echo "usage: onos-app <node-ip> list" >&2 16 echo "usage: onos-app <node-ip> list" >&2
16 echo " onos-app <node-ip> {install|install!} <app-file>" >&2 17 echo " onos-app <node-ip> {install|install!} <app-file>" >&2
17 - echo " onos-app <node-ip> {reinstall|reinstall!} <app-name> <app-file>" >&2 18 + echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2
18 echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2 19 echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2
19 exit 1 20 exit 1
20 } 21 }
21 22
23 +# Extract app name from the specified *.oar file
24 +function appName {
25 + aux=/tmp/aux$$.jar
26 + cp $1 $aux
27 + pushd /tmp >/dev/null
28 + jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2
29 + rm -f $aux /tmp/app.xml
30 + popd >/dev/null
31 +}
32 +
22 [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage 33 [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
23 34
24 case $cmd in 35 case $cmd in
25 list) $curl -X GET $URL;; 36 list) $curl -X GET $URL;;
26 - install) 37 + install!|install)
27 - [ $# -lt 3 -o ! -f $app ] && usage 38 + [ $cmd = "install!" ] && activate="?activate=true"
28 - $curl -X POST $HDR $URL --data-binary @$app;;
29 - install!)
30 [ $# -lt 3 -o ! -f $app ] && usage 39 [ $# -lt 3 -o ! -f $app ] && usage
31 - $curl -X POST $HDR $URL?activate=true --data-binary @$app;; 40 + $curl -X POST $HDR $URL$activate --data-binary @$app
41 + ;;
32 42
33 - reinstall) 43 + reinstall!|reinstall)
34 - [ $# -lt 4 -o ! -f $4 ] && usage 44 + [ $cmd = "reinstall!" ] && activate="?activate=true"
45 + [ $# -lt 4 -a ! -f "$3" ] && usage
46 + [ $# -eq 4 -a ! -f "$4" ] && usage
47 + oar=$4
48 + [ $# -lt 4 ] && oar=$3 && app=$(appName $oar)
35 $curl -X DELETE $URL/$app 49 $curl -X DELETE $URL/$app
36 - $curl -X POST $HDR $URL --data-binary @$4;; 50 + $curl -X POST $HDR $URL$activate --data-binary @$oar
37 - reinstall!) 51 + ;;
38 - [ $# -lt 4 -o ! -f $4 ] && usage
39 - $curl -X DELETE $URL/$app
40 - $curl -X POST $HDR $URL?activate=true --data-binary @$4;;
41 52
42 uninstall) 53 uninstall)
43 [ $# -lt 3 ] && usage 54 [ $# -lt 3 ] && usage
44 - $curl -X DELETE $URL/$app;; 55 + $curl -X DELETE $URL/$app
56 + ;;
45 activate) 57 activate)
46 [ $# -lt 3 ] && usage 58 [ $# -lt 3 ] && usage
47 - $curl -X POST $URL/$app/active;; 59 + $curl -X POST $URL/$app/active
60 + ;;
48 deactivate) 61 deactivate)
49 [ $# -lt 3 ] && usage 62 [ $# -lt 3 ] && usage
50 - $curl -X DELETE $URL/$app/active;; 63 + $curl -X DELETE $URL/$app/active
64 + ;;
51 65
52 *) usage;; 66 *) usage;;
53 esac 67 esac
......