run-build.sh 2.32 KB
Newer Older
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
#!/bin/bash
#set -x
opt=$2
export USERUID="$(id -u)"
export USERGID="$(id -g)"
DCKRIMAGE="mt7621-imagebuild:master"
DCKRNAME="mt7621-openwrt-imagebuild"
BARGS="--build-arg USERUID=$USERUID --build-arg USERGID=$USERGID"
ARGS="--rm --name $DCKRNAME -d --cap-add NET_ADMIN -v $PWD/openwrt:/home/buser/openwrt"

# Check if docker image exist, if not build image
if test ! -z "$(docker images -q $DCKRIMAGE)"; then
   echo "Ready to Start!"
else
   echo "$DCKRIMAGE doesnt exist!, running './$0 build-image' first!"
   docker build $BARGS -t $DCKRIMAGE -f Dockerfile.build .
fi

case "$1" in
  build-image)
    docker build $BARGS -t $DCKRIMAGE -f Dockerfile.build .
    ;;
  build-official)
    docker run $ARGS $DCKRIMAGE build-official $opt
    echo "Build started - now watching $DCKRNAME"
    echo "Press CTRL+C to stop watching!"
    echo "To stop build completely - '$0 stop'"
    docker logs -f $DCKRNAME
    ;;
30
31
32
33
34
35
36
  build-custom)
    docker run $ARGS $DCKRIMAGE build-custom $opt
    echo "Build started - now watching $DCKRNAME"
    echo "Press CTRL+C to stop watching!"
    echo "To stop build completely - '$0 stop'"
    docker logs -f $DCKRNAME
    ;;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  rebuild)
    docker run $ARGS $DCKRIMAGE build-rebuild
    ;;
  clean-min)
    docker run $ARGS $DCKRIMAGE clean-min
    ;;
  clean-full)
    docker run $ARGS $DCKRIMAGE clean-full
    ;;
  watch-build)
    echo "Press CTRL+C to stop watching!"
    echo "To stop build completely - '$0 stop'"
    sleep 5
    docker logs -f $DCKRNAME
    ;;
  stop)
    docker stop -t 60 $DCKRNAME
    ;;
  shell)
    docker run --rm --name $DCKRNAME -it --entrypoint /bin/bash \
    --cap-add NET_ADMIN -v $PWD/openwrt:/home/buser/openwrt $DCKRIMAGE
    ;;
  *)
60
    echo "Usage: $0 {build-image|build-official|build-custom|rebuild|clean-min|clean-full|stop}" >&2
61
62
    echo "build-image: Build $DCKRIMAGE to build openwrt firmware images" >&2
    echo "build-official: Build Openwrt with official config using $DCKRIMAGE" >&2
63
    echo "build-custom: Build Openwrt with custom config (Custom.config) using $DCKRIMAGE" >&2
64
65
66
67
68
69
70
71
    echo "rebuild: Restart build process" >&2
    echo "clean-min: Cleanup minimum build - keep config" >&2
    echo "clean-full: Cleanup full build - clean slate" >&2
    echo "watch-build: Watch the Openwrt build on container" >&2
    echo "shell: Enter bash shell in docker container" >&2
    exit 1
    ;;
esac