-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·145 lines (122 loc) · 3.99 KB
/
build
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
143
144
145
#!/bin/bash -ex
##################################################
#
# ./build DISTRO [DOCKER_TAG]
#
# If no docker tag, `latest` is used
#
# ie:
# ./build debian 9
#
##################################################
CWD=$(pwd)
CYAN='\E[1;36m'
RED='\E[1;31m'
YELLOW='\E[1;33m'
GREEN='\E[1;32m'
BLUE='\E[1;34m'
RESET='\E[0m'
DISTRO=$1
if [ "$DISTRO" == "" ]; then
echo -en "${RED}ERROR: ${RESET}"
echo -e "You must specify a Distro to build for: debian, mint"
echo "ie: ./build debian"
exit 1
fi
DOCKER_TAG=$2
if [ "$DOCKER_TAG" == "" ]; then
DOCKER_TAG=latest
fi
# Make sure jq exists
if ! hash jq 2>/dev/null; then
echo -en "${RED}ERROR: ${RESET}"
echo -e "jq command is required"
exit 1
fi
# Make sure docker exists
if ! hash docker 2>/dev/null; then
echo -en "${RED}ERROR: ${RESET}"
echo -e "docker command is required"
exit 1
fi
# Variables
DOCKER_IMAGE=jc21/dpkg-${DISTRO}
PACKAGE=$(cat dpkg.json | jq -r .PACKAGE)
VERSION=$(cat dpkg.json | jq -r .VERSION)
GH_USER=$(cat dpkg.json | jq -r .GH_USER)
GH_VERSION=$(cat dpkg.json | jq -r .GH_VERSION)
SIGN_KEY=$(cat dpkg.json | jq -r .SIGN_KEY)
URL=
export PACKAGE VERSION GH_USER GH_VERSION
eval "URL=$(cat dpkg.json | jq -r .URL)"
if [ -z "$URL" ]; then
echo -en "${RED}ERROR: ${RESET}"
echo -e "URL could not be determined from dpkg.json file"
exit 1
fi
echo -e "${BLUE}❯ ${GREEN}Building ${CYAN}${PACKAGE} v${VERSION} ${GREEN}for ${DISTRO}:${DOCKER_TAG}${RESET}"
# Clean
rm -rf "${PACKAGE}-${VERSION}"
# Download
echo -e "${BLUE}❯ ${YELLOW}Downloading${RESET}"
if [ -e "${PACKAGE}_${VERSION}.orig.tar.gz" ]; then
echo "${PACKAGE}_${VERSION}.orig.tar.gz exists, skipping..."
else
wget -nv "${URL}" -O "${PACKAGE}_${VERSION}.orig.tar.gz"
fi
# Extract
echo -e "${BLUE}❯ ${YELLOW}Extracting${RESET}"
tar xzf "${PACKAGE}_${VERSION}.orig.tar.gz"
mv "wtf-${VERSION}" "${PACKAGE}-${VERSION}"
# Copy over debian package info
echo -e "${BLUE}❯ ${YELLOW}Setting up ./debian folder${RESET}"
cp -pr debian "${PACKAGE}-${VERSION}"/
# Pull latest builder image
echo -e "${BLUE}❯ ${YELLOW}Pulling docker image: ${DOCKER_IMAGE}:${DOCKER_TAG}${RESET}"
docker pull "${DOCKER_IMAGE}:${DOCKER_TAG}"
# Use the build to change the ownership of folders
echo -e "${BLUE}❯ ${YELLOW}Temporarily changing ownership${RESET}"
docker run --rm \
-v "${CWD}:/home/builder/package" \
-v "${CWD}/sign/.gnupg:/home/builder/.gnupg" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
sudo chown -R builder:builder /home/builder/package /home/builder/.gnupg
# Build
echo -e "${BLUE}❯ ${YELLOW}Building Part 1${RESET}"
set +e
# Docker Run Part 1
docker run --rm \
--name "dpkgbuild-${BUILD_TAG:-dpkg-${DISTRO}-${PACKAGE}}" \
-v "${CWD}:/home/builder/package" \
-v "${CWD}/sign/.gnupg:/home/builder/.gnupg" \
-e "GOPROXY=${GOPROXY}" \
-w "/home/builder/package/${PACKAGE}-${VERSION}" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
sudo mk-build-deps --install --tool='apt-get --no-install-recommends -y' debian/control
BUILD_SUCCESS=$?
# Docker Run Part 2
if [ $BUILD_SUCCESS -eq 0 ]; then
echo -e "${BLUE}❯ ${YELLOW}Building Part 2${RESET}"
docker run --rm \
--name "dpkgbuild-${BUILD_TAG:-dpkg-${DISTRO}-${PACKAGE}}" \
-v "${CWD}:/home/builder/package" \
-v "${CWD}/sign/.gnupg:/home/builder/.gnupg" \
-e "GOPROXY=${GOPROXY}" \
-e "DPKG_COLORS=always" \
-w "/home/builder/package/${PACKAGE}-${VERSION}" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
dpkg-buildpackage --sign-key="${SIGN_KEY}" --force-sign
BUILD_SUCCESS=$?
fi
# Change ownership back
echo -e "${BLUE}❯ ${YELLOW}Reverting ownership${RESET}"
docker run --rm \
-v "${CWD}:/home/builder/package" \
-v "${CWD}/sign/.gnupg:/home/builder/.gnupg" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
sudo chown -R "$(id -u):$(id -g)" /home/builder/package /home/builder/.gnupg
# do we need to exit the loop?
if [ $BUILD_SUCCESS -ne 0 ]; then
echo -e "${BLUE}❯ ${RED}Exiting due to error${RESET}"
exit ${BUILD_SUCCESS}
fi