1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2019 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# foamPackRelease [OPTION]
#
# Description
# Simple script generator for packing OpenFOAM sources and submodules
#
# $ foamPackRelease -output=some/path origin/master > create-tar
# $ bash ./create-tar
#
# Or directly:
#
# $ foamPackRelease -tgz origin/master | bash
#
# Done as two-step process to allow further manual adjustments as required
#------------------------------------------------------------------------------
Script="${0##*/}"
usage() {
exec 1>&2
while [ "$#" -gt 0 ]; do echo "$1"; shift; done
cat <<USAGE
Usage: ${0##*/} [OPTION] commit-ish
options:
-output=dir Write to alternative output directory
-no-modules Exclude submodules
-no-patch Ignore _patch number for the output tar-file
-compress=TYPE Compress with specified type
-sep=SEP Change the patch, version separator from '_' to SEP
-tgz Alias for -compress=tgz
-help Print help
Simple script generator for packing OpenFOAM and submodules.
Eg,
$Script -output some-directory origin/master > create-tar
sh ./create-tar
$Script -tgz origin/master | bash
USAGE
exit 1
}
# Report error and exit
die()
{
exec 1>&2
echo
echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
echo
echo "See '${0##*/} -help' for usage"
echo
exit 1
}
#-------------------------------------------------------------------------------
outputDir="."
versionSeparator='_'
unset compress skipModules skipPatchNum
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
usage
;;
-output)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
outputDir="$2"
shift
;;
-output=*)
outputDir="${1#*=}"
;;
-no-modules)
skipModules=true
;;
-no-patch)
skipPatchNum=true
;;
-compress=*)
compress="${1#*=}"
;;
-sep=*)
versionSeparator="${1#*=}"
;;
-tgz)
compress="${1#*-}"
;;
-*)
usage "unknown option: '$*'"
;;
*)
break
;;
esac
shift
done
commit="$1"
[ "$#" -eq 1 ] && [ -n "$commit" ] || usage "Requires one argument"
# Failsafe patch, version separator
: "${versionSeparator:=_}"
#-------------------------------------------------------------------------------
# Resolve the output directory
outputDir="$(cd "$outputDir" 2>/dev/null && pwd -L)" || \
die "Cannot resolve output directory"
[ -w "$outputDir" ] || \
die "Output directory non-writable: $outputDir"
echo "Using outputDir=$outputDir" 1>&2
#-------------------------------------------------------------------------------
# Locate the git repository
# Locate git-dir via rev-parse
findGitDir()
{
(
if cd "$1" 2>/dev/null && \
git rev-parse --is-inside-work-tree > /dev/null 2>&1
then
git rev-parse --show-toplevel 2>/dev/null
fi
)
}
echo "Find git repository ... from script location" 1>&2
gitbase=$(findGitDir "${0%/*}")
##DEBUG unset gitbase
if [ -z "$gitbase" ]
then
echo "Find git repository ... from current directory" 1>&2
gitbase=$(findGitDir "$PWD")
fi
[ -d "$gitbase" ] || die "Could not locate a git directory"
echo "Detected git repository at $gitbase" 1>&2
# Resolve the given commit-ish to a real commit number.
# Eg, origin/master on input, SHA1 on output
head="$(git --git-dir="$gitbase/.git" rev-parse "$commit")"
[ -n "$head" ] || die "Could resolve requested start point $commit"
echo "Resolved $commit as $head" 1>&2
#-------------------------------------------------------------------------------
# Determine the API and PATCH numbers.
# Extract from META-INFO/api-info
unset api patch sha1
# Grab the sha1 for the file
sha1=$(git --git-dir="$gitbase/.git" ls-tree "$head" META-INFO/api-info | \
awk '{ if ($2 == "blob") { print $3 }}')
[ -n "$sha1" ] || die "Could locate git content for META-INFO/api-info"
# The api and patch
api="$(git --git-dir="$gitbase/.git" show "$sha1" | sed -ne s/api=//p)"
patch="$(git --git-dir="$gitbase/.git" show "$sha1" | sed -ne s/patch=//p)"
[ -n "$api" ] || die "Could resolve api value"
# Determine the BUILD information from git, as per wmakeBuildInfo.
build="$(git --git-dir="$gitbase/.git" log -1 --date=short --format='%h=%ad' 2>/dev/null|sed 's/-//g;s/=/-/')"
echo "Detected api, patch, build as '$api', '$patch', '$build'" 1>&2
# Define the output names
dirPrefix="OpenFOAM-v${api}"
tarName="OpenFOAM-v${api}"
if [ "$skipPatchNum" = true ]
then
echo "Ignoring patch number for output name" 1>&2
elif [ "${patch:-0}" -gt 0 ]
then
tarName="${tarName}${versionSeparator}${patch}"
fi
echo 1>&2
echo "Tar-file name: $tarName.tar" 1>&2
echo "Directory name: $dirPrefix/" 1>&2
echo 1>&2
#-------------------------------------------------------------------------------
# Create main tar
echo '#!/bin/bash'
echo "cd '$gitbase/' || exit"
echo "api='$api'"
echo "patch='${patch:-0}'"
echo "build='$build'"
echo "head='$head'"
echo "outputDir='$outputDir'"
echo "dirPrefix='$dirPrefix'"
echo "tarName='$tarName'"
# Note - directory separator '/' encoded as '@' for manifest name
echo 'manifest="${dirPrefix}@META-INFO@manifest.txt"'
echo 'buildInfo="${dirPrefix}@META-INFO@build-info"'
echo '#--------'
echo 'set -x'
echo 'umask 0022'
echo 'git -c tar.umask=user archive --format=tar --prefix="$dirPrefix/" -o "$outputDir/$tarName.tar" "$head"'
# Tag build information with underscore to distinguish from "real" build
# information when git is available.
echo 'echo build="${build:+_}$build" > "$outputDir/$buildInfo"'
echo '{'
echo ' echo api="$api"'
echo ' echo patch="$patch"'
echo ' echo head="$head"'
echo ' echo'
echo ' git ls-tree -r "$head"'
echo '} > "$outputDir/$manifest"'
#------------------------------------------------------------------------------
# Add in mpdules
if [ "$skipModules" != true ]
then
git --git-dir="$gitbase/.git" ls-tree "$head" modules/ | \
while read mode gittype sha1 module
do
[ "$gittype" == commit ] || continue
echo
echo "module=\""$module"\""
echo "commit=\""$sha1"\""
echo "tarModule=\""$tarName-${module##*/}"\""
echo
echo 'if pushd "$module"; then'
echo 'git -c tar.umask=user archive --format=tar --prefix="$dirPrefix/$module/" -o "$outputDir/$tarModule.tar" "$commit"'
echo 'tar -Af "$outputDir/$tarName.tar" "$outputDir/$tarModule.tar"'
echo 'rm -f "$outputDir/$tarModule.tar"'
echo '{'
echo ' echo'
echo ' echo "$module"'
echo ' echo commit="$commit"'
echo ' echo'
echo ' git ls-tree -r "$commit"'
echo '} >> "$outputDir/$manifest"'
echo 'popd; fi'
done
fi
#------------------------------------------------------------------------------
# Add in build-info and manifest files
# Decode '@' in the names as '/' directory separator
echo
echo '{ echo; echo "# End"; } >> "$outputDir/$manifest"'
echo
echo "echo 'Adding build-info and manifest files'"
echo 'if pushd "$outputDir"; then'
echo "tar --owner=root --group=root --append --transform='s|@|/|g' -v -f \"\$tarName.tar\" \"\$buildInfo\" \"\$manifest\""
echo 'rm -f "$buildInfo" "$manifest"'
echo 'popd; fi'
echo
echo "# End of creating archive"
echo
#------------------------------------------------------------------------------
# Compression
case "$compress" in
('')
echo "No compression requested" 1>&2
;;
(gz | gzip)
echo "Using gzip compression" 1>&2
echo 'gzip -9 "$outputDir/$tarName.tar"'
echo
echo '# End of compression'
;;
(tgz)
echo "Using gzip compression with tgz ending" 1>&2
echo 'gzip -c -9 "$outputDir/$tarName.tar" > "$outputDir/$tarName.tgz"'
echo 'rm -f "$outputDir/$tarName.tar"'
echo
echo '# End of compression'
;;
(bz | bzip | bzip2)
echo "Using bzip2 compression" 1>&2
echo 'bzip2 -9 "$outputDir/$tarName.tar"'
echo
echo '# End of compression'
;;
(xz)
echo "Using xz compression" 1>&2
echo 'xz -9 "$outputDir/$tarName.tar"'
echo
echo '# End of compression'
;;
(*)
echo "Unknown compression scheme: $compress" 1>&2
;;
esac
#------------------------------------------------------------------------------
|