Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 299 lines (266 sloc) 7 KB
#!/bin/sh
# Copyright (c) 2004-2016 Fernando Nunes - domusonline@gmail.com
# License: This script is licensed as GPL V2 ( http://www.gnu.org/licenses/old-licenses/gpl-2.0.html )
# $Author: Fernando Nunes - domusonline@gmail.com $
# $Revision: 2.0.13 $
# $Date 2016-12-12 00:32:18$
# Disclaimer: This software is provided AS IS, without any kind of guarantee. Use at your own risk.
# Although the author is/was an IBM employee, this software was created outside his job engagements.
# As such, all credits are due to the author.
usage()
{
echo "$PROGNAME Usage:" >&2
echo "$PROGNAME <existing INFORMIXDIR> <new virt INFORMIXDIR> [ {DBSA GROUP} {AAO_GROUP} {DBSSO_GROUP} ]" >&2
}
PROGNAME=`basename $0`
VERSION=`echo "$Revision: 2.0.13 $" | cut -f2 -d' '`
case $# in
2)
EXISTING_IXDIR=$1
NEW_IXDIR=$2
GROUPS_FLAG=0
;;
5)
EXISTING_IXDIR=$1
NEW_IXDIR=$2
DBSA_GROUP=$3
grep "^${DBSA_GROUP}:" /etc/group 1>/dev/null 2>/dev/null
if [ $? != 0 ]
then
echo "The group given for DBSA ( ${DBSA_GROUP} ) does not exist in /etc/group" >&2
exit 1
fi
AAO_GROUP=$4
grep "^${AAO_GROUP}:" /etc/group 1>/dev/null 2>/dev/null
if [ $? != 0 ]
then
echo "The group given for AAO ( ${AAO_GROUP} ) does not exist in /etc/group" >&2
exit 1
fi
DBSSO_GROUP=$5
grep "^${DBSSO_GROUP}:" /etc/group 1>/dev/null 2>/dev/null
if [ $? != 0 ]
then
echo "The group given for DBSSO ( ${DBSSO_GROUP} ) does not exist in /etc/group" >&2
exit 1
fi
GROUPS_FLAG=1
;;
*)
usage
exit 1
esac
SO=`uname -s | tr "[:upper:]" "[:lower:]"`
case $SO in
sunos*)
AWK=nawk
;;
*)
AWK=awk
;;
esac
export AWK
IX_VERSION=`export INFORMIXDIR=$EXISTING_IXDIR;$EXISTING_IXDIR/bin/onstat -V | egrep -e "Informix Dynamic " | $AWK '
BEGIN {
DBSA=0
}
/Informix Dynamic/ { split($0, a, "Version"); split(a[2],b,".");VER=b[1]"."b[2] }
END {
print VER
}' | $AWK '{print $1}'`
OPTIONAL_DIRS="dummy"
case $IX_VERSION in
7*)
IX_SUB_DIRS="aaodir bin dbssodir demo etc forms gls help incl ism lib msg release snmp"
IX_DIRS="bin demo forms gls help incl ism lib msg release snmp"
;;
9*)
IX_SUB_DIRS="aaodir bin dbssodir demo doc etc extend forms gls help incl ism lib msg release snmp"
IX_DIRS="bin demo doc extend forms gls help incl ism lib msg release snmp"
;;
10.00|11.10)
IX_SUB_DIRS="aaodir bin dbssodir demo doc etc extend forms gls help incl ism lib msg release snmp ids_license tmp"
IX_DIRS="bin demo doc extend forms gls help incl ism lib msg release snmp ids_license"
;;
11.50)
IX_SUB_DIRS="aaodir bin dbssodir demo doc etc extend forms gls help incl ism lib msg release snmp ids_license gskit gsk ssl tmp"
IX_DIRS="bin demo doc extend forms gls help incl ism lib msg release snmp ids_license gskit gsk"
OPTIONAL_DIRS=snmp
;;
11.70)
IX_SUB_DIRS="SDK aaodir bin dbssodir demo doc etc extend forms gls gskit help incl isa lib license msg properties release ssl tmp uninstall jdbc"
IX_DIRS="SDK bin demo doc extend forms gls gskit help incl isa lib license msg properties release ism jdbc"
OPTIONAL_DIRS="jdbc ism"
#ism as optional?
;;
12.10)
IX_SUB_DIRS="SDK aaodir bin dbssodir demo doc etc extend gls gskit help incl isa lib license msg properties release snmp ssl tmp uninstall jdbc"
IX_DIRS="SDK bin demo doc extend gls gskit help incl isa lib license msg properties release snmp jdbc"
OPTIONAL_DIRS="snmp jdbc"
#ism as optional?
;;
*)
echo "Version can only be 7, 9, 10, 11, 11.5, 11.7 or 12.1. Found:$IX_VERSION" >&2
exit 1
;;
esac
GROUP_MEMBERSHIP=`groups | ${AWK} '{for (a=1;a<=NF;a++) {printf("%s|",$a)} printf ("\n");}'`
MY_USER=`id | ${AWK} -F"[()]" ' { print $2 } '`
WARN_FLAG=0
case $MY_USER in
root)
;;
informix)
if [ "X${GROUPS_FLAG}" = "X1" ]
then
for GROUP in $DBSA_GROUP $AAO_GROUP $DBSSO_GROUP
do
echo $GROUP_MEMBERSHIP | grep "$GROUP|" >/dev/null
if [ $? != 0 ]
then
WARN_FLAG=1
fi
done
fi
;;
*)
echo "This utility must be run as root or informix" >&2
exit 1
;;
esac
if [ ! -d $EXISTING_IXDIR ]
then
echo "$EXISTING_IXDIR is not an existing dir!" >&2
exit 1
else
CURR_DIR=`pwd`
cd $EXISTING_IXDIR
EXISTING_IXDIR=`pwd`
cd $CURR_DIR
fi
for dir in $IX_SUB_DIRS
do
if [ ! -d $EXISTING_IXDIR/$dir ]
then
AUX_FLAG=0
for aux in ${OPTIONAL_DIRS}
do
if [ "X${dir}" = "X${aux}" ]
then
echo "$EXISTING_IXDIR/$dir does not exist!... Skiping..."
AUX_FLAG=1
break
fi
done
if [ $AUX_FLAG = 0 ]
then
echo "$EXISTING_IXDIR/$dir does not exist!... Aborting..." >&2
exit 1
fi
fi
done
if [ ! -w $NEW_IXDIR ]
then
mkdir $NEW_IXDIR
if [ $? != 0 ]
then
echo "Error creating non existing new INFORMIXDIR: $NEW_IXDIR" >&2
exit 1
fi
if [ $MY_USER != "informix" ]
then
chown informix:informix $NEW_IXDIR
fi
chmod 755 $NEW_IXDIR
fi
cd $NEW_IXDIR
if [ $? != 0 ]
then
echo "Error changing to new INFORMIXDIR">&2
fi
for dir in $IX_DIRS
do
if [ $MY_USER != "informix" ]
then
su informix -c "ln -s $EXISTING_IXDIR/$dir ."
else
ln -s $EXISTING_IXDIR/$dir .
fi
done
mkdir ${NEW_IXDIR}/dbssodir ${NEW_IXDIR}/aaodir ${NEW_IXDIR}/etc
cp -pR $EXISTING_IXDIR/etc/* $NEW_IXDIR/etc
cp -pR $EXISTING_IXDIR/dbssodir/* $NEW_IXDIR/dbssodir
cp -pR $EXISTING_IXDIR/aaodir/* $NEW_IXDIR/aaodir
if [ -d $EXISTING_IXDIR/ssl ]
then
mkdir ${NEW_IXDIR}/ssl
cp -pR $EXISTING_IXDIR/ssl $NEW_IXDIR/ssl
fi
if [ -d $EXISTING_IXDIR/tmp ]
then
mkdir ${NEW_IXDIR}/tmp
fi
case ${GROUPS_FLAG} in
1)
if [ "X${WARN_FLAG}" = "X0" ]
then
chown informix:${DBSSO_GROUP} $NEW_IXDIR/dbssodir
chown informix:${DBSA_GROUP} $NEW_IXDIR/etc
chown informix:${AAO_GROUP} $NEW_IXDIR/aaodir
#Should ssl and tmp belong to group informix or DBSA_GROUP?
if [ -d $NEW_IXDIR/ssl ]
then
chown informix:${DBSA_GROUP} $NEW_IXDIR/ssl
fi
if [ -d $NEW_IXDIR/tmp ]
then
chown informix:informix $NEW_IXDIR/tmp
fi
else
#If WARN_FLAG = 1 then we are informix and we don't belong to all the groups
echo "User informix does not belong to all the specified groups ( ${DBSA_GROUP} , ${AAO_GROUP}, ${DBSSO_GROUP} ) "
echo "These commands will have to be run by root:"
echo chown informix:${DBSSO_GROUP} $NEW_IXDIR/dbssodir
echo chown informix:${DBSA_GROUP} $NEW_IXDIR/etc
echo chown informix:${AAO_GROUP} $NEW_IXDIR/aaodir
if [ -d $NEW_IXDIR/ssl ]
then
echo chown informix:${DBSA_GROUP} $NEW_IXDIR/ssl
fi
if [ -d $NEW_IXDIR/tmp ]
then
echo chown informix:informix $NEW_IXDIR/tmp
fi
fi
;;
0)
if [ ${MY_USER} = "root" ]
then
chown informix:informix $NEW_IXDIR/dbssodir
chown informix:informix $NEW_IXDIR/etc
chown informix:informix $NEW_IXDIR/aaodir
if [ -d $NEW_IXDIR/ssl ]
then
chown informix:${DBSA_GROUP} $NEW_IXDIR/ssl
fi
if [ -d $NEW_IXDIR/tmp ]
then
chown informix:informix $NEW_IXDIR/tmp
fi
fi
;;
*)
echo "Internal error: Invalid value for GROUPS_FLAG..." >&2
exit 1
;;
esac
chmod 770 ${NEW_IXDIR}/dbssodir ${NEW_IXDIR}/aaodir
chmod 775 ${NEW_IXDIR}/etc
if [ -d $NEW_IXDIR/ssl ]
then
chmod 770 $NEW_IXDIR/ssl
fi
if [ -d $NEW_IXDIR/tmp ]
then
chmod 770 $NEW_IXDIR/tmp
fi