4 if ! type docker >/dev/null 2>&1; then
5 echo "You have to install docker in your system before." 1>&2
9 if ! docker info >/dev/null 2>&1; then
11 Cannot connect to docker socket.
12 Please make sure that you have the right permission to use docker and the docker daemon has been running correctly.
17 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
20 echo "usage ${0} [options]"
22 echo " General options:"
23 echo " -o | --build-opiton \"[options]\" Set build options passed to build.sh"
24 echo " -d | --dist-out-dir \"[path]\" Set distributions' output directory"
25 echo " -w | --work-dir \"[path]\" Set build working dir for debug"
26 echo " -n | --noninteractive The process will not ask you any questions"
27 echo " -c | --clean Enable --no-cache option when building docker image"
28 echo " -s | --no-share-pkgfile Disable pacman pkgcache"
29 echo " -p | --pkg-cache-dir \"[path]\" Set pacman pkg cache directory"
30 echo " -h | --help This help message and exit"
35 if [[ -d "/var/cache/pacman/pkg" ]] && [[ -d "/var/lib/pacman/sync" ]]; then
36 SHARE_PKG_DIR="/var/cache/pacman/pkg"
37 SHARE_DB_DIR="/var/lib/pacman/sync"
39 SHARE_PKG_DIR="${script_path}/cache/pkg"
40 SHARE_DB_DIR="${script_path}/cache/sync"
45 DIST_DIR="${script_path}/out"
48 while (( ${#} > 0 )); do
51 # -o: dists output dir option in build.sh
52 if [[ "${2}" == *"-o"* ]]; then
53 echo "The -o option cannot be set with docker build. Please use -d option instead." 1>&2
57 #BUILD_SCRIPT_OPTS+=(${2})
58 IFS=" " read -r -a BUILD_SCRIPT_OPTS <<< "${2}"
64 echo "Error: failed creating output directory: ${2}" 1>&2
67 DIST_DIR=$(cd -P ${2} && pwd)
72 echo "Error: failed creating working directory: ${2}" 1>&2
75 EXTERNAL_WORK_DIR=$(cd -P "${2}" && pwd)
78 -n | --noninteractive)
79 BUILD_SCRIPT_OPTS+=(--noconfirm)
83 # Enable docker's --no-cache option
84 DOCKER_BUILD_OPTS+=(--no-cache)
87 -s | --no-share-pkgfile)
92 if [[ -d "${2}" ]] && \
93 mkdir -p "${2}/pkg" && \
96 SHARE_PKG_DIR="${2}/pkg"
97 SHARE_DB_DIR="${2}/sync"
99 echo "Error: The directory is not found or cannot make directory." 1>&2
112 msg_error "Invalid argument '${1}'"
119 if [[ -d "/usr/lib/modules/$(uname -r)" ]]; then
120 KMODS_DIR="/usr/lib/modules"
122 KMODS_DIR="/lib/modules"
126 DOCKER_RUN_OPTS+=(-v "${DIST_DIR}:/alterlinux/out")
127 DOCKER_RUN_OPTS+=(-v "${KMODS_DIR}:/usr/lib/modules:ro")
128 [[ "x${EXTERNAL_WORK_DIR}" != "x" ]] && \
129 DOCKER_RUN_OPTS+=(-v "${EXTERNAL_WORK_DIR}:/alterlinux/work")
130 [[ "x${NO_SHARE_PKG}" != "xTrue" ]] && {
131 DOCKER_RUN_OPTS+=(-v "${SHARE_PKG_DIR}:/var/cache/pacman/pkg")
132 DOCKER_RUN_OPTS+=(-v "${SHARE_DB_DIR}:/var/lib/pacman/sync")
135 tty >/dev/null 2>&1 && OPT_TTY="-it" || OPT_TTY=""
137 docker build "${DOCKER_BUILD_OPTS[@]}" -t alterlinux-build:latest "${script_path}"
138 exec docker run --rm ${OPT_TTY} --privileged -e _DOCKER=true "${DOCKER_RUN_OPTS[@]}" alterlinux-build "${BUILD_SCRIPT_OPTS[@]}"