#!/bin/bash function bail() { msg=$1 echo -e "\nError: $1\n" exit 1 } function usage () { echo -e "\nUsage:\n\t$(basename $0) -p <passwd> -s <sdp|sdp.win>\n" exit 1 } export P4CONFIG=.p4config declare Package=UNSET_PACKAGE declare Passwd=UNSET_PASSWORD declare -i shiftArgs=0 while [[ $# -gt 0 ]]; do case $1 in (-h|-man) usage;; (-p) Passwd=$2; shiftArgs=1;; (-s) Package=$2; shiftArgs=1;; (*) bail "Unrecognized arg [$1].";; esac # Shift (modify $#) the appropriate number of times. shift; while [[ $shiftArgs -gt 0 ]]; do [[ $# -eq 0 ]] && bail "Bad usage." shiftArgs=$shiftArgs-1 shift done done # Command line validation. if [[ $Passwd != UNSET_PASSWORD ]]; then echo "Verified: Password value is set to [$Passwd]. Using it to enctrypt." else bail "The '-p <passwd>' argument is required. Set it to a simple value with no spaces or too-funky characters. Aborting." fi if [[ $Package != UNSET_PACKAGE ]]; then if [[ $Package == sdp || $Package == sdp.win ]]; then echo "Generating tarfile for package [$Package]." else bail "Invalid package specified [$Package]. Valid package values are: sdp sdp.win" fi else bail "The '-s <package>' argument is required. Valid packages are: sdp sdp.win" fi cd /consulting/sw/MAIN || bail "Could not cd to [/consulting/sw/MAIN]." echo "Logging in to Perforce Production server." p4 -s login < /consulting/.p4passwd echo "Getting latest $Package files." p4 -s sync $Package/... o=$(p4 -s opened $Package/... 2>&1) if [[ $o == *"not opened on this client"* ]]; then echo "Verified: no files opened. Continuing." else p4 -s opened $Package/... bail "Files opened or could not verify no files opened. Aborting." fi echo "Checking files status." o=$(p4 -s status $Package/...) if [[ $o == *" - no file(s) to reconcile"* ]]; then echo "Verified: File 'status' checked, all files OK. Continuing." else p4 -s status $Package/... bail "The 'p4 status' command reported differences. Aborting." fi echo "Getting latest changelist for $Package package." c=$(p4 changes -m 1 $Package/...|cut -d ' ' -f 2) echo "Latest changelist for $Package is $c." tarFile=/pub/guest/tom_tyler/sw/main/dist/$Package.$c.encrypted.tar.gz if [[ -e $tarFile ]]; then bail "Tar file [$tarFile] already exists. Aborting." else echo "Generating encrypted tar file [$tarFile]." tar -cvzpf - $Package | openssl des3 -salt -k $Passwd | dd of=$tarFile echo "Logging in to Perforce Workshop server." cd $(dirname $tarFile) || bail "Could not cd to [$(dirname $tarFile)]." p4 -s login < /pub/.p4passwd echo "Testing encrypted tar file." /bin/rm -rf $Package || bail "Could not remove dir [$PWD/$Package]. Test not started. Aborting." dd if=$tarFile | openssl des3 -d -k $Passwd | tar -xvzpf - if [[ -d $Package ]]; then /bin/rm -rf $Package echo "Verified Tar file looks OK." else bail "Error: Tar file bogus!" fi fi echo "Tar file looks OK!" exit 0
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 8841 | C. Thomas Tyler |
Enhanced docs, added '-f' force flag, and added unpacking instructions. |
||
#4 | 8752 | C. Thomas Tyler | Added package check. | ||
#3 | 8750 | C. Thomas Tyler |
Enhanced to accept password as a command line flag, rather than requiring an environment variable to be set. Added command line parsing and usage message. |
||
#2 | 8748 | C. Thomas Tyler | Added support for generating Windows flavor. | ||
#1 | 8747 | C. Thomas Tyler |
Added a personal utility for generating an encrypted tar file from files on the Perforce Production server. |