mkdirs.sh #8

  • //
  • guest/
  • robert_cowham/
  • perforce/
  • sdp/
  • Server/
  • Unix/
  • setup/
  • mkdirs.sh
  • View
  • Commits
  • Open Download .zip Download (18 KB)
#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
#------------------------------------------------------------------------------
#
# Change the first three variables below to match the volume names on the machine
# you are configuring the SDP on. 
# Set the remaining variables appropriately. The meaning of each should be obvious.
# Change the first three variables below to match the volume names on the machine
# you are configuring the SDP on.
# Set the remaining variables appropriately. The meaning of each should be obvious.
# Before running this script, create a configuration file.  You can use a
# single configuration file named mkdirs.cfg in the same directory as this
# mkdirs.sh script. Alternately, you can create a file named mkdirs.N.cfg,
# where 'N' is the name of the instance you intend to configure.
#
# Run this script as root, and pass in the instance number you are configuring.
#
# If you do not have root access, then some commands will be skipped, and you
# will need to have the defined $P4DIR directory already existing (created by
# the root user and the ownership changed to the OS user that you are planning
# to run Perforce under). The /hxmetadata*, /hxdepots and /hxlogs volumes will
# also need to be owned by the OS user as well in order for the script to work.
# You can then run this script as the OS user for Perforce and everything
# should work fine.
#
# This script creates an init script in the $P4DIR/$SDP_INSTANCE/bin directory.
# You can use it from there if you are configuring a cluster, or you can link
# it in /etc/init.d if you are setting up a stand alone machine.  Sample
# systemd service files are included in the systemd folder.
#
# After running this script, set up the crontab based on templates
# generated in $P4DIR/common/etc/cron.d.  For convenience, a sample generated
# is to $P4DIR/p4.crontab.
#
# Next, put the license file in place in the P4ROOT dir, and launch the server with the init
# script.
#
# Then run $P4DIR/common/bin/p4master_run <instance> $P4DIR/common/bin/live_checkpoint.sh
# and then run both the daily_checkpoint.sh and recreate_db_checkpoint.sh to
# make sure everything is working before setting up the crontab.
#
# Also run $P4DIR/common/bin/p4master_run <instance> $P4DIR/common/bin/p4review.py <instance>
# to make sure the review script is working properly.  If you intend to use
# Swarm, you can skip configuration of the review daemon, and instead configure
# Swarm to handle review-style email notifications.
#
# UPGRADING SDP
# Specify the -test parameter to the script.
# In this case the script will NOT make the various directories under $P4DIR,
# but will instead create /tmp/p4 directory structure with the various files
# processed via templates etc. You can then manually compare this directory
# structure with your existing $P4DIR structure and manually copy the various
# files into it. For a more sophisticated approch using, see the
# 'hms_ts_setup.sh' script in the hms subdirectory.

set -u

function msg () { echo -e "$*"; }
function errmsg () { msg "\nError: $*" >&2; }
function warnmsg () { msg "\nWarning: $*"; }
function bail() { errmsg "${1:-Unknown Error}\n" >&2; exit ${2:-1}; }
function usage () {
   msg "Usage:\n\t${0##*/} <instance> [-test]\n"
   exit 1
}

declare -i DoChownCommands=1

