discover/sysinfo: Set IPv6 addresses
[petitboot] / docker / build-pb
1 #!/usr/bin/env bash
2
3 set -e
4
5 name="$(basename $0)"
6
7 : ${TOP_DIR:="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"}
8
9 source ${TOP_DIR}/docker/builder-include
10
11 usage () {
12         echo "${name} - Builds the petitboot programs using a pb-builder container." >&2
13         echo "Usage: ${name} [flags]" >&2
14         echo "Option flags:" >&2
15         echo "  -c --check       - Run 'make check'." >&2
16         echo "  -d --dry-run     - Do not run docker commands." >&2
17         echo "  -h --help        - Show this help and exit." >&2
18         echo "  -i --interactive - Run an interactive pb-builder container." >&2
19         echo "  -t --tag         - Print Docker tag to stdout and exit." >&2
20         echo "  -v --verbose     - Verbose execution." >&2
21         echo "Environment:" >&2
22         echo "  DOCKER_TAG       - Default: '${DOCKER_TAG}'" >&2
23         echo "Examples:" >&2
24         echo "  ${name} -vc"
25         echo "  ${name} -v"
26 }
27
28 short_opts="cdhitv"
29 long_opts="check,dry-run,help,interactive,tag,verbose"
30
31 opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${name}" -- "$@")
32
33 if [ $? != 0 ]; then
34         echo "${name}: ERROR: Internal getopt" >&2 
35         exit 1
36 fi
37
38 eval set -- "${opts}"
39
40 while true ; do
41         case "${1}" in
42         -c | --check)
43                 check=1
44                 shift
45                 ;;
46         -d | --dry-run)
47                 dry_run=1
48                 shift
49                 ;;
50         -h | --help)
51                 usage=1
52                 shift
53                 ;;
54         -i | --interactive)
55                 interactive=1
56                 shift
57                 ;;
58         -t | --tag)
59                 tag=1
60                 shift
61                 ;;
62         -v | --verbose)
63                 set -x
64                 verbose=1
65                 shift
66                 ;;
67         --)
68                 shift
69                 break
70                 ;;
71         *)
72                 echo "${name}: ERROR: Internal opts" >&2 
73                 exit 1
74                 ;;
75         esac
76 done
77
78 if [[ -n "${usage}" ]]; then
79         usage
80         exit 0
81 fi
82
83 if [[ -n "${tag}" ]]; then
84         show_tag
85         exit 0
86 fi
87
88 docker_base_args="\
89         --rm \
90         -v /etc/group:/etc/group:ro \
91         -v /etc/passwd:/etc/passwd:ro \
92         -v ${TOP_DIR}:/opt/pb \
93         -w /opt/pb \
94 "
95
96 docker_user_args="-u $(id -u):$(id -g)"
97
98 if [[ -n "${interactive}" ]]; then
99         cd "${TOP_DIR}"
100         docker_args="${docker_base_args}"
101         run_cmd "docker run -it ${docker_args} ${DOCKER_TAG} /bin/bash"
102         exit
103 fi
104
105 if [[ -n "${verbose}" ]]; then
106         bash_debug="-x"
107 fi
108
109 if [[ -n "${check}" ]]; then
110         docker_extra="make check"
111 else
112         docker_extra="true"
113 fi
114
115 cd "${TOP_DIR}"
116 docker_args="${docker_base_args} ${docker_user_args}"
117 run_cmd "docker run ${docker_args} ${DOCKER_TAG} /bin/bash \
118         -e ${bash_debug} \
119         -c './bootstrap && ./configure --with-ncurses && make && ${docker_extra}'"