1 #!/bin/sh
1 #!/bin/sh
2 AWK=/bin/awk
3 CHMOD=/bin/chmod
4 CHGRP=/bin/chgrp
5 CP=/bin/cp
6 ECHO=/bin/echo
7 MKDIR=/bin/mkdir
8 RUID=`/usr/bin/id|$AWK -F( '{print $1}'|$AWK -F= '{print $2}'` --检查当前用户是否是 root
9 if [ ${RUID} != "0" ];then --root用户执行语句输出 是 0
10 $ECHO "This script must be executed as root" --输出
11 exit 1
12 fi
13 if [ -d "/etc" ]; then
14 $CHMOD 755 /etc; --如果目录存在,给目录授权
15 else
16 $MKDIR -p /etc; --如果目录不存在,创建目录
17 fi
18 if [ -f "/u01/app/oraInventory/oraInst.loc" ]; then --如果文件存在
19 $CP /u01/app/oraInventory/oraInst.loc /etc/oraInst.loc; --复制文件到指定目录
20 $CHMOD 644 /etc/oraInst.loc --给目标文件授权
21 else
22 INVPTR=/etc/oraInst.loc
23 INVLOC=/u01/app/oraInventory
24 GRP=oinstall
25 PTRDIR="`dirname $INVPTR`";
26 # Create the software inventory location pointer file
27 if [ ! -d "$PTRDIR" ]; then --如果目录不存在
28 $MKDIR -p $PTRDIR; --创建目录
29 fi
30 $ECHO "Creating the Oracle inventory pointer file ($INVPTR)";
31 $ECHO inventory_loc=$INVLOC > $INVPTR
32 $ECHO inst_group=$GRP >> $INVPTR
33 chmod 644 $INVPTR --给指定文件授权
34 # Create the inventory directory if it doesn't exist
35 if [ ! -d "$INVLOC" ];then
36 $ECHO "Creating the Oracle inventory directory ($INVLOC)";
37 $MKDIR -p $INVLOC; --如果目录不存在,创建目录
38 fi
39 fi
40 $ECHO "Changing permissions of /u01/app/oraInventory.
41 Adding read,write permissions for group.
42 Removing read,write,execute permissions for world.
43 ";
44 $CHMOD -R g+rw,o-rwx /u01/app/oraInventory; --给目录授权
45 if [ $? != 0 ]; then
46 $ECHO "OUI-35086:WARNING: chmod of /u01/app/oraInventory
47 Adding read,write permissions for group.
48 ,Removing read,write,execute permissions for world.
49 failed!";
50 fi
51 $ECHO "Changing groupname of /u01/app/oraInventory to oinstall.";
52 $CHGRP -R oinstall /u01/app/oraInventory; --给目录更改 主组
53 if [ $? != 0 ]; then
54 $ECHO "OUI-10057:WARNING: chgrp of /u01/app/oraInventory to oinstall failed!";
55 fi
56 $ECHO "The execution of the script is complete."