-
Notifications
You must be signed in to change notification settings - Fork 36
/
package.sh
executable file
·142 lines (110 loc) · 3.05 KB
/
package.sh
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
#!/bin/bash
#
# Copyright NetApp Inc, 2021 All rights reserved
#
BUILD_SOURCE=$(pwd)
BIN=$(basename "$0")
help() {
cat <<EOF_PRINT_HELP
$BIN - Build Distribution Package
Usage:
$./$BIN <dist> <arch> <version> <release> [options]
Arguments:
dist package format (rpm or dep)
arch target architecture, one of:
x86_64/amd64, amd64, arm64, arm32, armhf
(other architectures should work as well,
but we haven't tested)
version version
release release
Options
-d, --docker build in docker container
EOF_PRINT_HELP
}
usage() {
echo "Usage:"
echo "$./$BIN <dist> <arch> <version> <release> [options]"
}
info() {
echo -e "\033[1m\033[45m$1\033[0m"
}
error() {
echo -e "\033[1m\033[41m$1\033[0m"
}
build () {
if [ "$DOCKER" == "true" ]; then
info "building [harvest_$VERSION-$RELEASE_$ARCH.$DIST] in container"
if [ "$DIST" == "rpm" ]; then
cd "$BUILD_SOURCE/$DIST/centos" || exit
else
cd "$BUILD_SOURCE/$DIST/debian" || exit
fi
if [ ! $? -eq 0 ]; then
error "docker image"
exit 1
fi
docker build -t harvest2/"$DIST" .
if [ ! $? -eq 0 ]; then
error "build docker container"
exit 1
fi
docker run -it -v "$BUILD_SOURCE":/tmp/src -e HARVEST_BUILD_SRC="/tmp/src" -e HARVEST_ARCH="$ARCH" -e HARVEST_VERSION="$VERSION" -e HARVEST_RELEASE="$RELEASE" harvest2/"$DIST"
if [ ! $? -eq 0 ]; then
error "run docker container"
exit 1
else
info "build in docker complete"
fi
cd "$BUILD_SOURCE" || exit
exit 0
else
info "building [harvest_$VERSION-$RELEASE_$ARCH.$DIST] on local system"
export HARVEST_BUILD_SRC="$BUILD_SOURCE"
export HARVEST_ARCH="$ARCH"
export HARVEST_VERSION="$VERSION"
export HARVEST_RELEASE="$RELEASE"
export ASUP_MAKE_TARGET="$ASUP_MAKE_TARGET"
export GIT_TOKEN="$GIT_TOKEN"
sh "$BUILD_SOURCE/$DIST/build-$DIST.sh"
if [ ! $? -eq 0 ]; then
error "run build script"
exit 1
else
info "build complete"
fi
cd "$BUILD_SOURCE" || exit
exit 0
fi
}
# defaults
if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
help
exit 0
fi
DIST=$1
ARCH=$2
VERSION=$3
RELEASE=$4
ASUP_MAKE_TARGET=$5
GIT_TOKEN=$6
if [[ -z "$DIST" || -z "$ARCH" || -z "$VERSION" || -z "$RELEASE" ]]; then
usage
exit 1
fi
if [[ "$5" == "-d" || "$5" == "--docker" ]]; then
echo " -- build in docker"
DOCKER=true
else
echo " -- build locally"
DOCKER=false
fi
if [[ "$ARCH" == "x86_64" && "$DIST" == "deb" ]]; then
ARCH="amd64"
fi
# build package in container
if [[ "$DIST" == "rpm" || "$DIST" == "deb" ]]; then
build
else
error "unknown package format: $DIST"
exit 1
fi