if [ $# -lt 1 ] || [ $# -gt 2 ]; then
   usage
fi

# Verify instance value.
SDP_INSTANCE=$1
if [[ "$SDP_INSTANCE" == "-test" ]]; then
    bail "An instance argument is required."
fi

# Note that if the following is set to 1 then a trial run is done, into /tmp/p4
TEST=0
if [[ $# -gt 1 && "$2" == "-test" ]]; then
   TEST=1
fi

# Check for config file - same dir as this script
if [[ -r "${0%/*}/mkdirs.${SDP_INSTANCE}.cfg" ]]; then
   mkdirs_config="${0%/*}/mkdirs.${SDP_INSTANCE}.cfg"
elif [[ -r "${0%/*}/mkdirs.cfg" ]]; then
   mkdirs_config="${0%/*}/mkdirs.cfg"
else
   bail "Missing mkdirs config file $mkdirs_config."
fi

source $mkdirs_config || bail "Failed to source $mkdirs_config."

if [[ -r $SDP/Version ]]; then
   SDP_VERSION="$(cat $SDP/Version)"
else
   SDP_VERSION="Rev. SDP/Unix/UNKNOWN"
fi

P4DIR=/p4
P4SERVER=p4_$SDP_INSTANCE

export AWK=awk
export ID=id
export MAIL=mail

OS=`uname`
if [[ "${OS}" = "SunOS" ]] ; then
  export AWK=/usr/xpg4/bin/awk
  export ID=/usr/xpg4/bin/id
  export MAIL=mailx
elif [[ "${OS}" = "AIX" ]] ; then
  export AWK=awk
  export ID=id
  export MAIL=mail
fi

if [[ `$ID -u` -eq 0 ]]; then
   msg "Verified: Running as root."
elif [[ `whoami` == $OSUSER ]]; then
   warnmsg "Not running as root; chown commands will be skipped and basic directories must exist.\n"
   DoChownCommands=0
else
   bail "$0 must be run as as root or $OSUSER.\n"
fi

if [[ $TEST -eq 1 ]]; then
  DD=tmp
  MD=tmp
  LG=tmp
  CN=tmp
  P4DIR=/tmp/p4
  msg "\n*********  -test specified - will install to $P4DIR  *********\n"
fi

SDP_COMMON=$SDP/Server/Unix/p4/common

declare -i PreflightOK=1

[[ -f $SDP_COMMON/bin/p4 ]] || { errmsg "No p4 in $SDP_COMMON/bin"; PreflightOK=0; }
[[ -f $SDP_COMMON/bin/p4d ]] || { errmsg "No p4d in $SDP_COMMON/bin"; PreflightOK=0; }
[[ -f $SDP_COMMON/bin/p4p ]] || warnmsg "No p4p in $SDP_COMMON/bin"
[[ -f $SDP_COMMON/bin/p4broker ]] || warnmsg "No p4broker in $SDP_COMMON/bin"

if [[ $TEST -eq 1 && ! -d "$P4DIR" ]]; then
   mkdir "$P4DIR" || bail "Failed to create $P4DIR."
fi

# If we aren't running as root, extend the preflight checks to verify basic dirs
# exist.
if [[ `$ID -u` -ne 0 && $TEST -eq 0 ]]; then
   for d in "$P4DIR" "/$DD" "/$DB1" "/$DB2" "/$LG"; do
      if [[ -d "$d" ]]; then
         dirOwner=$(ls -ld "$d" | $AWK '{print $3}')
         dirGroup=$(ls -ld "$d" | $AWK '{print $4}')
         if [[ "$dirOwner" != "$OSUSER" ]]; then
            errmsg "Dir [$d] exists but with wrong owner, $dirOwner instead of $OSUSER."
            PreflightOK=0
         fi
         if [[ "$dirGroup" != "$OSGROUP" ]]; then
            warnmsg "Dir [$d] exists but with wrong group, $dirGroup instead of $OSGROUP."
         fi
      else
         errmsg "Dir must exist if not running as root: $d"
         PreflightOK=0
      fi
   done
fi

if [[ $PreflightOK -eq 1 ]]; then
   msg "Verified: Preflight checks passed."
else
   bail "Aborting due to failed preflight checks."
fi

if [[ $TEST -eq 0 ]]; then
   chmod 755 $SDP_COMMON/bin/p4
   chmod 700 $SDP_COMMON/bin/p4d
fi

[[ -f $SDP_COMMON/bin/p4broker ]] && chmod 700 $SDP_COMMON/bin/p4broker
[[ -f $SDP_COMMON/bin/p4web ]] && chmod 700 $SDP_COMMON/bin/p4web
[[ -f $SDP_COMMON/bin/p4p ]] && chmod 700 $SDP_COMMON/bin/p4p

# Make sure you update the p4 and p4d to the latest versions in the
# sdp/Server/Unix/p4/common/bin directory when making new instances at a later date.

P4RELNUM=`$SDP_COMMON/bin/p4 -V | grep -i Rev. | $AWK -F / '{print $3}'`
P4BLDNUM=`$SDP_COMMON/bin/p4 -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`
P4DRELNUM=`$SDP_COMMON/bin/p4d -V | grep -i Rev. | $AWK -F / '{print $3}'`
P4DBLDNUM=`$SDP_COMMON/bin/p4d -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`

[[ -d $P4DIR ]] || mkdir $P4DIR

[[ -d /$DD/p4 ]] || mkdir /$DD/p4
[[ -d /$DB1/p4 ]] || mkdir /$DB1/p4
[[ -d /$DB2/p4 ]] || mkdir /$DB2/p4
[[ -d /$LG/p4 ]] || mkdir /$LG/p4

mkdir -p /$DD/p4/$SDP_INSTANCE/bin
mkdir -p /$LG/p4/$SDP_INSTANCE/tmp
mkdir -p /$DD/p4/$SDP_INSTANCE/depots
mkdir -p /$DD/p4/$SDP_INSTANCE/checkpoints

case "$SERVER_TYPE" in 
   (p4d_standby)
      mkdir -p /$LG/p4/$SDP_INSTANCE/journals.rep
      if [[ $DoChownCommands -eq 1 ]]; then
         chown $OSUSER:$OSGROUP /$LG/p4/$SDP_INSTANCE/journals.rep
      fi
   ;;
   (p4d_replica|p4d_edge)
      mkdir -p /$DD/p4/$SDP_INSTANCE/checkpoints.${REPLICA_ID#p4d_}
      if [[ $DoChownCommands -eq 1 ]]; then
         chown $OSUSER:$OSGROUP /$LD/p4/$SDP_INSTANCE/checkpoints.${REPLICA_ID#p4d_}
      fi
   ;;
esac

[[ -d $P4DIR/ssl ]] || mkdir -p $P4DIR/ssl
[[ -f $SDP/Server/Unix/p4/ssl/config.txt && ! -f $P4DIR/ssl/config.txt ]] &&\
   cp $SDP/Server/Unix/p4/ssl/config.txt $P4DIR/ssl/
[[ -d /$CN/p4/common/bin ]] || mkdir -p /$CN/p4/common/bin
[[ -d /$CN/p4/common/config ]] || mkdir -p /$CN/p4/common/config

mkdir -p /$DB1/p4/$SDP_INSTANCE/db1/save
mkdir -p /$DB2/p4/$SDP_INSTANCE/db2/save
mkdir -p /$LG/p4/$SDP_INSTANCE/logs

if [[ $TEST -eq 0 ]]; then
    cd /$DD/p4/$SDP_INSTANCE
else
    cd $P4DIR/$SDP_INSTANCE
fi

if [[ $TEST -eq 0 ]]; then
   [[ -L root ]] || ln -s /$DB1/p4/$SDP_INSTANCE/db1 root
   [[ -L offline_db ]] || ln -s /$DB2/p4/$SDP_INSTANCE/db2 offline_db
   if [[ ! -d logs ]]; then
      [[ -L logs ]] || ln -s /$LG/p4/$SDP_INSTANCE/logs
   fi

   case "$SERVER_TYPE" in 
      (p4d_standby)
         if [[ ! -d journals.rep ]]; then
            [[ -L journals.rep ]] || ln -s /$LG/p4/$SDP_INSTANCE/journals.rep
         fi
      ;;
   esac

   if [[ ! -d tmp ]]; then
      [[ -L tmp ]] || ln -s /$LG/p4/$SDP_INSTANCE/tmp
   fi
   cd $P4DIR
   [[ -L $SDP_INSTANCE ]] || ln -s /$DD/p4/$SDP_INSTANCE
   [[ -L sdp ]] || ln -s $SDP $P4DIR/sdp
   [[ -L common ]] || ln -s /$CN/p4/common
fi

case "$SERVER_TYPE" in
   (p4d_master|p4d_edge)
      SERVERID=$MASTER_ID
      echo $SERVERID > $P4DIR/$SDP_INSTANCE/root/server.id
   ;;
   (p4d_replica|p4d_standby)
      SERVERID=$REPLICA_ID
      echo $SERVERID > $P4DIR/$SDP_INSTANCE/root/server.id
   ;;
   (*)
      SERVERID=$SERVER_TYPE
   ;;
esac

[[ -f /$CN/p4/common/bin/p4_$P4RELNUM.$P4BLDNUM ]] || cp $SDP_COMMON/bin/p4 /$CN/p4/common/bin/p4_$P4RELNUM.$P4BLDNUM
[[ -f /$CN/p4/common/bin/p4d_$P4DRELNUM.$P4DBLDNUM ]] || cp $SDP_COMMON/bin/p4d /$CN/p4/common/bin/p4d_$P4DRELNUM.$P4DBLDNUM

if [[ ! -f /$CN/p4/common/bin/p4_vars ]]; then
   cp -R $SDP_COMMON/bin/* /$CN/p4/common/bin

   # Copy certain subdirs of /p4/common if don't already exist.
   for dir in etc hms lib; do
      if [[ ! -d /$CN/p4/common/$dir ]]; then
         cp -pr $SDP_COMMON/$dir /$CN/p4/common/.
      fi
   done

   cd /$CN/p4/common/bin
   ln -s p4_$P4RELNUM.$P4BLDNUM p4_${P4RELNUM}_bin
   ln -s p4d_$P4DRELNUM.$P4DBLDNUM p4d_${P4DRELNUM}_bin
   ln -s p4_${P4RELNUM}_bin p4_bin

   sed -e "s:REPL_SDPVERSION:${SDP_VERSION}:g" \
      -e "s/REPL_OSUSER/${OSUSER}/g" \
      $SDP_COMMON/config/p4_vars.template > p4_vars
fi

cd /$CN/p4/common/bin

ln -s p4d_${P4DRELNUM}_bin p4d_${SDP_INSTANCE}_bin

if [[ ! -e /$CN/p4/common/config/.p4passwd.${P4SERVER}.admin ]]; then
   echo $P4ADMINPASS > /$CN/p4/common/config/.p4passwd.${P4SERVER}.admin
else
   warnmsg "Skipping update of existing admin password file /$CN/p4/common/config/.p4passwd.${P4SERVER}.admin"
fi

if [[ ! -e /$CN/p4/common/config/.p4passwd.${P4SERVER}.service ]]; then
   echo $P4SERVICEPASS > /$CN/p4/common/config/.p4passwd.${P4SERVER}.service
else
   warnmsg "Skipping update of existing service password file /$CN/p4/common/config/.p4passwd.${P4SERVER}.service"
fi

# Create broker links if broker exists
if [[ -f $SDP_COMMON/bin/p4broker ]]; then
   P4BRELNUM=`$SDP_COMMON/bin/p4broker -V | grep -i Rev. | $AWK -F / '{print $3}'`
   P4BBLDNUM=`$SDP_COMMON/bin/p4broker -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`
   [[ -f /$CN/p4/common/bin/p4broker_$P4BRELNUM.$P4BBLDNUM ]] || cp $SDP_COMMON/bin/p4broker /$CN/p4/common/bin/p4broker_$P4BRELNUM.$P4BBLDNUM
   [[ -L p4broker_${P4BRELNUM}_bin ]] && unlink p4broker_${P4BRELNUM}_bin
   ln -s p4broker_$P4BRELNUM.$P4BBLDNUM p4broker_${P4BRELNUM}_bin
   [[ -L p4broker_${SDP_INSTANCE}_bin ]] && unlink p4broker_${SDP_INSTANCE}_bin
   ln -s p4broker_${P4BRELNUM}_bin p4broker_${SDP_INSTANCE}_bin
   cd $P4DIR/$SDP_INSTANCE/bin
   [[ -L p4broker_${SDP_INSTANCE} ]] || ln -s $P4DIR/common/bin/p4broker_${SDP_INSTANCE}_bin p4broker_${SDP_INSTANCE}
   sed "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" $SDP_COMMON/etc/init.d/p4broker_instance_init.template > p4broker_${SDP_INSTANCE}_init
   chmod +x p4broker_${SDP_INSTANCE}_init
fi

# Create p4p links if p4p exists
cd /$CN/p4/common/bin
if [[ -x $SDP_COMMON/bin/p4p ]]; then
   P4PRELNUM=`$SDP_COMMON/bin/p4p -V | grep -i Rev. | $AWK -F / '{print $3}'`
   P4PBLDNUM=`$SDP_COMMON/bin/p4p -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`
   [[ -f /$CN/p4/common/bin/p4p_$P4PRELNUM.$P4PBLDNUM ]] || cp $SDP_COMMON/bin/p4p /$CN/p4/common/bin/p4p_$P4PRELNUM.$P4PBLDNUM
   [[ -L p4p_${P4PRELNUM}_bin ]] && unlink p4p_${P4PRELNUM}_bin
   ln -s p4p_$P4PRELNUM.$P4PBLDNUM p4p_${P4PRELNUM}_bin
   [[ -L p4p_${SDP_INSTANCE}_bin ]] && unlink p4p_${SDP_INSTANCE}_bin
   ln -s p4p_${P4PRELNUM}_bin p4p_${SDP_INSTANCE}_bin
   cd $P4DIR/$SDP_INSTANCE/bin
   [[ -L p4p_${SDP_INSTANCE} ]] || ln -s $P4DIR/common/bin/p4p_${SDP_INSTANCE}_bin p4p_${SDP_INSTANCE}
   sed -e "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" \
      -e "s/REPL_DNSNAME/${P4DNSNAME}/g" \
      $SDP_COMMON/etc/init.d/p4p_instance_init.template > p4p_${SDP_INSTANCE}_init
   chmod +x p4p_${SDP_INSTANCE}_init
   mkdir -p /$DD/p4/$SDP_INSTANCE/cache
fi

cd $P4DIR/$SDP_INSTANCE/bin
ln -s $P4DIR/common/bin/p4_bin p4_$SDP_INSTANCE

sed "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" \
   $SDP_COMMON/etc/init.d/p4d_instance_init.template > p4d_${SDP_INSTANCE}_init
chmod +x p4d_${SDP_INSTANCE}_init

# Moved the less commonly used, but always created init scripts to an init directory.
mkdir init
cd init

sed "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" \
   $SDP_COMMON/etc/init.d/p4dtg_instance_init.template > p4dtg_${SDP_INSTANCE}_init
chmod +x p4dtg_${SDP_INSTANCE}_init

cd ..

if [[ $CASE_SENSITIVE -eq 1 ]]; then
   ln -s $P4DIR/common/bin/p4d_${SDP_INSTANCE}_bin p4d_$SDP_INSTANCE
else
   echo '#!/bin/bash' > p4d_$SDP_INSTANCE
   echo P4D=/p4/common/bin/p4d_${SDP_INSTANCE}_bin >> p4d_$SDP_INSTANCE
   echo 'exec $P4D -C1 "$@"' >> p4d_$SDP_INSTANCE
   chmod +x p4d_$SDP_INSTANCE
fi

cd $P4DIR/common/config

sed -e "s/REPL_MAILTO/${MAILTO}/g" \
   -e "s/REPL_MAILFROM/${MAILFROM}/g" \
   -e "s/REPL_ADMINUSER/${ADMINUSER}/g" \
   -e "s/REPL_MASTER_ID/${MASTER_ID}/g" \
   -e "s/REPL_SSLPREFIX/${SSL_PREFIX}/g" \
   -e "s/REPL_P4PORT/${P4_PORT}/g" \
   -e "s/REPL_P4BROKERPORT/${P4BROKER_PORT}/g" \
   -e "s/REPL_P4WEBPORT/${P4WEB_PORT}/g" \
   -e "s/REPL_P4FTPPORT/${P4FTP_PORT}/g" \
   -e "s/REPL_DNSNAME/${P4DNSNAME}/g" \
   -e "s/REPL_P4P_TARGET_PORT/${P4P_TARGET_PORT}/g" \
   $SDP_COMMON/config/instance_vars.template > p4_${SDP_INSTANCE}.vars

sed -e "s/REPL_ADMINISTRATOR/${MAILTO}/g" \
   -e "s/REPL_COMPLAINFROM/${COMPLAINFROM}/g" \
   -e "s/REPL_MAILHOST/${MAILHOST}/g" \
   -e "s/REPL_DNSNAME/${P4DNSNAME}/g" \
   $SDP_COMMON/config/p4review.cfg.template > p4_${SDP_INSTANCE}.p4review.cfg

cd $P4DIR
if [[ ! -f ${P4DIR}/p4.crontab ]]; then
   CRONTAB_NAME=p4.crontab
else
   CRONTAB_NAME=p4.crontab.new
   rm -f ${P4DIR}/$CRONTAB_NAME > /dev/null 2>&1
   msg "Existing crontab found, writing new crontab to ${P4DIR}/${CRONTAB_NAME}"
fi

sed -e "s/REPL_MAILTO/${MAILTO}/g" \
   -e "s/REPL_MAILFROM/${MAILFROM}/g" \
   -e "s/REPL_INSTANCE/${SDP_INSTANCE}/g" \
   $SDP_COMMON/etc/cron.d/template.crontab.combined > $CRONTAB_NAME

cd $P4DIR/${SDP_INSTANCE}/bin

if [[ "$SHAREDDATA" == "TRUE" ]]; then
   if [[ "$SERVER_TYPE" == p4d_replica || "$SERVER_TYPE" == p4d_standby ]]; then
      msg "Configuring Replica sharing depot data with master, skipping chown/chmod of depot files"
      DoChownCommands=0
   fi
fi

if [[ $DoChownCommands -eq 1 ]]; then
   if [[ $TEST -eq 0 ]]; then
      chown $OSUSER:$OSGROUP /$DD
      chown $OSUSER:$OSGROUP /$LG
      chown $OSUSER:$OSGROUP /$DB1
      chown $OSUSER:$OSGROUP /$DB2
   fi
   chown $OSUSER:$OSGROUP /$DD/p4
   chown $OSUSER:$OSGROUP /$LG/p4
   chown $OSUSER:$OSGROUP /$DB1/p4
   chown $OSUSER:$OSGROUP /$DB2/p4

   chown -h $OSUSER:$OSGROUP $P4DIR
   chown -h $OSUSER:$OSGROUP $P4DIR/$SDP_INSTANCE
   chown -h $OSUSER:$OSGROUP $P4DIR/common
   [[ $TEST -eq 0 ]] && chown -h $OSUSER:$OSGROUP $P4DIR/sdp
   chown $OSUSER:$OSGROUP $P4DIR/*

   chown -Rh $OSUSER:$OSGROUP $P4DIR/common
   [[ $TEST -eq 0 ]] && chown -Rh $OSUSER:$OSGROUP $P4DIR/sdp
   chown -Rh $OSUSER:$OSGROUP /$CN/p4/common
   chown -Rh $OSUSER:$OSGROUP /$DB1/p4/$SDP_INSTANCE
   chown -Rh $OSUSER:$OSGROUP /$DB2/p4/$SDP_INSTANCE
   chown -Rh $OSUSER:$OSGROUP /$LG/p4/$SDP_INSTANCE

   if [[ "$SHAREDDATA" == "FALSE" ]]; then
      msg "Setting ownership on depot files - this may take some time ..."
      chown -Rh $OSUSER:$OSGROUP /$DD/p4/$SDP_INSTANCE
   fi
else
   msg "Skipped chown/chmod commands for large directory trees."
fi

chmod 700 /$DB1/p4
chmod 700 /$DB2/p4
chmod 700 /$DD/p4
chmod 700 /$LG/p4

chmod -R 700 /$DB1/p4/$SDP_INSTANCE
chmod -R 700 /$DB2/p4/$SDP_INSTANCE
chmod -R 700 /$CN/p4/common
chmod -R 700 /$LG/p4/$SDP_INSTANCE

if [[ "$SHAREDDATA" == "FALSE" ]]; then
   msg "Setting permissions on depot files - this may take some time ..."
   chmod -R 700 /$DD/p4/$SDP_INSTANCE
fi

if [[ $SDP_INSTANCE != $MASTERINSTANCE ]]; then
   if [[ -f $P4DIR/$MASTERINSTANCE/root/license ]]; then
      ln -s $P4DIR/$MASTERINSTANCE/root/license $P4DIR/$SDP_INSTANCE/root/license
      chown -h $OSUSER:$OSGROUP $P4DIR/$SDP_INSTANCE/root/license
   fi
fi

chmod 755 $P4DIR/${SDP_INSTANCE}/bin/*_init
chmod 755 $P4DIR/${SDP_INSTANCE}/bin/init/*_init
chmod 600 /$CN/p4/common/config/.p4passwd.${P4SERVER}.admin
chmod 600 /$CN/p4/common/config/.p4passwd.${P4SERVER}.service
[[ -e /$CN/p4/common/bin/*.cfg ]] && chmod 600 /$CN/p4/common/bin/*.cfg
[[ -e /$CN/p4/common/bin/*.html ]] && chmod 600 /$CN/p4/common/bin/*.html
chmod 700 $P4DIR/ssl
[[ -e $P4DIR/ssl/* ]] && chmod 600 $P4DIR/ssl/*

if [[ $TEST -eq 1 ]]; then
   msg "
This was done in TEST mode - please run the following command to see any changes should be
applied to your live environment (manually):

diff -r /p4/$SDP_INSTANCE/bin $P4DIR/$SDP_INSTANCE/bin
diff -r /p4/common $P4DIR/common

If upgrading an older SDP version then be careful to ensure files in /p4/common/config are correct
and update that /p4/common/bin/p4_vars is appropriate.\n"
fi

exit 0
# Change User Description Committed
#9 25113 Robert Cowham Merge latest changes from dev
#8 23483 Robert Cowham Merge in latest changes from dev - includes the mkrep changes.
#7 23430 Robert Cowham Merge in changes from dev
#6 23205 Robert Cowham Merged all changes from dev to test
#5 22477 Robert Cowham Bring latest dev changes into test
#4 22143 Robert Cowham All mkdirs to be run from another dir
       Tweak config order for mail
#3 22142 Robert Cowham Merge in latest changes from Dev
#2 20726 Robert Cowham Catch up from dev
#1 18586 Robert Cowham Branching using cowhamr.sdp.dev
//guest/perforce_software/sdp/dev/Server/Unix/setup/mkdirs.sh
#22 18203 richard_baum Removed hard-coded /p4 path for server.id file location.
 This fixes "-test" mode so server.id file is written to the correct location. Without this it is written to /p4 where there could be an installation with the same instance ID.  In that case the server.id file could get overwritten with different data.  If there is not an existing instance an error message would be displayed.  Now neither of these should occur :-)

Also fixed some typos.
#21 16563 C. Thomas Tyler Routine Merge Down to dev from main using:
p4 merge -b perforce_software-sdp-dev
p4 resolve -as
#20 16373 C. Thomas Tyler Routine Merge Down to dev from main using:
p4 merge -b perforce_software-sdp-dev
#19 16335 C. Thomas Tyler Routine Merge Down to dev from main using:
p4 merge -b perforce_software-sdp-dev
#18 16029 C. Thomas Tyler Routine merge to dev from main using:
p4 merge -b perforce_software-sdp-dev
#17 15701 C. Thomas Tyler Routine merge down using 'p4 merge -b perforce_software-sdp-dev'.
#16 14136 C. Thomas Tyler Routine merge down to dev from main for SDP
using perforce_software-sdp-dev.
#15 14038 C. Thomas Tyler Routine merge-down to SDP dev from main.
#14 13906 C. Thomas Tyler Normalized P4INSTANCE to SDP_INSTANCE to get Unix/Windows
implementations in sync.

Reasons:
1. Things that interact with SDP in both Unix and Windows
environments shoudn't have to account for this obscure
SDP difference between Unix and Windows.  (I came across
this doing CBD work).

2. The Windows and Unix scripts have different variable
names for defining the same concept, the SDP instance.
Unix uses P4INSTANCE, while Windows uses SDP_INSTANCE.

3. This instance tag, a data set identifier, is an SDP concept.
I prefer the SDP_INSTANCE name over P4INSTANCE, so I prpose
to normalize to SDP_INSTANCE.

4. The P4INSTANCE name makes it look like a setting that might be
recognized by the p4d itself, which it is not.  (There are other
such things such as P4SERVER that could perhaps be renamed as
a separate task; but I'm not sure we want to totally disallow
the P4 prefix for variable names. It looks too right to be wrong
in same cases, like P4BIN and P4DBIN.  That's a discussion for
another day, outside the scope of this task).

Meanwhile:
* Fixed a bug in the Windows 2013.3 upgrade script that
was referencing undefined P4INSTANCE, as the Windows
environment defined only SDP_INSTANCE.

* Had P4INSTANCE been removed completely, this change would
likely cause trouble for users doing updates for existing
SDP installations.  So, though it involves slight technical debt,
I opted to keep a redundant definition of P4INSTANCE
in p4_vars.template, with comments indicating SDP_INSTANCE should be
used in favor of P4INSTANCE, with a warning that P4INSTANCE
may go away in a future release.  This should avoid unnecessary
upgrade pain.

* In mkdirs.sh, the varialbe name was INSTANCE rather than
SDP_INSTANCE.  I changed that as well.  That required manual
change rather than sub/replace to avoid corrupting other similar
varialbe names (e.g.  MASTERINSTANCE).

This is a trivial change technically (a substitute/replace, plus
tweaks in p4_vars.template), but impacts many files.
#13 13586 C. Thomas Tyler Routine merge down from main -> dev.
Trivial merges, all resolved with 'p4 resolve -as.'
#12 12923 C. Thomas Tyler Routine merge down from main to dev.
Resolved with 'p4 resolve -as', no merges or conflicts.
#11 12170 Russell C. Jackson (Rusty) Merged in changes in Main
#10 12116 Russell C. Jackson (Rusty) Update dev from main.
#9 12107 C. Thomas Tyler Routine merge down from 'main' to 'dev', resolved with
'p4 resolve -as'.
#8 12028 C. Thomas Tyler Refreshed SDP dev branch, merging down from main.
#7 11523 Russell C. Jackson (Rusty) Modified P4BROKERPORTNUM to just be the port number and added P4BROKERPORT to instance_vars
 to be consistent with P4PORT. Also makes it easier to modify p4review.py to use P4BROKERPORT
 rather than P4PORT for the subject line when needed.
#6 11490 Russell C. Jackson (Rusty) Added SSL_PREFIX back and P4MASTERPORTNUM in order to support the sync_replica.sh
and weekly_sync_replica.sh scripts.
#5 11477 Russell C. Jackson (Rusty) Updated to use /usr/bin/env python

Added workshop header.

 Changed cfg to config.
#4 11474 Russell C. Jackson (Rusty) Had to move the cfg directory to the metadata volume and link it under the instance
directory to provide the proper separation in a shared volume environment. The
 instance specific vars cannot be in a shared directory since they need to be different
 on each node using the shared volume.

 Since the files moved back to the instance directory, I changed the names back to:
   instance_vars
   p4review.cfg
 to keep things simple.

 Also moved p4_vars.template to SDP/Server/Unix/p4/common/cfg so that it doesn't get
 copied to the /p4/common/bin folder. Plus, it makes more sense for it to be in that
 directory in the SDP structure.
#3 11468 Russell C. Jackson (Rusty) Added comments regarding configuring Edge and Edge replicas.
#2 11466 Russell C. Jackson (Rusty) Initial work to simplify p4_vars and remove cluster stuff.

 Testing of named instances surfaced some bugs that are in prod sdp,
 now fixed in dev.

 Added three triggers from RCJ SDP

 Moved p4review.cfg into the new /p4/common/cfg to go along with the
 instance_vars files. mkdirs.sh now generates an instance_p4review.cfg
 as well.

 Removed incremental p4verify to clean up a bit. It didn't support replicas
 and was really never used.

 All port settings now live in <instance>_vars file. You set what you want
 the ports to be in mkdirs.sh. There is no more fancy logic to try to guess
 what the port should be. You set it, and that is what it is.

 Remaining to do is to updated scripts to not need p4master_run. Saved
 that work for later since this is tested and works.
#1 10638 C. Thomas Tyler Populate perforce_software-sdp-dev.
//guest/perforce_software/sdp/main/Server/Unix/setup/mkdirs.sh
#1 10148 C. Thomas Tyler Promoted the Perforce Server Deployment Package to The Workshop.