Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / agl-systemd / tool_9E_SI / set_capability.sh
1 #!/bin/bash
2 #
3 # @copyright Copyright (c) 2019 TOYOTA MOTOR CORPORATION.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 ROMFILESTOP=/
19 CAP_LST=${ROMFILESTOP}/usr/target/cap.lst
20 echo `cat ${CAP_LST}`
21 #-----------------------------------------------------------------------
22 # Capability
23
24 df -T / | grep nfs > /dev/null
25 IS_EMMC_BOOT=$?
26
27 #*********************from init_nfs_cap.sh**************************
28
29 echo "init_nfs-cap.sh: Start"
30
31 VERBOSE=y
32 SKIPWARN=n
33 #-----------------------------------------------------------------------
34 # Set Capability for NFS or Set DummyLink for ROM
35 #CAP_LST="/usr/debug/share/target/cap.lst"
36 CAP_LST="/usr/target/cap.lst"
37
38 if [ $IS_EMMC_BOOT -eq 0 ]; then
39 if [ -f "${CAP_LST}" ];then
40     echo "*** set capability for NFS environment ***"
41   CAPPATH=/tmp/
42   cd /
43     for PREAD in `cat ${CAP_LST}`
44     do
45       IFS_ORG=${IFS} ; IFS='|' ; PARAM=(${PREAD}) ; IFS=${IFS_ORG}
46       CAP_NAME=${PARAM[0]} ; FMODE=${PARAM[1]} ; FUID_GID=${PARAM[2]}
47       FCAP=${PARAM[3]} ; FKEEPORGPATH=${PARAM[4]}
48       if [ ! -f "${CAP_NAME}" -a ! -f "${CAP_NAME}.org" ];then
49         if [ "${SKIPWARN}" = "n" ];then
50           echo "set capability: ${CAP_NAME}: No such file or directory" 1>&2
51         fi
52         continue
53       fi
54       TCAP_NAME="/tmp/${CAP_NAME##*/}"
55       # Set Capability for NFS
56         if [ ! -L "${CAP_NAME}" ]; then
57           cp -a ${CAP_NAME} ${TCAP_NAME}
58           if [ "${FKEEPORGPATH}" = "y" ];then
59             mv ${CAP_NAME} ${CAP_NAME}.org
60             ln -fs ${TCAP_NAME} ${CAP_NAME}
61           fi
62         else
63           cp -a ${CAP_NAME}.org ${TCAP_NAME}
64         fi
65         if [ -n "${FUID_GID}" ];then
66           chown ${FUID_GID} ${TCAP_NAME}
67         fi
68         if [ -n "${FMODE}" ];then
69           chmod ${FMODE} ${TCAP_NAME}
70         fi
71         if [ -n "${FCAP}" ];then
72           setcap ${FCAP} ${TCAP_NAME}
73           if [ "${VERBOSE}" = "y" ];then
74             getcap ${TCAP_NAME}
75           fi
76         fi
77     done
78   cd - > /dev/null
79 else
80   unset CAPPATH
81 fi
82 fi