-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.sh
executable file
·216 lines (191 loc) · 3.69 KB
/
exec.sh
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env bash
#
# Copyright 2021-2024 Gaël PORTAY
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
unset LD_PRELOAD
unset LD_LIBRARY_PATH
log() {
level="$1"
shift
if [ ! -t 2 ] || [ "${NO_COLOR:-0}" -ne 0 ]
then
echo "$level:" "$@" >&2
return
fi
echo -e "\e[31;1m$level:\e[0m" "$@" >&2
}
error() {
log "Error" "$@"
}
warn() {
log "Warning" "$@"
}
fixme() {
log "FIXME" "$@"
}
notice() {
if [ "${IAMROOT_DEBUG:-0}" -le 1 ]
then
return
fi
log "Notice" "$@"
}
info() {
if [ "${IAMROOT_DEBUG:-0}" -le 2 ]
then
return
fi
log "Info" "$@"
}
path_resolution() {
if [ "${1:0:1}" != / ]
then
echo "$PWD/${1#/*}"
return
fi
echo "$IAMROOT_ROOT/${1#/*}"
}
if [ $# -eq 0 ]
then
echo "Usage: $0 COMMAND [ARGUMENTS...]" >&2
error "Too few arguments!"
exit 1
fi
path="$1"
inchroot_path="$(path_resolution "$path")"
argv0="${_argv0:-$path}"
shift
case "${path##*/}" in
mount|umount)
notice "not-running" "$argv0" "$@"
exit 0
;;
mountpoint)
args=()
for i in "$@"
do
if [ "${i:0:1}" = "-" ]
then
args+=("$i")
else
args+=("$IAMROOT_ROOT$i")
fi
done
set -- "${args[@]}"
unset args
notice "running" "$inchroot_path" "$@"
exec "$inchroot_path" "$@"
;;
build-locale-archive|chfn|chkstat|*.postinst)
fixme "not-running" "$argv0" "$@"
exit 0
;;
busybox)
info "running" "$inchroot_path" "$@"
exec "$inchroot_path" "$@"
;;
# /sbin/ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
# /usr/sbin/glibc_post_upgrade: While trying to execute /sbin/ldconfig child exited with exit code 1
glibc_post_upgrade.*)
if [ -r "$IAMROOT_ROOT/etc/ld.so.conf" ] &&
! grep -q "^include /etc/ld.so.conf.d/*.conf$" "$IAMROOT_ROOT/etc/ld.so.conf"
then
echo "include /etc/ld.so.conf.d/*.conf" >"$IAMROOT_ROOT/etc/ld.so.conf"
fi
if [ "${IAMROOT_ROOT:-/}" != / ]
then
exec "$IAMROOT_ROOT/sbin/ldconfig" -r "$IAMROOT_ROOT"
fi
exec "/sbin/ldconfig"
;;
ldconfig|ldconfig.real)
if [ "${IAMROOT_ROOT:-/}" != / ]
then
args=()
r=
f=
prev=
for cur in "$@"
do
if [ "$prev" = "-r" ]
then
args+=("$(path_resolution "$cur")")
r="${args[-1]}"
elif [ "$prev" = "-f" ]
then
args+=("$(path_resolution "$cur")")
f="${args[-1]}"
elif [ "${cur:0:1}" != "-" ]
then
args+=("$(path_resolution "$cur")")
else
args+=("$cur")
fi
prev="$cur"
done
unset prev
unset cur
if [ ! "$r" ]
then
args+=(-r "$IAMROOT_ROOT")
fi
unset r
if [ ! "$f" ]
then
f="$IAMROOT_ROOT/etc/ld.so.conf"
fi
# Fixes: $IAMROOT_ROOT/usr/sbin/ldconfig: need absolute file name for configuration file when using -r
if [ -r "$f" ]
then
sed -e 's,include ld.so.conf.d/\*.conf,include /etc/ld.so.conf.d/*.conf,' \
-i "$f"
fi
unset f
set -- "${args[@]}"
unset args
fi
notice "running" "$inchroot_path" "$@"
exec "$inchroot_path" "$@"
;;
gpasswd|passwd|su)
error "not-running" "$argv0" "$@"
exit 1
;;
bbsuid)
for i in /bin/mount /bin/umount /bin/su /usr/bin/crontab /usr/bin/passwd /usr/bin/traceroute /usr/bin/traceroute6 /usr/bin/vlock
do
ln -sf /bin/bbsuid "$IAMROOT_ROOT$i"
done
exit 0
;;
ldd)
args=()
for i in "$@"
do
if [ "${i:0:1}" = "-" ]
then
args+=("$i")
else
args+=("$IAMROOT_ROOT$i")
fi
done
set -- "${args[@]}"
unset args
# Do not pollute stderr with a warning trace!
#warn "running" "$inchroot_path" "$@"
# FIXME: reuse implementation within the library.
LD_LIBRARY_PATH="$IAMROOT_ROOT/lib:$IAMROOT_ROOT/usr/lib" \
exec "$inchroot_path" "$@" | sed "s,$IAMROOT_ROOT,,g"
;;
ld*.so*)
# Do not pollute stderr with a warning trace!
# warn "running" "$inchroot_path" "$@"
exec "$inchroot_path" "$@"
;;
*)
warn "running" "$inchroot_path" "$@"
exec "$inchroot_path" "$@"
;;
esac