summaryrefslogtreecommitdiffhomepage
path: root/desktop/scripts/release/publish-metadata-to-api
blob: 12bda06e4aa6b452f300829ed0785433dee1ef98 (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
#!/usr/bin/env bash

set -eu

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

if [ $# -lt 3 ]; then
    echo "Please provide the following arguments:"
    echo "    $(basename "$0") \\"
    echo "        <metadata directory> \\"
    echo "        <build server SSH destination> \\"
    echo "        <metadata server SSH destination>"
    echo ""
    echo "Note that the metadata server SSH destination is part of the rsync command executed on the build server and will be checked against the SSH config of build@\$buildserver_host."
    exit 1
fi

# shellcheck source=desktop/scripts/release/release-config.sh
source "$SCRIPT_DIR/release-config.sh"

LOCAL_METADATA_DIR=$1
BUILD_SERVER_HOST=$2
METADATA_SERVER_HOST=$3

BUILDSERVER_TMP_DIR="/tmp/desktop-upload-release"
BUILDSERVER_METADATA_DIR="$BUILDSERVER_TMP_DIR/metadata"
METADATA_SERVER_METADATA_DIR="desktop/metadata"

RSYNC_OPTIONS=(-av --mkpath)
METADATA_SERVER_RSYNC_OPTIONS=("${RSYNC_OPTIONS[@]}" '--rsh="ssh -p 1122"')

function run_on_build_server {
  # This should be expanded client side
  # shellcheck disable=SC2029
  ssh "$BUILD_SERVER_HOST" "$@"
}

function run_on_build_server_as_build_user {
  run_on_build_server sudo -i -u "$BUILDSERVER_BUILDUSER" "$@"
}

function local_rsync {
  rsync "${RSYNC_OPTIONS[@]}" "$@"
}

function buildserver_rsync {
  run_on_build_server_as_build_user rsync "${METADATA_SERVER_RSYNC_OPTIONS[@]}" "$@"
}

function remove_buildserver_tmp_dir {
  run_on_build_server rm -rf $BUILDSERVER_TMP_DIR
}

# Clean up previous metadata dir on build server in case this failed the last time this script ran
remove_buildserver_tmp_dir

# Send the local metadata dir to the build server
local_rsync "$LOCAL_METADATA_DIR" "$BUILD_SERVER_HOST":$BUILDSERVER_METADATA_DIR

# Send the metadata on the buildserver to the cdn server
buildserver_rsync $BUILDSERVER_METADATA_DIR "$METADATA_SERVER_HOST":"$(dirname "$METADATA_SERVER_METADATA_DIR")"

# Remove intermediate tmp dir when done
remove_buildserver_tmp_dir