-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenter.in
119 lines (96 loc) · 3.4 KB
/
enter.in
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
#!/bin/sh
#
# This script runs a shell inside chroot as a 'build' user. If any arguments
# supplied, those are the command to be run, otherwise the interactive shell
# will be invoked.
#
CHROOT_PATH=$0
case "$0" in
/*) CHROOT_PATH=$(dirname "$0");;
*) CHROOT_PATH=$(dirname $(pwd)/"$0");;
esac
HTTP_PROXY=@@HTTP_PROXY@@
FTP_PROXY=@@FTP_PROXY@@
# Quote argument for shell.
# Usage example: eval "$var_name=\"$(quote_shell "$var_value")\""
quote_shell() {
local out="$*"
if [ -z "${out##*[\"\$\`\\\\]*}" ]; then
out="$(printf %s "$out" |sed -e 's/["$`\\]/\\&/g')" ||
return 1
fi
printf %s "$out"
#` # Hey, Emacs, your syntax highlighter is wrooong!
#'` # You too, gedit!
}
quote_args() {
for i in "$@"; do
echo -n \"$(quote_shell "$i")\"
echo -n " "
done
echo
}
# A space-separated list of mounted repositories
mounted_repos=
# Unmount all mounted repositories
unmount_repos() {
for _mounted_repo in $mounted_repos; do
# Unmount repository no matter what.
sudo umount "$_mounted_repo" 2> /dev/null || :
# Remove the repo directory and any empty parent directories
sudo rmdir -p "$_mounted_repo" 2> /dev/null || :
done
exit
}
# Mount a repository directory
mount_repo() {
_chroot_path=$1
_local_rep=$2
# Strip any meaningless trailing dots and slashes from the chroot path
_trimmed_chroot_path=$(echo "$_chroot_path" | sed 's|/\.\?$||')
# If the local repo directory isn't already mounted
if ! fgrep -q "$_trimmed_chroot_path$_local_rep" < /etc/mtab; then
# Make a mount dir within chroot and mount the local repo dir to it
sudo mkdir -p "$_trimmed_chroot_path$_local_rep"
sudo mount --bind "$_local_rep" "$_trimmed_chroot_path$_local_rep"
# Add local repo to list of mounted repos
mounted_repos=`echo "$mounted_repos $_trimmed_chroot_path$_local_rep"`
# Call unmount_repos to clean up the local repos when the script is
# exited or interrupted
trap unmount_repos TERM INT EXIT
fi
}
if [ "$#" -eq 0 ]; then
# Interactive shell
SU_CMD="-i -l"
else
# Single command. Double quoting to pass through two su(1) invocations. Blergh.
S=$(quote_args "$@")
QS=$(quote_args "$S")
SU_CMD="-c $QS"
fi
if [ -n "$HTTP_PROXY" ]; then
ENV_EXPORT="http_proxy=$HTTP_PROXY; export http_proxy;"
fi
if [ -n "$FTP_PROXY" ]; then
ENV_EXPORT="$ENV_EXPORT ftp_proxy=$FTP_PROXY; export ftp_proxy;"
fi
if [ -f /proc/cpuinfo ]; then
NCPUS=$(grep -c '^processor' /proc/cpuinfo)
ENV_EXPORT="$ENV_EXPORT DEB_BUILD_OPTIONS=parallel=$NCPUS"
fi
# Mount every local repository in the chroot's sources.list file that doesn't
# exist in the chroot file system.
# All the local repositories mentioned in chroot's sources.list file
local_repos=$(egrep -o '(file:[^[:space:]]+)' < "$CHROOT_PATH/etc/apt/sources.list" | sed 's/file://')
for local_repo in $local_repos; do
# If the directory doesn't exist in the chroot file system
if [ ! -e "$CHROOT_PATH$local_repo" ]; then
# If the directory does exist in the exterior file system
if [ -d "$local_repo" ]; then
# Make a mount dir and mount the exterior repository dir to it
mount_repo "$CHROOT_PATH" "$local_repo"
fi
fi
done
sudo chroot "$CHROOT_PATH" su -l -c "$ENV_EXPORT exec \$SHELL $SU_CMD" build