-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshell
More file actions
executable file
·177 lines (166 loc) · 5.02 KB
/
Copy pathshell
File metadata and controls
executable file
·177 lines (166 loc) · 5.02 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/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"
PASSENGER_DIR=
WORK_DIR=
CACHE_DIR=
OUTPUT_DIR=
CONCURRENCY=1
DISTRIBUTIONS="$DEFAULT_DISTROS"
RPM_ARCH=$(uname -m)
DOCKER_ARCH=$(uname -m)
FETCH_PASSENGER_TARBALL_FROM_CACHE=true
CLEAR_WORK_DIR=true
SHOW_OVERVIEW_PERIODICALLY=false
SHOW_BACKTRACES=false
function usage()
{
echo "Usage: ./shell [OPTIONS]"
echo "Open a shell in a build box container."
echo
echo "Required options:"
echo " -p DIR Path to Passenger source directory"
echo " -w DIR Path to work directory (for temporary files)"
echo " -c DIR Path to cache directory"
echo " -o DIR Path in which to store build products"
echo " -a NAME RPM architecture name. This must be a single architecture"
echo " name, not a list, and must agree with -A."
echo " Default: $RPM_ARCH, allowed values: aarch64, x86_64"
echo " -A NAME Docker architecture name. This must be a single architecture"
echo " name, not a list, and must agree with -a."
echo " Default: $DOCKER_ARCH, allowed values: arm64, amd64"
echo
echo "Optional options:"
echo " -j NUM Set build concurrency. Default: 1"
echo " -d NAMES Shell for building only given distributions. This is a space-separated list"
echo " of distribution names."
echo " Default: $DEFAULT_DISTROS"
echo " -R Do not fetch Passenger tarball from cache"
echo " -N Do not clear work directory on startup"
echo " -O Periodically show progress overview"
echo " -t Show backtraces on error"
echo
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local opt
while getopts "p:w:c:o:j:d:a:A:RNOth" opt; do
case "$opt" in
p)
PASSENGER_DIR="$OPTARG"
;;
w)
WORK_DIR="$OPTARG"
;;
c)
CACHE_DIR="$OPTARG"
;;
o)
OUTPUT_DIR="$OPTARG"
;;
j)
CONCURRENCY=$OPTARG
;;
d)
DISTRIBUTIONS="$OPTARG"
;;
a)
read -ra RPM_ARCH <<< "$OPTARG"
;;
A)
read -ra DOCKER_ARCH <<< "$OPTARG"
;;
t)
SHOW_BACKTRACES=true
;;
R)
FETCH_PASSENGER_TARBALL_FROM_CACHE=false
;;
N)
CLEAR_WORK_DIR=false
;;
O)
SHOW_OVERVIEW_PERIODICALLY=true
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
BUILDBOX_IMAGE=$(get_buildbox_image)
if [[ "$PASSENGER_DIR" = "" ]]; then
echo "ERROR: please specify a Passenger source directory with -p."
exit 1
fi
if [[ ! -e "$PASSENGER_DIR" ]]; then
echo "ERROR: $PASSENGER_DIR does not exist."
exit 1
fi
if [[ 1 != "${#DOCKER_ARCH[@]}" ]]; then
echo "ERROR: $DOCKER_ARCH must be a single arch name."
exit 1
fi
if [[ 1 != "${#RPM_ARCH[@]}" ]]; then
echo "ERROR: $RPM_ARCH must be a single arch name."
exit 1
fi
if [[ "$WORK_DIR" = "" ]]; then
echo "ERROR: please specify a work directory with -w."
exit 1
fi
if [[ "$CACHE_DIR" = "" ]]; then
echo "ERROR: please specify a cache directory with -c."
exit 1
fi
if [[ "$OUTPUT_DIR" = "" ]]; then
echo "ERROR: please specify an output directory with -o."
exit 1
fi
}
parse_options "$@"
PASSENGER_DIR=$(absolute_path "$PASSENGER_DIR")
WORK_DIR=$(absolute_path "$WORK_DIR")
CACHE_DIR=$(absolute_path "$CACHE_DIR")
OUTPUT_DIR=$(absolute_path "$OUTPUT_DIR")
run mkdir -p "$WORK_DIR"
run mkdir -p "$CACHE_DIR"
run mkdir -p "$OUTPUT_DIR"
echo "-------- Entering Docker container --------"
exec docker run \
--rm -it \
--privileged \
-v "$SELFDIR:/system:ro" \
-v "$PASSENGER_DIR:/passenger:ro" \
-v "$WORK_DIR:/work" \
-v "$CACHE_DIR:/cache" \
-v "$OUTPUT_DIR:/output" \
-e "DISTRIBUTIONS=$DISTRIBUTIONS" \
-e "RPM_ARCH=$RPM_ARCH" \
-e "SHOW_OVERVIEW_PERIODICALLY=$SHOW_OVERVIEW_PERIODICALLY" \
-e "FETCH_PASSENGER_TARBALL_FROM_CACHE=$FETCH_PASSENGER_TARBALL_FROM_CACHE" \
-e "APP_UID=$(/usr/bin/id -u)" \
-e "APP_GID=$(/usr/bin/id -g)" \
-e "LC_CTYPE=C.UTF-8" \
-e "CONCURRENCY=$CONCURRENCY" \
-e "CLEAR_WORK_DIR=$CLEAR_WORK_DIR" \
--platform "linux/$DOCKER_ARCH" \
"$BUILDBOX_IMAGE" \
/system/internal/scripts/my_init --quiet --skip-runit --skip-startup-files -- \
/system/internal/scripts/inituidgid.sh \
/system/internal/build/preinit.sh \
/system/internal/scripts/setuser app \
/system/internal/build/resetpaths.sh \
/bin/bash -l