summaryrefslogtreecommitdiff
path: root/Utilities/Release/push.bash
blob: a1c6651a6892949b48e6a93ccc034105c33870f2 (plain)
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
#!/usr/bin/env bash

usage='usage: push.bash [<options>] [--] <dest>

Options:

    --dir     <dir>            Specify subdirectory under destination.
                               Defaults to "v<version>".
    --version <ver>            CMake <major>.<minor> version number to push.
                               Defaults to version of source tree.
'

die() {
    echo "$@" 1>&2; exit 1
}

cmake_source_dir="${BASH_SOURCE%/*}/../.."

cmake_version_component()
{
  sed -n "
/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
" "${cmake_source_dir}/Source/CMakeVersion.cmake"
}


version=''
dir=''
while test "$#" != 0; do
    case "$1" in
    --dir) shift; dir="$1" ;;
    --version) shift; version="$1" ;;
    --) shift ; break ;;
    -*) die "$usage" ;;
    *) break ;;
    esac
    shift
done
test "$#" = 1 || die "$usage"
readonly dest="$1"

if test -z "$version"; then
    cmake_version_major="$(cmake_version_component MAJOR)"
    cmake_version_minor="$(cmake_version_component MINOR)"
    version="${cmake_version_major}.${cmake_version_minor}"
fi
readonly version

if test -z "$dir"; then
    dir="v${version}"
fi
readonly dir
if ! test -d "${dest}/${dir}"; then
    mkdir "${dest}/${dir}"
fi

for f in cmake-${version}*; do
    if ! test -f "${f}"; then
        continue
    fi

    echo "pushing '${f}'"

    # Make a copy with a new timestamp and atomically rename into place.
    tf="${dest}/${dir}/.tmp.${f}"
    df="${dest}/${dir}/${f}"
    cp "${f}" "${tf}"
    mv "${tf}" "${df}"

    # Pause to give each file a distinct time stamp even with 1s resolution
    # so that sorting by time also sorts alphabetically.
    sleep 1.1
done