github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/hack/make/tgz (about)

     1  #!/bin/bash
     2  
     3  CROSS="$DEST/../cross"
     4  
     5  set -e
     6  
     7  arch=$(go env GOHOSTARCH)
     8  if [ ! -d "$CROSS/linux/${arch}" ]; then
     9  	echo >&2 'error: binary and cross must be run before tgz'
    10  	false
    11  fi
    12  
    13  (
    14  for d in "$CROSS/"*/*; do
    15  	export GOARCH="$(basename "$d")"
    16  	export GOOS="$(basename "$(dirname "$d")")"
    17  
    18  	source "${MAKEDIR}/.binary-setup"
    19  
    20  	BINARY_NAME="${DOCKER_CLIENT_BINARY_NAME}-$VERSION"
    21  	DAEMON_BINARY_NAME="${DOCKER_DAEMON_BINARY_NAME}-$VERSION"
    22  	PROXY_BINARY_NAME="${DOCKER_PROXY_BINARY_NAME}-$VERSION"
    23  	BINARY_EXTENSION="$(export GOOS && binary_extension)"
    24  	if [ "$GOOS" = 'windows' ]; then
    25  		# if windows use a zip, not tgz
    26  		BUNDLE_EXTENSION=".zip"
    27  		IS_TAR="false"
    28  	else
    29  		BUNDLE_EXTENSION=".tgz"
    30  		IS_TAR="true"
    31  	fi
    32  	BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
    33  	DAEMON_BINARY_FULLNAME="$DAEMON_BINARY_NAME$BINARY_EXTENSION"
    34  	PROXY_BINARY_FULLNAME="$PROXY_BINARY_NAME$BINARY_EXTENSION"
    35  	mkdir -p "$DEST/$GOOS/$GOARCH"
    36  	TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME$BUNDLE_EXTENSION"
    37  
    38  	# The staging directory for the files in the tgz
    39  	BUILD_PATH="$DEST/build"
    40  
    41  	# The directory that is at the root of the tar file
    42  	TAR_BASE_DIRECTORY="docker"
    43  
    44  	# $DEST/build/docker
    45  	TAR_PATH="$BUILD_PATH/$TAR_BASE_DIRECTORY"
    46  
    47  	# Copy the correct docker binary
    48  	mkdir -p $TAR_PATH
    49  	cp -L "$d/$BINARY_FULLNAME" "$TAR_PATH/${DOCKER_CLIENT_BINARY_NAME}${BINARY_EXTENSION}"
    50  	if [ -f "$d/$DAEMON_BINARY_FULLNAME" ]; then
    51  		cp -L "$d/$DAEMON_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_DAEMON_BINARY_NAME}${BINARY_EXTENSION}"
    52  	fi
    53  	if [ -f "$d/$PROXY_BINARY_FULLNAME" ]; then
    54  		cp -L "$d/$PROXY_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_PROXY_BINARY_NAME}${BINARY_EXTENSION}"
    55  	fi
    56  
    57  	# copy over all the extra binaries
    58  	copy_binaries $TAR_PATH
    59  
    60  	if [ "$IS_TAR" == "true" ]; then
    61  		echo "Creating tgz from $BUILD_PATH and naming it $TGZ"
    62  		tar --numeric-owner --owner 0 -C "$BUILD_PATH" -czf "$TGZ" $TAR_BASE_DIRECTORY
    63  	else
    64  		# ZIP needs to full absolute dir path, not the absolute path
    65  		ZIP=`pwd`"/$TGZ"
    66  		# keep track of where we are, for later.
    67  		pushd .
    68  		# go into the BUILD_PATH since zip does not have a -C equivalent.
    69  		cd $BUILD_PATH
    70  		echo "Creating zip from $BUILD_PATH and naming it $ZIP"
    71  		zip -q -r $ZIP $TAR_BASE_DIRECTORY
    72  		# go back to where we started
    73  		popd
    74  	fi
    75  
    76  	hash_files "$TGZ"
    77  
    78  	# cleanup after ourselves
    79  	rm -rf "$BUILD_PATH"
    80  
    81  	echo "Created tgz: $TGZ"
    82  done
    83  )