-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_funcs.sh
128 lines (109 loc) · 2.67 KB
/
build_funcs.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
function target_compile {
echo "${ROOT_COMPILE}/${PACKAGE}"
}
function target_install {
echo "${ROOT_INSTALL}/${PACKAGE}"
}
function target_manifest {
echo "${MANIFESTS}/${PACKAGE}.files"
}
function go_home {
cd $PKG_HOME
}
function go_compile {
cd "$(target_compile)"
}
function go_install {
cd "$(target_install)"
}
function download_archive {
go_home
url="$1"
arc_file="$2"
test -z "$arc_file" && arc_file=$(basename $url)
arc_src=$( dirname $url )
if [ -f "${DOWNLOAD}/${arc_file}" ]; then
echo "$arc_file already cached in $DOWNLOAD"
else
echo "downloading $arc_file from $url"
cd $DOWNLOAD && curl -L -s "$url" > $arc_file
fi
}
function download_git {
git_url="$1"
git_branch="$2"
if [[ -z "$git_branch" ]]; then
git_branch="master"
fi
if [[ -d $(target_compile) && -d "$(target_compile)/.git" ]]; then
( go_compile && git checkout $git_branch && git pull origin $git_branch )
else
rm -fr $(target_compile)
git clone "$git_url" "$(target_compile)"
( go_compile && git checkout "$git_branch")
fi
}
function extract_archive {
go_home
archive="$1"
dst_dir="$2"
arc_file=$(basename $archive)
if [ -d "$(target_compile)" ]; then
echo "cleaning $(target_compile)"
rm -vrf "$(target_compile)/*"
else
echo "creating $(target_compile)"
mkdir -v -p "$(target_compile)"
fi
echo "extracting $arc_file to $(target_compile)"
tar xaf $archive -C "$(target_compile)" --strip-components=1
}
function install_buildtime_dependencies {
go_home
echo "installing for build environment: $*"
sudo yum -y install $*
}
function make_install_root {
go_compile
echo "cleaning install root"
rm -rvf "$(target_install)"
test -d "$(target_install)" || mkdir -vp "$(target_install)"
echo "installing to $(target_install)"
make install DESTDIR="$(target_install)"
}
function package_dir {
go_home
if [[ -z "$PACKAGE_SIGN" || "$PACKAGE_SIGN" -eq "no" || "$PACKAGE_SIGN" -eq "false" ]]; then
export SIGN_FLAG=""
else
export SIGN_FLAG="--rpm-sign"
fi
fpm -t rpm -s dir \
-C $(target_install) \
-p $ARTIFACTS/7/x86_64 \
-n $PACKAGE \
--version $PACKAGE_VERSION \
--iteration $PACKAGE_ITERATION \
--provides "$PACKAGE" \
--inputs $PKG_HOME/mf/$PACKAGE.files \
$SIGN_FLAG $*
if [ $? -ne 0 ]; then
exit 1
fi
}
function compile_make {
go_compile
echo "compiling $PACKAGE"
make
if [ $? -eq 0 ]; then
echo "build complete"
else
echo "build failed"
exit 1
fi
}
function build_package_manifest {
go_home
rm -fv "$(target_manifest)"
find "$(target_install)" -type f | sed -e "s#$(target_install)/##" > "$(target_manifest)"
}