@ -0,0 +1,165 @@ |
|||||
|
#!/bin/sh |
||||
|
# --- SDE-COPYRIGHT-NOTE-BEGIN --- |
||||
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch. |
||||
|
# |
||||
|
# Filename: bin/sde-prepare-chroot |
||||
|
# Copyright (C) 2006 - 2010 The OpenSDE Project |
||||
|
# Copyright (C) 2004 - 2006 The T2 SDE Project |
||||
|
# Copyright (C) 1998 - 2003 Clifford Wolf |
||||
|
# |
||||
|
# More information can be found in the files COPYING and README. |
||||
|
# |
||||
|
# This program is free software; you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation; version 2 of the License. A copy of the |
||||
|
# GNU General Public License can be found in the file COPYING. |
||||
|
# --- SDE-COPYRIGHT-NOTE-END --- |
||||
|
|
||||
|
#Description: Prepare sandbox for chrooted building |
||||
|
|
||||
|
[ -n "$SDEROOT" ] || |
||||
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P ) |
||||
|
|
||||
|
. "$SDEROOT/lib/libsde.in" |
||||
|
|
||||
|
prepare_usage() { |
||||
|
local progname=$(echo ${0##*/} | tr '-' ' ') |
||||
|
|
||||
|
[ $# -eq 0 ] || echo_error "$@" |
||||
|
cat <<-EOT |
||||
|
Usage: $progname [-u] [-b <sderoot>] <sandbox> ... |
||||
|
EOT |
||||
|
|
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
# parse arguments |
||||
|
shortopts='?ub:' |
||||
|
longopts='help' |
||||
|
options=$(getopt -o "$shortopts" -l "$longopts" -- "$@") |
||||
|
[ $? -eq 0 ] || prepare_usage |
||||
|
|
||||
|
eval set -- "$options" |
||||
|
|
||||
|
chroot_mode=mount |
||||
|
chroot_base="$SDEROOT" |
||||
|
|
||||
|
while [ $# -gt 0 ]; do |
||||
|
case "$1" in |
||||
|
--help) |
||||
|
check_usage |
||||
|
;; |
||||
|
-u) |
||||
|
chroot_mode=umount |
||||
|
;; |
||||
|
-b) |
||||
|
if [ -x "$2/bin/sde" ]; then |
||||
|
chroot_base="$(cd "$2/" && pwd -P)" |
||||
|
echo_info "Using $chroot_base instead of $SDEROOT" |
||||
|
else |
||||
|
prepare_usage "$2: Invalid tree." |
||||
|
fi |
||||
|
;; |
||||
|
|
||||
|
--) |
||||
|
shift; break |
||||
|
;; |
||||
|
*) |
||||
|
break |
||||
|
esac |
||||
|
shift |
||||
|
done |
||||
|
|
||||
|
x_mknod() { |
||||
|
[ -c "$1" -o -b "$1" ] || mknod "$@" |
||||
|
} |
||||
|
|
||||
|
mountpoint() { |
||||
|
grep -q " $1 " /proc/mounts |
||||
|
} |
||||
|
|
||||
|
chroot_mount() { |
||||
|
local realconf= realdown= realbase= realxroot= |
||||
|
local x= s= d= |
||||
|
|
||||
|
[ -d dev/loop ] || mkdir -p dev/loop |
||||
|
x_mknod dev/null c 1 3 |
||||
|
x_mknod dev/zero c 1 5 |
||||
|
x_mknod dev/random c 1 8 |
||||
|
x_mknod dev/urandom c 1 9 |
||||
|
x_mknod dev/loop/0 b 7 0 |
||||
|
x_mknod dev/loop/1 b 7 1 |
||||
|
x_mknod dev/loop/2 b 7 2 |
||||
|
x_mknod dev/loop/3 b 7 3 |
||||
|
#_mknod dev/tty c 5 0 |
||||
|
|
||||
|
[ -L dev/fd ] || ln -s /proc/self/fd dev/fd |
||||
|
|
||||
|
[ -r proc/mounts ] || mount -nt proc none proc |
||||
|
|
||||
|
realxroot=$(pwd -P) |
||||
|
realconf=$(cd "$chroot_base"/config; pwd -P) |
||||
|
realdown=$(cd "$chroot_base"/download; pwd -P) |
||||
|
realbase=$(dirname $(cd "$chroot_base"/scripts; pwd -P)) |
||||
|
|
||||
|
for x in "loop:$realbase" "config:$realconf" "download:$realdown"; do |
||||
|
s="${x#*:}" d="TOOLCHAIN/${x%%:*}" |
||||
|
[ -d "$d" ] || mkdir -p "$d" |
||||
|
|
||||
|
mountpoint "$realxroot/$d" || mount --bind "$s" "$d" |
||||
|
done |
||||
|
|
||||
|
for x in bin etc lib doc src package architecture target; do |
||||
|
[ -e TOOLCHAIN/$x ] || ln -s "loop/$x" "TOOLCHAIN/$x" |
||||
|
done |
||||
|
|
||||
|
x=${realxroot##*/} |
||||
|
if [ ! -e "TOOLCHAIN/build/$x" ]; then |
||||
|
mkdir -p "TOOLCHAIN/build" |
||||
|
ln -sn ../.. "TOOLCHAIN/build/$x" |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
chroot_umount() { |
||||
|
local busy= x= y= |
||||
|
local realxroot=$(pwd -P) |
||||
|
|
||||
|
if [ -d var/adm/logs ]; then |
||||
|
if ( cd var/adm/logs; fuser *.log > /dev/null 2>&1 ); then |
||||
|
busy=yes |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$busy" ]; then |
||||
|
echo_info "Unmounting loop mounts ..." |
||||
|
for x in loop config mount; do |
||||
|
y=$realxroot/TOOLCHAIN/$x |
||||
|
if mountpoint $y; then |
||||
|
umount -d -f $y || umount -d -f -l $y |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
y=$realxroot/proc |
||||
|
if mountpoint $y; then |
||||
|
umount -d -f $y || umount -d -f -l $y |
||||
|
fi |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
errno=0 cmd="chroot_$chroot_mode" |
||||
|
for d; do |
||||
|
if [ -d "$d/TOOLCHAIN" ]; then |
||||
|
dir="$(cd "$d/" && pwd -P)" |
||||
|
else |
||||
|
dir= |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$dir" ]; then |
||||
|
echo_error "$d: Invalid sandbox" |
||||
|
errno=1 |
||||
|
else |
||||
|
(set -e; cd "$dir"; "$cmd") |
||||
|
[ $? -eq 0 ] || errno=1 |
||||
|
fi |
||||
|
done |
||||
|
exit $errno |