-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_frr.sh
executable file
·54 lines (46 loc) · 1.72 KB
/
build_frr.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
#!/bin/bash
# Usage: ./script_name.sh <branch_name> <frr_version>
BRANCH=$1
FRR_VERSION=$2
CONTAINER=frrbuild
IMAGE_NAME="piotrsuchydocker/tinynetlab:frrbuild-${FRR_VERSION}-debian-11"
REPO="https://github.com/piotrsuchy/frr.git"
echo "Checking if docker image ${IMAGE_NAME} is running..."
if ! docker images ${IMAGE_NAME} | grep -q ${IMAGE_NAME}; then
echo "Image ${IMAGE_NAME} does not exist. Attempting to pull from registry..."
if ! docker pull ${IMAGE_NAME}; then
echo "Pull failed. Attempting to build the image locally..."
if ! docker build -t ${IMAGE_NAME} ./docker/frr/build; then
echo "Failed to build the image."
exit 1
fi
else
echo "Pull successful"
fi
fi
docker stop ${CONTAINER}
docker rm ${CONTAINER}
echo "Checking if the container ${CONTAINER} is running..."
if ! docker ps | grep -q ${CONTAINER}; then
echo "Container frrbuild is not running. Starting container..."
docker run --init --privileged -itd --name ${CONTAINER} ${IMAGE_NAME}
else
echo "Docker container ${CONTAINER} is running properly"
fi
echo "Cloning the repo into the container on branch ${BRANCH}..."
if docker exec ${CONTAINER} git clone -b ${BRANCH} ${REPO}; then
echo "Repository cloned successfully."
else
echo "Failed to clone repository."
exit 1
fi
echo "Building FRR .deb package..."
if docker exec ${CONTAINER} /bin/bash -c "cd frr && dpkg-buildpackage -b -rfakeroot --no-sign -Ppkg.frr.nortrlib,pkg.frr.nolua"; then
echo ".deb package built successfully."
docker exec ${CONTAINER} bash -c 'mkdir -p debs'
docker exec ${CONTAINER} bash -c 'mv /root/*.deb debs'
docker cp ${CONTAINER}:/root/debs .
else
echo "Failed to build .deb package."
exit 1
fi