-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·124 lines (104 loc) · 2.99 KB
/
build.sh
File metadata and controls
executable file
·124 lines (104 loc) · 2.99 KB
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
#!/bin/bash
repos="cligen clixon clixon-controller clixon-pyapi"
curdir=$(pwd)
usage() {
echo "Usage: $0 [options]"
echo "-b build packages"
echo "-c clean up"
echo "-u upload packages"
exit
}
build() {
# Install dependencies
DEBIAN_FRONTEND=noninteractive sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install -y git make gcc bison libnghttp2-dev libssl-dev flex build-essential python3 dh-python python3-stdeb python3-pip
# Create the user clicon if it does not exist
grep clicon /etc/passwd > /dev/null
if [ $? != 0 ]; then
sudo useradd -r -s /bin/false clicon
fi
# Clone all repos
for repo in ${repos}; do
if [ -d "${repo}" ]; then
(cd "${repo}"; git pull)
else
git clone "https://github.com/clicon/${repo}.git"
fi
if [ $? != 0 ]; then
echo "Git: ${repo} failed"
exit
fi
done
# Build all repos
for repo in $repos; do
builddir="${curdir}/build/${repo}"
version=$(date +"%Y%m%d-%H%M")
if [ "$repo" != "clixon-pyapi" ]; then
sudo chown root:root "$builddir"
fi
if [ "$repo" == "cligen" ]; then
(cd "$repo"; ./configure --prefix="$builddir"; make; sudo make install)
elif [ "$repo" == "clixon" ]; then
(cd "$repo"; ./configure --prefix="$builddir" --with-cligen="${curdir}/build/cligen"; make; sudo make install)
elif [ "$repo" == "clixon-controller" ]; then
(cd "$repo"; ./configure --prefix="$builddir" --with-cligen="${curdir}/build/cligen" --with-clixon="${curdir}/build/clixon"; make; sudo make install)
fi
if [ "$repo" == "clixon-pyapi" ]; then
(cd "$repo"; ./requirements-apt.sh)
(cd "$repo"; VERSION=${version} DEB_BUILD_OPTIONS=nocheck python3 setup.py --command-packages=stdeb.command bdist_deb)
mv "${repo}/deb_dist/"*.deb "${curdir}/build"
else
arch=$(dpkg --print-architecture)
(cd "${curdir}/build/"; sed -ie "s/Version:.*/Version: $version/g" ${repo}/DEBIAN/control; sed -ie "s/Architecture:.*/Architecture: $arch/g" ${repo}/DEBIAN/control; sudo dpkg-deb --build ${repo})
fi
done
}
clean() {
sudo rm -f ${curdir}/build/*.deb
for repo in $repos; do
# Remove all files under ${curdir}/build/${repo}
if [ -d "${curdir}/build/${repo}" ]; then
(cd "${curdir}/build/${repo}"; sudo rm -rf bin etc include lib sbin share var local)
fi
# Do a make clean for all repos
if [ -d "${repo}" ]; then
sudo rm -r ${repo}
fi
done
}
upload() {
if [ -z ${API_USER} ]; then
echo "API_USER must be set."
exit
fi
if [ -z ${API_KEY} ]; then
echo "API_KEY must be set."
exit
fi
if [ -z ${API_URL} ]; then
API_URL="https://platform.sunet.se/api/packages/khn/debian/pool/bookworm/main/upload"
fi
for package in build/*.deb; do
curl --user ${API_USER}:${API_KEY} --upload-file $package ${API_URL}
done
}
# If no arguments are given, then print usage
if [ $# -eq 0 ]; then
usage
fi
while getopts "bcu" opt; do
case $opt in
b)
build
;;
c)
clean
;;
u)
upload
;;
*)
usage
;;
esac
done