-
Notifications
You must be signed in to change notification settings - Fork 20
/
shell
executable file
·117 lines (106 loc) · 2.72 KB
/
shell
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=internal/lib/library.sh
source "$SELFDIR/internal/lib/library.sh"
# shellcheck source=internal/lib/distro_info.sh
source "$SELFDIR/internal/lib/distro_info.sh"
WORK_DIR=
CACHE_DIR=
DISTRIBUTIONS="$DEFAULT_DISTROS"
ARCHITECTURES="amd64 arm64"
function usage()
{
echo "Usage: ./shell [OPTIONS] <TASK NAMES...>"
echo "Open a shell in a build box container."
echo
echo "Required options:"
echo " -c DIR Path to cache directory"
echo
echo "Optional options:"
echo " -w DIR Path to work directory (for temporary files)"
echo " -d NAMES Build only for given distributions. This is a space-separated list"
echo " of distribution names."
echo " Default: $DEFAULT_DISTROS"
echo " -a NAMES Build only for given architectures. This is a space-separated list"
echo " of architecture names."
echo " Default: $ARCHITECTURES"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local opt
while getopts "c:w:d:a:h" opt; do
case "$opt" in
c)
CACHE_DIR="$OPTARG"
;;
w)
WORK_DIR="$OPTARG"
;;
d)
DISTRIBUTIONS="$OPTARG"
;;
a)
ARCHITECTURES="$OPTARG"
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
if [[ "$CACHE_DIR" = "" ]]; then
echo "ERROR: please specify a cache directory with -c."
exit 1
fi
}
parse_options "$@"
DOCKER_OPTIONS=()
CACHE_DIR=$(absolute_path "$CACHE_DIR")
run mkdir -p "$CACHE_DIR"
run mkdir -p "$CACHE_DIR/pbuilder/ccache"
BUILDBOX_IMAGE=$(get_buildbox_image)
if [[ "$WORK_DIR" != "" ]]; then
WORK_DIR=$(absolute_path "$WORK_DIR")
run mkdir -p "$WORK_DIR"
DOCKER_OPTIONS+=(-v "$WORK_DIR:/work")
fi
echo "+ Initializing ccache directory"
verbose_run docker run \
--rm -t -i \
-v "$SELFDIR:/system:ro" \
-v "$CACHE_DIR:/cache" \
-e "DISTRIBUTIONS=$DISTRIBUTIONS" \
-e "ARCHITECTURES=$ARCHITECTURES" \
-e "APP_UID=$(/usr/bin/id -u)" \
-e "APP_GID=$(/usr/bin/id -g)" \
$BUILDBOX_IMAGE \
/system/internal/scripts/inituidgid.sh \
/system/internal/scripts/initccache.sh
echo "-------- Entering Docker container --------"
exec docker run \
--rm -t -i \
--privileged \
-v "$SELFDIR:/system:ro" \
-v "$CACHE_DIR:/cache" \
-v "$CACHE_DIR/pbuilder:/var/cache/pbuilder" \
-e "DISTRIBUTIONS=$DISTRIBUTIONS" \
-e "ARCHITECTURES=$ARCHITECTURES" \
-e "APP_UID=$(/usr/bin/id -u)" \
-e "APP_GID=$(/usr/bin/id -g)" \
-e "LC_CTYPE=C.UTF-8" \
"${DOCKER_OPTIONS[@]}" \
$BUILDBOX_IMAGE \
/sbin/my_init --quiet --skip-runit --skip-startup-files -- \
/system/internal/scripts/inituidgid.sh \
/system/internal/shell/preinit.sh \
/sbin/setuser app \
/bin/bash -l