@@ -22,6 +22,34 @@ TAG="pihole:local"
22
22
DOCKER_BUILD_CMD=" docker buildx build src/. --tag ${TAG} --load --no-cache"
23
23
FTL_FLAG=false
24
24
25
+ # Check if buildx is installed
26
+ docker buildx version > /dev/null 2>&1
27
+ if [ $? -ne 0 ]; then
28
+ echo " Error: Docker buildx is required to build this image. For installation instructions, see:"
29
+ echo " https://github.com/docker/buildx#installing"
30
+ exit 1
31
+ fi
32
+
33
+ # Function to check if a custom branch entered by the user is valid
34
+ check_branch_exists () {
35
+ local repo=$1
36
+ local branch=$2
37
+ local url
38
+
39
+ if [ " $repo " == " ftl" ]; then
40
+ # Special case for FTL - we check for the binary instead of just the branch - in case it is not yet built.
41
+ url=" https://ftl.pi-hole.net/${branch} /pihole-FTL-amd64"
42
+ else
43
+ url=" https://github.com/pi-hole/${repo} /blob/${branch} /README.md"
44
+ fi
45
+
46
+ local http_code=$( curl -sI " $url " -o /dev/null -w " %{http_code}" )
47
+ if [ $http_code -ne 200 ]; then
48
+ echo " Error: $repo branch '$branch ' not found. Exiting."
49
+ exit 1
50
+ fi
51
+ }
52
+
25
53
# Parse command line arguments
26
54
while [[ $# -gt 0 ]]; do
27
55
key=" $1 "
@@ -47,24 +75,28 @@ while [[ $# -gt 0 ]]; do
47
75
fi
48
76
FTL_FLAG=true
49
77
FTL_BRANCH=" $2 "
78
+ check_branch_exists " ftl" " $FTL_BRANCH "
50
79
DOCKER_BUILD_CMD+=" --build-arg FTL_BRANCH=$FTL_BRANCH "
51
80
shift
52
81
shift
53
82
;;
54
83
-c | --corebranch)
55
84
CORE_BRANCH=" $2 "
85
+ check_branch_exists " pi-hole" " $CORE_BRANCH "
56
86
DOCKER_BUILD_CMD+=" --build-arg CORE_BRANCH=$CORE_BRANCH "
57
87
shift
58
88
shift
59
89
;;
60
90
-w | --webbranch)
61
91
WEB_BRANCH=" $2 "
92
+ check_branch_exists " web" " $WEB_BRANCH "
62
93
DOCKER_BUILD_CMD+=" --build-arg WEB_BRANCH=$WEB_BRANCH "
63
94
shift
64
95
shift
65
96
;;
66
97
-p | --paddbranch)
67
98
PADD_BRANCH=" $2 "
99
+ check_branch_exists " padd" " $PADD_BRANCH "
68
100
DOCKER_BUILD_CMD+=" --build-arg PADD_BRANCH=$PADD_BRANCH "
69
101
shift
70
102
shift
0 commit comments