#!/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> [-f]\n" [[ $1 == -h ]] && exit 1 echo -e "DESCRIPTION: This script generates an ecnrypted tarfile from the latest SDP code from the Perforce Production Server, suitable for distributing publicly. It checks using 'p4 status' to make sure it has the exact correct files from the Production server. It provdides decryption instructions. ARGUMENTS: -p <passwd> Specfiy the password used to encrypte/decrypt. Set it to a simple value with no spaces or too-funky characters. This is required. -s <sdp_package> Specify the SDP package, one of: sdp, sdp.win. -f Force mode. By default, if the package file has already been generated, a new one will not be created. Use '-f' recreate it. This is helpful if you forgot the passwor you created it with initially. CREDITS: The enctryption technique used in this script was inspired by this article: http://blog.ashurex.com/2012/07/17/encrypting-tar-gz-gzip-file-openssl\n" exit 1 } export P4CONFIG=.p4config declare Package=UNSET_PACKAGE declare Passwd=UNSET_PASSWORD declare TarFile=UNSET_TARFILE declare -i Force=0 declare -i shiftArgs=0 while [[ $# -gt 0 ]]; do case $1 in (-h|-man) usage $1;; (-p) Passwd=$2; shiftArgs=1;; (-s) Package=$2; shiftArgs=1;; (-f) Force=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 [[ $Force -eq 0 && -e $TarFile ]]; then echo -e "\nTar file [$TarFile] already exists.\n Transfer $TarFile to a remote Linux/Unix/Mac system, and unpack like this:\n \tcd /to/where/you/want/to/unpack/sdp \tdd if=/where/you/put/$TarFile | openssl des3 -d -k $Passwd |tar xvzf -\n" exit 0 else if [[ -e $TarFile ]]; then echo "Regnerating encrypted tar file [$TarFile]." /bin/rm -f $TarFile || bail "Failed to remove existing tarfile." else echo "Generating encrypted tar file [$TarFile]." fi 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!" echo -e "\nTransfer $TarFile to a remote Linux/Unix/Mac system, and unpack like this:\n \tcd /to/where/you/want/to/unpack/sdp \tdd if=/where/you/put/$TarFile | openssl des3 -d -k $Passwd |tar xvzf -\n" 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. |