-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·80 lines (72 loc) · 1.54 KB
/
build.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
#!/bin/bash
set -e
HELP=true
DEPLOY=false
BUILD=false
EXTRACT=false
DEPLOY_ON=""
while (( "$#" )); do
case "$1" in
deploy)
DEPLOY=true
HELP=false
shift 1
;;
build)
BUILD=true
HELP=false
shift 1
;;
extract)
EXTRACT=true
HELP=false
shift 1
;;
--help)
HELP=true
shift 1
;;
--deploy-on)
DEPLOY_ON="$2"
shift 2
;;
--) # end argument parsing
shift
break
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
if $HELP; then cat <<-END
Usage:
------
Build or deploy the openwrt image
build: Build openwrt inside a docker container
deploy: Deploy the last built image on the --deploy-device
extract: Extract the image from the docker image and place in the bin/ folder
--deploy-on /dev/sda: Flash the image on the device /dev/sda
--help: Show this help
END
exit 0
fi
IMAGE_NAME="openwrt"
echo "Selecting image $IMAGE_NAME"
if $BUILD; then
docker build -t $IMAGE_NAME --build-arg "MAKE_ARGS=$MAKE_ARGS" .
echo "Image $IMAGE_NAME successfully built"
fi
if $DEPLOY; then
docker run --rm "--device=$DEPLOY_ON" $IMAGE_NAME deploy "$DEPLOY_ON"
echo "Image $IMAGE_NAME successfully copied to $DEPLOY_ON"
fi
if $EXTRACT; then
docker run --rm -v "$(pwd)/bin:/opt/bin" $IMAGE_NAME extract
echo "Image successfully copied to bin/"
fi