# bbi_load_and_verify.lib Version=3.5.5 #============================================================================== # Copyright and license info is available in the LICENSE file included with # the P4BBI tool, and also available online: # https://swarm.workshop.perforce.com/view/p4bbi/main/LICENSE #------------------------------------------------------------------------------ #============================================================================== # BBI Library Functions. #------------------------------------------------------------------------------ # Function: check_p4_env # # Input: # Define (export) the P4CONFIG variable prior to calling this function. #------------------------------------------------------------------------------ function check_p4_env { vvmsg "CALL: check_p4_env($*)" declare -a errors declare -i errorCount=0 declare -i i=0 export P4CONFIG=${P4CONFIG:-Undefined} if [[ $P4CONFIG == Undefined ]]; then errmsg "P4CONFIG is not defined." return 1 fi runCmd "$P4BIN -s info -s" "Target Perforce Environment:" 0 || { errors[$errorCount]="The Perforce server is not responding." errorCount+=1 } if [[ "$($P4BIN protects -m 2>/dev/null)" == super ]]; then msg "Perforce super user access verified." else errors[$errorCount]="Perforce super user access could not be verified." errorCount+=1 fi if [[ $errorCount -eq 0 ]]; then msg "Verified: The Perforce environment is ready to receive imports." return 0 else msg "The following problems were identified:" i=0; while [[ $i -lt $errorCount ]]; do errmsg "${errors[$i]}" i+=1 done return 1 fi } #------------------------------------------------------------------------------ # Function: load_baselines # # Input: # $1 - BBI config file path # # Globals Modifiedq # * Baselines, associative array, indexed by baseline name, value is path. # # Return: # 0 - Baselines verified OK. # 1 - Errors detected. #------------------------------------------------------------------------------ function load_baselines { vvmsg "CALL: load_baselines($*)" declare bbiCfgFile=$1 declare reqVersion=$2 declare cfgVersion= declare baselineStorage= declare name= declare path= declare baselineOptions= declare line= declare -a errors declare -i errorCount=0 declare -i i=0 msg "Loading baseline definitions from [$bbiCfgFile]." if [[ ! -r "$bbiCfgFile" ]]; then errmsg "Cannot read BBI Config File [$bbiCfgFile]." return 1 fi while read line; do if [[ $line == VERSION=* ]]; then cfgVersion=$(echo $line | cut -d '=' -f 2) if [[ "$cfgVersion" > "$reqVersion" ]]; then msg "Verified: BBI config file version [$cfgVersion] meets minimum requirement." else errors[$errorCount]="BBI config file version [$cfgVersion] is too old. Must be at least ${reqVersion}.0." errorCount+=1 fi continue fi if [[ $line == BASELINE_STORAGE=* ]]; then baselineStorage=$(echo $line|cut -d '=' -f 2) if [[ $baselineStorage == \$* ]]; then baselineStorage=$(eval echo $baselineStorage) fi continue fi if [[ $line == GLOBAL_UPDATE_OPTIONS=* ]]; then GlobalUpdateOptions=$(echo $line|cut -d '=' -f 2) fi [[ $line == BASELINE* ]] || continue name=$(echo $line | cut -d '|' -f 2) path=$(echo $line | cut -d '|' -f 3) baselineOptions=$(echo $line | cut -d '|' -f 4) # If path is not an absolute path and baselineStorage is defined, prepend. if [[ $path != /* && -n "$baselineStorage" ]]; then path="$baselineStorage/$path" fi vvmsg "Line=[$line] N=[$name] P=[$path] O=[$baselineOptions]" Baselines[$name]="$path" BaselineOptions[$name]="$baselineOptions" case $path in (CMD:*) cmd=${path#CMD:} cmdExe=${cmd%% *} cmdExePath=$(which $cmdExe 2>/dev/null ||:) if [[ -z "$cmdExePath" ]]; then errors[$errorCount]="Command executable [$cmdExe] for baseline [$name] not found or not executable." errorCount+=1 fi ;; (*.tar.gz|*.tgz|*.tar|*.zip) if [[ ! -r "$path" ]]; then errors[$errorCount]="Baseline file [$path] does not exist." errorCount+=1 fi ;; (*) if [[ ! -r "$path" || ! -d "$path" ]]; then errors[$errorCount]="Baseline dir [$path] does not exist or is not a directory." errorCount+=1 fi ;; esac done < $bbiCfgFile if [[ -z "$cfgVersion" ]]; then errors[$errorCount]="BBI config file version is not defined with a 'VERSION=' tag." errorCount+=1 fi msg "${H}\nLoaded ${#Baselines[*]} baseline definitions:\n" printf "%-32s %-s\n" "Name" "Path" printf "%-32s %-s\n" "--------------------------------" "------------------------------------------" for name in ${!Baselines[*]}; do printf "%-32s %-s\n" "$name" "${Baselines[$name]}" done if [[ $errorCount -eq 0 ]]; then msg "\nVerified: All defined baselines are accessible." else msg "\nThe following problems were identified:" i=0; while [[ $i -lt $errorCount ]]; do errmsg "${errors[$i]}" i+=1 done fi if [[ $errorCount -eq 0 ]]; then return 0 else return 1 fi } #------------------------------------------------------------------------------ # Function: load_actions # # Input: # $1 - BBI config file path # # Globals Modified: # * ActionType array # # This is the main array of actions, the index of which applies to the other # arrays below. So if ActionType[3] is an Update, then the arrays for an UPDATE # action with that index will be defined, i.e. ActionBaseline[3], ActionPath1[3], # and ActionDesc[3], and optionally ActionUpdateOptions[3]. Different action types # have different parameters. # # * ActionBaseline array # * ActionDepotName array # * ActionDepotType array # * ActionPath1 array # * ActionPath2 array # * ActionDesc array # * ActionBranchSpecFile array # * ActionDepotSpecFile array # * ActionStreamSpecFile array # * ActionUpdateOptions array # * ActionStreamPath array # * ActionStreamType array # * ActionStreamOwner array # * ActionStreamDesc array # * ActionStreamOptions array # * ActionCount integer # # Action Types and their parameters: # BRANCH_SPEC|BranchSpecFile # CLIENT_SPEC|ClientSpecFile # DEPOT|Name|Type[|Desc] # DEPOT_SPEC|DepotSpecFile # UPDATE|Baseline|Path1|Desc[|ActionUpdateOptions] # POPULATE|Path1|Path2|Desc (or POPULATE|BRANCH_SPEC[-r]|BranchSpec|Desc) # COPY|Path1|Path2|Desc (or COPY|BRANCH_SPEC[-r]|BranchSpec|Desc) # MOVE|Path1|Path2|Desc # RECORD_MERGE|Path1|Path2|Desc (or RECORD_MERGE|BRANCH_SPEC[-r]|BranchSpec|Desc) # STREAM|StreamPath|StreamType|StreamParent|StreamDesc[|<StreamOptions>] # STREAM_SPEC|StreamSpecFile # # Return: # 0 - Actions loaded, syntax verified, refererenced baselines defined. # 1 - Errors detected. #------------------------------------------------------------------------------ function load_actions { vvmsg "CALL: load_actions($*)" declare bbiCfgFile=$1 declare actionType= declare baseline= declare path1= declare path2= declare desc= declare updateOption= declare updateOptions= declare branchSpecFile= declare depotSpecFile= declare streamSpecFile= declare streamPath= declare streamType= declare streamParent= declare streamDesc= declare streamOwner= declare streamOptions= declare injectionScript= declare injectionIndicator= declare line= declare -a errors declare -i errorCount=0 declare -i i=0 declare -i lineCount=0 msg "Loading action sequences from [$bbiCfgFile]." if [[ ! -r "$bbiCfgFile" ]]; then errmsg "Cannot read BBI Config File [$bbiCfgFile]." return 1 fi # The first action is artifically hard-coded to START_IMPORT. ActionType[$ActionCount]=START_IMPORT ActionCount+=1 while read line; do lineCount+=1 case $line in (\#*|BASELINE*|GLOBAL_UPDATE_OPTIONS*|NAME*|VERSION*) continue;; (BRANCH_SPEC*) # BRANCH_SPEC|BranchSpecFile ActionType[$ActionCount]=BRANCH_SPEC branchSpecFile="$BBIConfigDir/specs/$(echo $line | cut -d '|' -f 2).branch.p4s" ActionBranchSpecFile[$ActionCount]=$branchSpecFile ActionCount+=1 ;; (CLIENT_SPEC*) # CLIENT_SPEC|ClientSpecFile ActionType[$ActionCount]=CLIENT_SPEC clientSpecFile="$BBIConfigDir/specs/$(echo $line | cut -d '|' -f 2).client.p4s" ActionBranchSpecFile[$ActionCount]=$clientSpecFile ActionCount+=1 ;; (DEPOT_SPEC*) # DEPOT_SPEC|DepotSpecFile ActionType[$ActionCount]=DEPOT_SPEC depotSpecFile="$BBIConfigDir/specs/$(echo $line | cut -d '|' -f 2).depot.p4s" ActionDepotSpecFile[$ActionCount]=$depotSpecFile ActionCount+=1 ;; (STREAM_SPEC*) # STREAM_SPEC|StreamSpecFile ActionType[$ActionCount]=STREAM_SPEC streamSpecFile="$BBIConfigDir/specs/$(echo $line | cut -d '|' -f 2).stream.p4s" ActionStreamSpecFile[$ActionCount]=$streamSpecFile ActionCount+=1 ;; (DEPOT*) # DEPOT|Name|Type[|Desc] ActionType[$ActionCount]=DEPOT depotName="$(echo $line | cut -d '|' -f 2)" depotType="$(echo $line | cut -d '|' -f 3)" desc="$(echo $line | cut -d '|' -f 4)" [[ -z "$desc" ]] && desc="Created by $ImportUser." ActionDepotName[$ActionCount]="$depotName" ActionDepotType[$ActionCount]="$depotType" ActionDesc[$ActionCount]="$desc" ActionCount+=1 ;; (UPDATE*) # UPDATE|Baseline|Path1|Desc[|ActionUpdateOptions] ActionType[$ActionCount]=UPDATE baseline="$(echo $line | cut -d '|' -f 2)" path1="$(echo $line | cut -d '|' -f 3)" desc="$(echo $line | cut -d '|' -f 4)" updateOptions="$(echo $line | cut -d '|' -f 5) $GlobalUpdateOptions" updateOptions=$(echo $updateOptions) for updateOption in $updateOptions; do case $updateOption in (ASTYLE) ;; (DOS2UNIX) ;; (LABEL:*) label=$(echo ${updateOption##*LABEL:}) label=${label%% *} if [[ -z "$label" ]]; then errors[$errorCount]="LABEL option for UPDATE action on line $lineCount is malformed. Format is LABEL:YourLabelName." errorCount+=1 fi ;; (VERIFY) ;; (*) errors[$errorCount]="Invalid UPDATE option value ($updateOption) defined on line $lineCount. Valid options are ASTYLE, DOS2UNIX, LABEL:MyLabelName, and VERIFY." errorCount+=1 ;; esac done ActionBaseline[$ActionCount]="$baseline" ActionPath1[$ActionCount]="$path1" ActionDesc[$ActionCount]="$desc" ActionUpdateOptions[$ActionCount]="$updateOptions" set +u if [[ -z "${Baselines[$baseline]}" ]]; then errors[$errorCount]="Baseline [$baseline] referenced on line $lineCount is not defined." errorCount+=1 fi set -u ActionCount+=1 ;; # POPULATE and BRANCH are synonomous; POPULATE is the preferred term since this is now # implemented with the 'p4 populate' command. (POPULATE*|BRANCH*) # POPULATE|Path1|Path2|Desc # or: # POPULATE|BRANCH_SPEC[-r]|BranchSpec|Desc ActionType[$ActionCount]=POPULATE path1="$(echo $line | cut -d '|' -f 2)" path2="$(echo $line | cut -d '|' -f 3)" desc="$(echo $line | cut -d '|' -f 4)" ActionPath1[$ActionCount]="$path1" ActionPath2[$ActionCount]="$path2" ActionDesc[$ActionCount]="$desc" ActionCount+=1 ;; # COPY_MERGE and short form COPY are synonomous. (COPY*) # COPY|Path1|Path2|Desc # or: # COPY|BRANCH_SPEC[-r]|BranchSpecName|Desc ActionType[$ActionCount]=COPY path1="$(echo $line | cut -d '|' -f 2)" path2="$(echo $line | cut -d '|' -f 3)" desc="$(echo $line | cut -d '|' -f 4)" ActionPath1[$ActionCount]="$path1" ActionPath2[$ActionCount]="$path2" ActionDesc[$ActionCount]="$desc" ActionCount+=1 ;; # RENAME and short form MOVE are synonomous. (MOVE*|RENAME*) ActionType[$ActionCount]=MOVE path1="$(echo $line | cut -d '|' -f 2)" path2="$(echo $line | cut -d '|' -f 3)" desc="$(echo $line | cut -d '|' -f 4)" ActionPath1[$ActionCount]="$path1" ActionPath2[$ActionCount]="$path2" ActionDesc[$ActionCount]="$desc" ActionCount+=1 ;; # RECORD_AS_MERGED and short form RECORD_MERGE are synonomous. (RECORD_AS_MERGED*|RECORD_MERGE*) # RECORD_MERGE|Path1|Path2|Desc ActionType[$ActionCount]=RECORD_MERGE path1="$(echo $line | cut -d '|' -f 2)" path2="$(echo $line | cut -d '|' -f 3)" desc="$(echo $line | cut -d '|' -f 4)" ActionPath1[$ActionCount]="$path1" ActionPath2[$ActionCount]="$path2" ActionDesc[$ActionCount]="$desc" ActionCount+=1 ;; (STREAM*) # STREAM|StreamPath|StreamType|StreamParent[|StreamOwner[|StreamDesc[|<StreamOptions>]]] ActionType[$ActionCount]=STREAM streamPath="$(echo $line | cut -d '|' -f 2)" streamType="$(echo $line | cut -d '|' -f 3)" streamParent="$(echo $line | cut -d '|' -f 4)" streamOwner="$(echo $line | cut -d '|' -f 5)" [[ -z "$streamOwner" ]] && streamOwner="$ImportUser" streamDesc="$(echo $line | cut -d '|' -f 6)" [[ -z "$streamDesc" ]] && streamDesc="Created by $ImportUser." streamOptions="$(echo $line | cut -d '|' -f 7)" ActionStreamPath[$ActionCount]="$streamPath" ActionStreamType[$ActionCount]="$streamType" ActionStreamParent[$ActionCount]="$streamParent" ActionStreamOwner[$ActionCount]="$streamOwner" ActionStreamDesc[$ActionCount]="$streamDesc" ActionStreamOptions[$ActionCount]="$streamOptions" ActionCount+=1 ;; (*) [[ -z "$(echo $line)" ]] && continue actionType=${line%%\|*} errors[$errorCount]="Unprocessed action type [$actionType] on line $lineCount:\n$line\n" errorCount+=1 ;; esac done < $bbiCfgFile msg "${H}\nLoaded $((${#ActionType[*]}-1)) action sequences:\n" printf "%-3s %-17s %-s\n" "#" "Action" "Stuff" printf "%-3s %-17s %-s\n" "---" "----------------" "--------------------------------------------------------" i=1; while [[ $i -lt ${#ActionType[*]} ]]; do printf "%-3s %-16s " "$i" "${ActionType[$i]}" case ${ActionType[$i]} in (BRANCH_SPEC) msg "F=[${ActionBranchSpecFile[$i]}]" if [[ ! -r "${ActionBranchSpecFile[$i]}" ]]; then errors[$errorCount]="Missing branch spec file [${ActionBranchSpecFile[$i]}]." errorCount+=1 fi ;; (DEPOT_SPEC) msg "F=[${ActionDepotSpecFile[$i]}]" if [[ ! -r "${ActionDepotSpecFile[$i]}" ]]; then errors[$errorCount]="Missing depot spec file [${ActionDepotSpecFile[$i]}]." errorCount+=1 fi ;; (STREAM_SPEC) msg "F=[${ActionStreamSpecFile[$i]}]" if [[ ! -r "${ActionStreamSpecFile[$i]}" ]]; then errors[$errorCount]="Missing stream spec file [${ActionStreamSpecFile[$i]}]." errorCount+=1 fi ;; (DEPOT) msg "N=[${ActionDepotName[$i]}] T=[${ActionDepotType[$i]}] D=[${ActionDesc[$i]}]" ;; (UPDATE) injectionScript="$BBIConfigDir/injections/before_UPDATE_${ActionBaseline[$i]}.sh" if [[ -r "$injectionScript" ]]; then injectionIndicator="*INJ*" else injectionIndicator="" fi msg "B=[${ActionBaseline[$i]}]${injectionIndicator} P=[${ActionPath1[$i]}] D=[${ActionDesc[$i]}] A=[${ActionUpdateOptions[$i]}]" ;; (POPULATE) msg "P1=[${ActionPath1[$i]}] P2=[${ActionPath2[$i]}] D=[${ActionDesc[$i]}]" ;; (COPY) msg "P1=[${ActionPath1[$i]}] P2=[${ActionPath2[$i]}] D=[${ActionDesc[$i]}]" ;; (MOVE) msg "P1=[${ActionPath1[$i]}] P2=[${ActionPath2[$i]}] D=[${ActionDesc[$i]}]" ;; (RECORD_MERGE) msg "P1=[${ActionPath1[$i]}] P2=[${ActionPath2[$i]}] D=[${ActionDesc[$i]}]" ;; (STREAM) msg "P=[${ActionStreamPath[$i]}] T=[${ActionStreamType[$i]}] MOM=[${ActionStreamParent[$i]}] O=[${ActionStreamOwner[$i]}] D=[${ActionStreamDesc[$i]}] O=[${ActionStreamOptions[$i]}]" ;; (*) errors[$errorCount]="Invalid action type [${ActionType[$i]}]." errorCount+=1 ;; esac i+=1 done if [[ $errorCount -eq 0 ]]; then msg "\nVerified: All action sequences passed sanity checks, reference valid baselines etc." else msg "\nThe following problems were identified:" i=0; while [[ $i -lt $errorCount ]]; do errmsg "${errors[$i]}" i+=1 done fi if [[ $errorCount -eq 0 ]]; then return 0 else return 1 fi }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 30973 | C. Thomas Tyler |
Adapting to new home in //p4bbi stream depot. Mostly minor changes to doc links. More significant changes we needed for package_downloads.sh. |
||
#1 | 30968 | C. Thomas Tyler |
Migration from Classic to Streams with: p4 copy -b P4BBI_Classic_to_Streams |
||
//guest/perforce_software/p4bbi/main/lib/bbi_load_and_verify.sh | |||||
#2 | 18506 | C. Thomas Tyler | Released P4BBI/MultiArch/2016.2/18504 (2016/03/04). | ||
#1 | 18422 | C. Thomas Tyler | Corrected push from dev. | ||
//guest/perforce_software/p4bbi/dev/lib/bbi_load_and_verify.sh | |||||
#7 | 18410 | C. Thomas Tyler |
Implemented 'CMD:' prefix for baseline definintions, and added sample config file to illustrate pulling from Git Hub. Updated BBIJunkFiles.txt to exclude import of .git foldres. Added test case and updatd test suite to call it. |
||
#6 | 18408 | C. Thomas Tyler |
BBI Config File format updated to 3.5.1. RENAME action support has been re-added. |
||
#5 | 18402 | C. Thomas Tyler |
bbi.sh v3.5.1: Added support for BRANCH_SPEC, DEPOT_SPEC, and STREAM_SPEC actions, which allow imports to use hand-crafted spec files during imports. This allows the BBI import process to simulate the evolution of stream specs over time, e.g. to reflect reparenting, and to account for things like non-branching files and CBD workflows that use sophisticated, hand-crafted stream specs. The required BBI Config file version has been updated from 3.2 to 3.5. Test suite has been updated to test new functionality. |
||
#4 | 18394 | C. Thomas Tyler |
Implemented labeling feature. Added doc for label feature. Added preflight checks for malformed label tags. |
||
#3 | 18387 | C. Thomas Tyler |
Implemented the DOS2UNIX option for the UDPATE action. Updated test suite to apply DOS2UNIX. Documented DOS2UNIX in BBIConfigFileFormat.txt, and enhanced ASTYLE documentation as well. |
||
#2 | 16423 | C. Thomas Tyler |
Added support for ASTYLE option for UPDATE entry in *.bbi.cfg files. Fixed bug chekcing for User P4CONFIG file; it was checking $P4CONFIG rather than $UserP4CONFIG. Update Copyright to new, simpler and smaller-chunk-of-text standard for some files. |
||
#1 | 13590 | C. Thomas Tyler |
Changed naming convention to use standard '.sh'; using '.lib' confused some text editors. |
||
//guest/perforce_software/p4bbi/dev/lib/bbi_load_and_verify.lib | |||||
#7 | 12926 | C. Thomas Tyler |
Added support for BASELINE_STORAGE definition in the BBI Config file. The value can be reference a shell environment variable, added to env.sh. Updated BBI Config File required veresion to 3.2.0 Updated test suite accordingly. |
||
#6 | 12374 | C. Thomas Tyler |
Increased required BBI config file from 3.0 to 3.1. The new 3.1 format requires that a NAME tag be defined, e.g. NAME=FGS. Updated BBIConfigFileFormat.txt accordingly. This new NAME tag is incorporated into the log filename, the name of the import workspace, and the workspace root directory. This enables parallel operation of multiple concurrent imports of unrelated modules into the same target Helix server. Added doc clarification that P4CONFIG file specified with '-P' must be an absolute path, and added error checking as well. Added a check to ensure the P4CONFIG file does not define a P4CLIENT value, with appropriate error messge if it does. Added -V flag to query version of bbi.sh as well as included bash library files. Made corresponding updates to the test suite, including removing P4CLIENT from the test P4CONFIG file, and updating FGS.*.bbi.cfg files to the new confgie file format. Minor cosmetic changes. |
||
#5 | 11810 | C. Thomas Tyler |
Implemented RMTOP feature. Updated TO DO notes. |
||
#4 | 11808 | C. Thomas Tyler |
Addd root-relative style of tar file, not needing RMTOP. Added support for *.zip files. Added -J flag to bbi.sh to obliterate junk files in BBIJunkFiles.txt. Enahnced sample files and docs. |
||
#3 | 11797 | C. Thomas Tyler | Implemented remaining import actions. | ||
#2 | 11785 | C. Thomas Tyler |
Partially imported import actions. Enhanced BBI config file version check. Enhanced logging. |
||
#1 | 11784 | C. Thomas Tyler |
Refactored bash libriaries. Added bbi_actions.lib to hold the BBI functionality. Branched 3 bash library files from the SDP, removing the SDP dependency. Enhanced docs. |
||
//guest/perforce_software/p4bbi/dev/bbi_functions.sh | |||||
#4 | 11774 | C. Thomas Tyler |
Defined format of STREAM and DEPOT actions. Added new sample config file illustrating new v3.x format. This version parses and verifies the config file with the new fromat, but does not perform an import. |
||
#3 | 11771 | C. Thomas Tyler | Added load_actions() | ||
#2 | 11768 | C. Thomas Tyler | bbi_functions.sh v1.0.2: Added verification of CMD: entry. | ||
#1 | 11767 | C. Thomas Tyler | Broke ground on BBI v3.0 (shell script version). |