reproducible_debian_live_sync_result.sh 1.77 KB
Newer Older
1
2
3
4
5
#!/bin/bash

# Copyright 2022 Mattia Rizzolo <mattia@debian.org>
# released under the GPLv2

6
DEBUG=true
7
8
9
10
11
12
13
14
15
16
17
. /srv/jenkins/bin/common-functions.sh
common_init "$@"

# common code for tests.reproducible-builds.org
. /srv/jenkins/bin/reproducible_common.sh

set -u

PROJECT=debian_live_build
NODE=osuosl173-amd64.debian.net

18
19
20
# Argument 1 = description
# Argument 2 = absolute path on $NODE
# Argument 3 = published name
21
rsync_remote_results() {
22
23
    local description=$1
    local origfile=$2
24
25
    local filename
    filename=$(basename "$3")
26
27
    echo "$(date -u) - Starting to sync $description to '$filename'."
    # Copy the new results from the build node to the web server node
28
    cd "$BASE"/"$PROJECT"
29
    scp -o Batchmode=yes "$NODE":"$origfile" "$filename.tmp"
30
31
    chmod 755 "$filename.tmp"
    mv "$filename.tmp" "$filename"
32
    echo "$(date -u) - enjoy ${REPRODUCIBLE_URL}/${PROJECT}/${filename}"
33
34
}

35
36
# Argument 1 = description
# Argument 2 = filename part of the published name that was synced with 'rsync_remote_results'
37
delete_live_build_file() {
38
39
    local description=$1
    local filetodelete=$2
40
41
    local filename
    filename=$(basename "$filetodelete")
42
    echo "$(date -u) - Delete $description: '$filename'."
43
    cd "$BASE"/"$PROJECT"
44
45
    if [[ "$filename" != "$filetodelete" ]]; then
        echo "E: You provided a full path, ignoring for safety" >&2
46
47
48
        exit 1
    fi
    if [ -f "$filename" ]; then
49
        rm -vf "$filename"
50
    else
51
        echo "E: File not found" >&2
52
53
54
55
        exit 1
    fi
}

56
57
58
59
60
61
62
63
64
parse_arguments() {
    if [ "$1" == "delete" ]; then
        shift
        delete_live_build_file "$@"
    else
        rsync_remote_results "$@"
    fi
}

65
# main
66
67
68
69

# Intentionally unquoted, so the space-separated arguments will be available individually
parse_arguments ${SSH_ORIGINAL_COMMAND}