#!/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/view/p4bbi/main/LICENSE #------------------------------------------------------------------------------ #============================================================================== # Declarations and Environment set -u declare ToolsDir="$PWD" declare Log= if [[ -e "$ToolsDir/env.sh" ]]; then source "$ToolsDir/env.sh" ||\ { echo -e "\\nError: Failed to do: source \"$ToolsDir/env.sh\""; exit 1; } else echo -e "\\nError: Missing env file: $ToolsDir/env.sh" exit 1 fi # Environment isolation. For stability and security reasons, prepend # PATH to include dirs where known-good scripts exist. # known/tested PATH and, by implication, executables on the PATH. export PATH=$P4U_HOME:$PATH:~/bin:. export P4CONFIG=${P4CONFIG:-.p4config} [[ -n "$Log" ]] || Log="/tmp/package_p4bbi_downloads.$(date +'%Y-%m-%d-%H%M%S').log" export P4U_LOG="$Log" source $P4U_ENV source $P4U_LIB/libcore.sh source $P4U_LIB/libp4u.sh export VERBOSITY=3 declare Version=1.1.0 declare -i SilentMode=0 declare AppHome=${PWD%/*} declare ExcludesCfg="$ToolsDir/excludes.downloads.cfg" #============================================================================== # Local Functions #------------------------------------------------------------------------------ # Function: terminate function terminate { # Disable signal trapping. trap - EXIT SIGINT SIGTERM # Don't litter. cleanTrash vvmsg "$THISSCRIPT: EXITCODE: $OverallReturnStatus" # Stop logging. [[ "$Log" == off ]] || msg "Log is: $Log\\n${H}\\n" # With the trap removed, exit. exit "$OverallReturnStatus" } #------------------------------------------------------------------------------ # Function: usage (required function) # # Input: # $1 - style, either -h (for short form) or -man (for man-page like format). #------------------------------------------------------------------------------ function usage { declare style=${1:--h} echo "USAGE for $THISSCRIPT v$Version: $THISSCRIPT [-f] [-o] [-show] [-submit] [-L <log>] [-si] [-v<n>] [-n] [-D] or $THISSCRIPT [-h|-man] " if [[ $style == -man ]]; then echo -e " DESCRIPTION: Create a P4BBI distribution tar file from the latest files in the current stream. An exclusion config file defines files and directories to be excluded from packaging. This exclusion config file has one file name per line, which may include the '*' wild card. The exclusion config file can also specify directories to be excluded, which start with a 'D:' prefix. The exclusion config file is: $ExcludesCfg OPTIONS: -f Force creation of target tar/zip file, replacing an existing one if necessary. The default behavior is to abort if the target tar file already exists. -o Proceed even if files are opened in Perforce and/or not synced to the head revision. This may be useful for testing purposes. By default, we abort if any files are checked out, or if files are not syncd to the head revision. This option is not suitable for creating a distribution file that will be submitted. -show Show tar file contents using 'tar -tzf'. -v<n> Set verbosity 1-5 (-v1 = quiet, -v5 = highest). -L <log> Specify the path to a log file, or the special value 'off' to disable logging. By default, all output (stdout and stderr) goes to: $(dirname $Log). NOTE: This script is self-logging. That is, output displayed on the screen is simultaneously captured in the log file. Do not run this script with redirection operators like '> log' or '2>&1', and do not use 'tee.' -si Operate silently. All output (stdout and stderr) is redirected to the log only; no output appears on the terminal. This cannot be used with '-L off'. -n No-Op. Prints commands instead of running them. -D Set extreme debugging verbosity. HELP OPTIONS: -h Display short help message -man Display man-style help message -V Show versions " fi exit 1 } #============================================================================== # Command Line Processing declare -i shiftArgs=0 declare AppVersion= declare -i ForceTarCreation=0 declare -i AllowOpenedFiles=0 declare -i ShowTarContents=0 declare TarFile= set +u while [[ $# -gt 0 ]]; do case $1 in (-f) ForceTarCreation=1;; (-o) AllowOpenedFiles=1;; (-show) ShowTarContents=1;; (-h) usage -h;; (-man) usage -man;; (-v1) export VERBOSITY=1;; (-v2) export VERBOSITY=2;; (-v3) export VERBOSITY=3;; (-v4) export VERBOSITY=4;; (-v5) export VERBOSITY=5;; (-L) export 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 Verification [[ $SilentMode -eq 1 && "$Log" == off ]] && \ usageError "Cannot use '-si' with '-L off'." #============================================================================== # Main Program trap terminate EXIT SIGINT SIGTERM declare -i OverallReturnStatus=0 if [[ "$Log" != off ]]; then touch $Log || bail "Couldn't touch log file [$Log]." # Redirect stdout and stderr to a log file. if [[ $SilentMode -eq 0 ]]; then exec > >(tee "$Log") exec 2>&1 else exec >"$Log" exec 2>&1 fi initlog fi App=p4bbi AppVersion=$(cat ../Version|cut -d '/' -f 3).$(cat ../Version|cut -d '/' -f 4|cut -d ' ' -f 1) AppVersion=$(echo $AppVersion) DownloadsDir=$AppHome/downloads TarFile=$DownloadsDir/$App.$AppVersion.tgz TarFile2=$DownloadsDir/$App.tgz WorkingDir=/tmp/$AppVersion runCmd "p4 -ztag -F %TicketExpiration% login -s" \ "Checking login status." 0 if [[ -n "$CMDOUTPUT" ]]; then msg "Verified: Logged into Perforce." else bail "Not logged into Perforce." fi runCmd "p4 -F %depotFile% -ztag opened ../..." \ "Checking for opened files in the current stream (p4 -ztag -F %clientStream% info)." if [[ -n "$CMDOUTPUT" ]]; then if [[ "$AllowOpenedFiles" -eq 1 ]]; then msg "Proceeding despite opened files being detected, due to -o flag." else if [[ "$CMDOUTPUT" == *"//"* ]]; then bail "These files are checked out in main:\\n$CMDOUTPUT\\n\\nAborting." else bail "Could not determine if files are checked out in main. Output was:\\n$CMDOUTPUT\\n\\nAborting." fi fi else msg "Verified: No files checked out in P4BBI main." fi runCmd "p4 -F %depotFile% -ztag sync -n ../..." \ "Checking for unsynced P4BBI files." if [[ -n "$CMDOUTPUT" ]]; then if [[ $AllowOpenedFiles -eq 1 ]]; then msg "Proceeding despite unsynced files, due to -o flag." else if [[ $CMDOUTPUT == *"//"* ]]; then bail "These files need to be synced:\\n$CMDOUTPUT\\n\\nAborting." else bail "Could not determine if files need to be synced. Output was:\\n$CMDOUTPUT\\n\\nAborting." fi fi else msg "Verified: No unsynced P4BBI files." fi msg "AppHome=[$AppHome] TF=[$TarFile] TF2=[TarFile2] WD=[$WorkingDir]." for tf in $TarFile $TarFile2; do if [[ -r $tf ]]; then if [[ $ForceTarCreation -eq 1 ]]; then runCmd "/bin/rm -f $tf" \ "Removing existing tar file [$tf] due to '-f'." ||\ bail "Failed to remove existing tar file [$tf]. Aborting." else bail "Tar file already exists: [$tf]. Use '-f' to forcibly replace. Aborting." fi fi done if [[ ! -d "$DownloadsDir" ]]; then runCmd "/bin/mkdir -p $DownloadsDir" "Initializing downloads dir [$DownloadsDir]." 0 ||\ bail "Failed to create empty downloads dir [$DownloadsDir]. Aborting." fi msg "Creating working directory." if [[ -d "$WorkingDir" ]]; then runCmd "/bin/rm -rf $WorkingDir" \ "Removing old working dir [$WorkingDir]." ||\ bail "Failed to remove old working dir [$WorkingDir]. Aborting." fi runCmd "/bin/mkdir -p $WorkingDir" "Initializing working dir [$WorkingDir]." 0 ||\ bail "Failed to create empty working dir [$WorkingDir]. Aborting." #------------------------------------------------------------------------------ # Create tar file. RootDir="$WorkingDir/p4bbi" runCmd "/bin/cp -pr ${AppHome} $RootDir" \ "Copying P4BBI package to working dir." 0 ||\ bail "The copy to the working dir failed. Aborting." cd "$RootDir" || bail "Failed to cd to P4BBI root in Working Dir [$RootDir]." if [[ -r "$ExcludesCfg" ]]; then while read excludeFile; do [[ "$excludeFile" == "" || "$excludeFile" == "#"* ]] && continue if [[ "$excludeFile" == "D:"* ]]; then excludeDir=${excludeFile#D:} msg "/usr/bin/find $RootDir -type d -name \"$excludeDir\" -print -exec /bin/rm -r -f {} \\;" /usr/bin/find $RootDir -type d -name "$excludeDir" -print -exec /bin/rm -r -f {} \; else msg "/usr/bin/find $RootDir -type f -name \"$excludeFile\" -print -exec /bin/rm -f {} \\;" /usr/bin/find $RootDir -type f -name "$excludeFile" -print -exec /bin/rm -f {} \; fi done < $ExcludesCfg fi cd "$WorkingDir" || bail "Failed to cd to Working Dir [$WorkingDir]." runCmd "tar -czf $TarFile p4bbi" ||\ bail "Failed to create tar file [$TarFile]. Aborting." runCmd "cp -f $TarFile $TarFile2" if [[ $ShowTarContents -eq 1 ]]; then runCmd "/usr/bin/tar -tzf $TarFile" \ "Tar file [$TarFile] contains these elements:" fi if [[ $OverallReturnStatus -eq 0 ]]; then msg "${H}\\nAll processing completed successfully.\\n" else msg "${H}\\nProcessing completed, but with errors. Scan above output carefully.\\n" fi # Illustrate using $SECONDS to display runtime of a script. msg "That took about $(($SECONDS/3600)) hours $(($SECONDS%3600/60)) minutes $(($SECONDS%60)) seconds.\\n" # See the terminate() function, which is really where this script exits. exit $OverallReturnStatus
# | 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/tools/package_downloads.sh | |||||
#1 | 16392 | C. Thomas Tyler | Changed 'dist' to 'downloads'. | ||
//guest/perforce_software/p4bbi/tools/dist.sh | |||||
#1 | 12392 | C. Thomas Tyler |
Added script to create P4BBI zip file, modeled after a similar script used for the SDP. |