48aa91970054d2b9fd31f78555414af965eb0a47
[platform/framework/web/crosswalk.git] / src / xwalk / application / tools / tizen / xwalk_backend_wrapper.sh
1 #!/bin/bash
2
3 # Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 #parse installation options
8 while [ "$1" != "" ]
9 do
10     case "$1" in
11         "-i") option="-i"
12               id="$2"
13               shift
14               ;;
15         "-d") option="-u"
16               id="$2"
17               shift
18               ;;
19         "-q") quiet="-q"
20               ;;
21         "-k") key="-k"
22               keyvalue="$2"
23               shift
24               ;;
25         "-r") echo "Reinstall not supported"
26               exit 128 # ErrorNotSupportRDSUpdate == 128
27               ;; #TODO(t.iwanek) fix me - sending signals for reinstall option
28     esac
29     shift
30 done
31
32 if [ "`whoami`" == "root" ]
33 then
34     #
35     # TODO(t.iwanek): fix me
36     # this is workaround that will work only for 'app' user
37     # pkgmgr-server is running as root and then backend too
38     # 1) backend need to know the user
39     #  or
40     # 2) pkgmgr must change user before launching backend
41     #
42
43     # Find requesting process...
44     #  (will fail for multiple installation at same time)
45     user=`ps aux | grep -v 'grep' | grep pkgcmd | cut -f1 -d" "`
46
47     su - ${user} -c "/usr/bin/xwalkctl ${option} ${id} ${key} ${keyvalue} ${quiet}"
48 else
49     # correct UID was set by pkgmgr
50     /usr/bin/xwalkctl ${option} ${id} ${key} ${keyvalue} ${quiet}
51 fi