OSDN Git Service

fixed ply
[alterlinux/LFBS.git] / docker-build.sh
1 #!/usr/bin/env bash
2 set -e
3
4 if [[ $UID != 0 ]]; then
5     echo "You have to run this as root." 1>&2
6     exit 1
7 fi
8
9 if ! type docker >/dev/null 2>&1; then
10     echo "You have to install docker." 1>&2
11     exit 1
12 fi
13
14 _usage () {
15     echo "usage ${0} [options]"
16     echo
17     echo " General options:"
18     echo "    -o | --build-opiton \"[options]\"     send the build option to ./lfbs"
19     echo "    -c | --clean                          Enable --no-cache option when build docker image"
20     echo "    -h | --help                           This help message and exit"
21     echo
22 }
23
24 # Start parse options
25 ARGUMENT="${@}"
26 while (( $# > 0 )); do
27     case ${1} in
28         -o | --build-opiton)
29             BUILD_OPT="${2}"
30             shift 2
31             ;;
32         -c | --clean)
33             NO_CACHE="--no-cache" # Enable --no-cache option
34             shift 1
35             ;;
36         -h | --help)
37             _usage
38             exit 0
39             ;;
40         --)
41             shift
42             break
43             ;;
44         *)
45             msg_error "Invalid argument '${1}'"
46             _usage 1
47             ;;
48     esac
49 done
50
51
52 # End parse options
53
54 SCRIPT_DIR=$(cd $(dirname $0); pwd)
55 cd ${SCRIPT_DIR}
56 docker build ${NO_CACHE} -t lfbs-build:latest .
57 docker run -t -i --privileged -v ${SCRIPT_DIR}/out:/lfbs/out -v /usr/lib/modules:/usr/lib/modules:ro -v ${SCRIPT_DIR}/cache:/lfbs/cache lfbs-build "${BUILD_OPT}"