#!/bin/bash set -u function msg () { echo -e "$*"; } function cmd () { msg "Executing: $*"; $*; return $?; } function bail () { msg "Error: $1"; exit ${2:-1}; } function usage () { msg "Usage:\n\t${0##*/} -u <user> -p <proj> [-f]\n"; exit 1; } declare Ckp= declare CkpMod= declare TemplateOwner=perforce declare TemplateStorageBase=/p4/1/tmp/dt declare TemplateStorage= declare Proj=Unset declare Passwd=Unset declare Port=Unset declare User=Unset declare TemplateSet=s1 declare TemplateName=${Proj}-${TemplateSet} declare RepoStorageBase=/p4/1/tmp/u declare RepoStorage= declare RemoteSpecFile= declare Version=1.0.4 declare -i DoFetch=0 declare -i Force=0 declare -i shiftArgs=0 set +u while [[ $# -gt 0 ]]; do case $1 in (-f) Force=1;; (-u) User=$2; shiftArgs=1;; (-p) Proj=$2; shiftArgs=1;; (-P) Passwd=$2; shiftArgs=1;; (-h) usage -h;; (-man) usage -man;; (-V) show_versions; exit 1;; (-v1) export VERBOSITY=1;; (-v2) export VERBOSITY=2;; (-v3) export VERBOSITY=3;; (-v4) export VERBOSITY=4;; (-v5) export VERBOSITY=5;; (-L) export P4U_LOG=$2; shiftArgs=1;; (-si) SilentMode=1;; (-n) export NO_OP=1;; (-D) set -x;; # Debug; use 'set -x' mode. (*) usageError "Unknown arg ($1)." ;; esac # Shift (modify $#) the appropriate number of times. shift; while [[ $shiftArgs -gt 0 ]]; do [[ $# -eq 0 ]] && usageError "Bad usage." shiftArgs=$shiftArgs-1 shift done done set -u #------------------------------------------------------------------------------ # Command Line Validation [[ $User == Unset || $Proj == Unset ]] && usage #------------------------------------------------------------------------------ # Main Program. msg "Started ${0##*/} v$Version at $(date).\n" export P4ENVIRO=/dev/null/.p4enviro export P4CONFIG=${P4CONFIG:-.p4config} export P4CONFIG=${P4CONFIG##*/} RepoStorage=${RepoStorageBase}/$User/$ TemplateStorage=${TemplateStorageBase}/${Proj}-${TemplateSet} if [[ -d $TemplateStorage/.p4root ]]; then msg "Using template $TemplateStorage." else bail "Could not find a suitable template. Checked: $TemplateStorage" fi RepoStorage=${RepoStorageBase}/${User}/${Proj} if [[ -d $RepoStorage ]]; then if [[ $Force -eq 1 ]]; then /bin/rm -rf $RepoStorage || bail "Failed to remove existing repo dir: $RepoStorage." else bail "Repo already exists at $RepoStorage." fi fi mkdir -p $RepoStorage || bail "Failed to create repo storage dir: $RepoStorage." msg "Snap/Cloning from $TemplateStorage to $RepoStorage." rsync -a $TemplateStorage/ $RepoStorage || bail "Failed to snap/clone template repo." msg "Massaging data". cd $RepoStorage/.p4root || bail "Failed to cd to $RepoStorage/.p4root" p4 admin checkpoint Ckp=$RepoStorage/.p4root/backups/back.ckp.1 CkpMod=${Ckp}.mod sed -e "s:@perforce@:@${User}@:g" \ $Ckp > $CkpMod # For safety, disable server vars so 'p4 init' doesn't go haywire on p4d. unset P4PORT P4ROOT P4JOURNAL P4LOG P4DEBUG P4AUDIT /bin/rm -rf $RepoStorage/.p4root/db.* p4d -r $RepoStorage/.p4root -jr $CkpMod grep -v P4USER= $RepoStorage/$P4CONFIG > $RepoStorage/${P4CONFIG}.1 grep -v P4PORT= $RepoStorage/${P4CONFIG}.1 > $RepoStorage/${P4CONFIG}.2 echo "P4PORT=rsh:/bin/sh -c \"umask 077 && exec p4d -i -J '\$configdir/.p4root/journal' -r '\$configdir/.p4root'\"" >> $RepoStorage/${P4CONFIG}.2 echo "P4USER=$User" >> $RepoStorage/${P4CONFIG}.2 mv $RepoStorage/${P4CONFIG}.2 $RepoStorage/${P4CONFIG} Port=$(p4 -ztag -F %Address% remote -o origin) if [[ $Port == ssl:* ]]; then export P4TRUST=$RepoStorage/.p4trust cmd p4 -p $Port trust -y fi msg "\nAdding User $User to 'origin' remote spec." RemoteSpecFile=/tmp/remote.origin.$User.p4s p4 remote -o origin > $RemoteSpecFile echo "RemoteUser: $User" >> $RemoteSpecFile p4 remote -i < $RemoteSpecFile if [[ $Passwd != Unset ]]; then touch .p4passwd chmod 600 .p4passwd echo "$Passwd" > .p4passwd msg "P:[$(cat .p4passwd)]" msg "Logging in to master server." p4 login -r origin < .p4passwd rm -f .p4passwd fi p4 login -r origin -s > /dev/null 2>&1 if [[ $? -eq 0 ]]; then DoFetch=1 else msg "\nSkipping auto fetch due to not being logged in to mastser server. Please do:\n\tp4 login -r origin\n\tp4 fetch\n" fi if [[ $DoFetch -eq 1 ]]; then msg "\nFetching." p4 fetch fi msg "\nDone. Enjoy your repo in: $RepoStorage" msg "That took $(($SECONDS/3600)) hours $(($SECONDS%3600/60)) minutes $(($SECONDS%60)) seconds.\n" exit 0
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 19956 | Perforce maintenance | Refactored. | ||
#5 | 19955 | Perforce maintenance | Added notes. | ||
#4 | 19953 | Perforce maintenance |
flexclone.sh is taking shape. Added test script. |
||
#3 | 19952 | Perforce maintenance | Milestone PoC. | ||
#2 | 19951 | Perforce maintenance | wip. | ||
#1 | 19950 | Perforce maintenance | Added flexclone script, wip. |