Lines Matching +full:libpython +full:- +full:dev
1 #!/bin/bash -e
4 # Use of this source code is governed by a BSD-style license that can be
7 # This script installs Debian-derived distributions in a chroot environment.
11 # Debian-derived system.
17 admin=$(grep '^admin:' /etc/group >&/dev/null && echo admin || echo adm)
20 echo "usage: ${0##*/} [-m mirror] [-g group,...] [-s] [-c]"
21 echo "-b dir additional directories that should be bind mounted,"
24 echo "-g group,... groups that can use the chroot unauthenticated"
25 echo " Default: '${admin}' and current user's group ('$(id -gn)')"
26 echo "-l List all installed chroot environments"
27 echo "-m mirror an alternate repository mirror for package downloads"
28 echo "-s configure default deb-srcs"
29 echo "-c always copy 64bit helper binaries to 32bit chroot"
30 echo "-h this help message"
38 if [ "${OPTARG}" = "NONE" -a -z "${bind_mounts}" ]; then
41 if [ "${bind_mounts}" = "NONE" -o "${OPTARG}" = "${OPTARG#/}" -o \
42 ! -d "${OPTARG}" ]; then
43 echo "Invalid -b option(s)"
52 [ -n "${OPTARG}" ] &&
60 if [ -n "${mirror}" ]; then
78 echo "'-$OPTARG' needs an argument."
83 echo "invalid command-line option: $OPTARG"
90 if [ $# -ge ${OPTIND} ]; then
101 [ -x "/usr/local/bin/${i%bit}" ] || continue
102 grep -qs "^\[${i%bit}\]\$" /etc/schroot/schroot.conf || continue
103 [ -r "/etc/schroot/script-${i}" -a \
104 -r "/etc/schroot/mount-${i}" ] || continue
111 trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT HUP
112 stty -echo iuclc -icanon 2>/dev/null
113 dd count=1 bs=1 2>/dev/null
122 printf '%d' $(printf '%c' "$1" | od -tu1 -An)
126 stat -c %T -f "$1/" 2>/dev/null |
127 egrep -qs '^nfs|cifs|smbfs'
131 [ "$(id -nu)" = root ] && {
146 trap 'sudo apt-get clean; tput bel; echo; echo Failed' EXIT
149 # are already installed, don't force another "apt-get install". That would
150 # prevent them from being auto-removed, if they ever become eligible for that.
154 for i in dchroot debootstrap libwww-perl; do
155 [ -d /usr/share/doc/"$i" ] || dep="$dep $i"
157 [ -n "$dep" ] && sudo apt-get -y install $dep
158 sudo apt-get -y install schroot
161 sudo mkdir -p /var/lib/chroot
165 ls | grep '^[a-z]*$')"
176 [ "$n" -gt 0 -a "$n" -lt "$j" ] >&/dev/null && break
179 [ "$j" -eq "$n" ] && { distname="$i"; break; }
184 # On x86-64, ask whether the user wants to install x86-32 or x86-64
187 if [ "$(uname -m)" = x86_64 ]; then
193 [ "${arch}" == 32 -o "${arch}" == 64 ] && break
195 [ "${arch}" == 32 ] && archflag="--arch i386" || archflag="--arch amd64"
202 [ -d /var/lib/chroot/"${target}" ] && {
205 if schroot -l --all-sessions 2>&1 |
207 grep -qs "^${target%bit}-"; then
209 echo "are currently using the chroot environment and then re-run this"
213 echo "executing \"${target%bit} -c\"."
222 o|O) sudo rm -rf "/var/lib/chroot/${target}"; break;;
223 d|D) sudo rm -rf "/var/lib/chroot/${target}" \
225 "/etc/schroot/mount-${target}" \
226 "/etc/schroot/script-${target}" \
228 sudo sed -ni '/^[[]'"${target%bit}"']$/,${
239 sudo mkdir -p /var/lib/chroot/"${target}"
241 # Offer to include additional standard repositories for Ubuntu-based chroots.
243 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" && {
245 echo "Would you like to add ${distname}-updates and ${distname}-security "
261 # Check for non-standard file system mount points and ask the user whether
266 # false-positives and something is very unusual about the system's
269 if [ -z "${bind_mounts}" ]; then
272 ($3 ~ "ext[2-4]" || $3 == "reiserfs" || $3 == "btrfs" ||
275 $3 ~ "nfs[4-9]?" || $3 == "smbfs" || $3 == "cifs") {
278 head -n26)"
279 if [ -n "${mounts}" ]; then
280 echo "You appear to have non-standard mount points that you"
285 # Print a menu, listing all non-default mounts of local or network
289 echo "$sel" | grep -qs $c &&
291 printf " $c) %-40s${state}\n" "$m"
294 # Allow user to interactively (de-)select any of the entries
298 c="$(getkey | tr a-z A-Z)"
300 if [ -z "$c" ] ||
301 [ "$c" '<' 'A' -o $(ord "$c") -gt $((64 + $(ord "$j"))) ]; then
306 if echo "$sel" | grep -qs $c; then
319 if echo "$sel" | grep -qs $c; then
334 sudo sed -ni '/^[[]'"${target%bit}"']$/,${:1;n;/^[[]/b2;b1;:2;p;n;b2};p' \
338 if [ -z "${mirror}" ]; then
339 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" &&
348 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" &&
350 if [ -z "${chroot_groups}" ]; then
351 chroot_groups="${admin},$(id -gn)"
354 if [ -d '/etc/schroot/default' ]; then
359 fstab="/etc/schroot/mount-${target}"
363 sudo cp -ar /etc/schroot/default /etc/schroot/${target}
365 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF
372 root-groups=${chroot_groups}
377 [ -n "${bind_mounts}" -a "${bind_mounts}" != "NONE" ] &&
379 sudo sh -c "cat >>${fstab}"
385 priority=$(grep -qs 'priority=' /etc/schroot/schroot.conf &&
387 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF
394 root-groups=${chroot_groups}
396 script-config=script-${target}
404 /etc/schroot/script-defaults |
405 sudo sh -c 'cat >/etc/schroot/script-'"${target}"
407 /etc/schroot/mount-defaults |
408 sudo sh -c "cat > ${fstab}"
412 [ -n "${bind_mounts}" -a "${bind_mounts}" != "NONE" ] &&
414 sudo sh -c 'cat >>'"${fstab}"
419 if [ -d /media ] &&
420 ! grep -qs '^/media' "${fstab}"; then
422 sudo sh -c 'cat >>'"${fstab}"
425 # Share /dev/shm, /run and /run/shm.
426 grep -qs '^/dev/shm' "${fstab}" ||
427 echo '/dev/shm /dev/shm none rw,bind 0 0' |
428 sudo sh -c 'cat >>'"${fstab}"
429 if [ ! -d "/var/lib/chroot/${target}/run" ] &&
430 ! grep -qs '^/run' "${fstab}"; then
432 sudo sh -c 'cat >>'"${fstab}"
434 if ! grep -qs '^/run/shm' "${fstab}"; then
435 { [ -d /run ] && echo '/run/shm /run/shm none rw,bind 0 0' ||
436 echo '/dev/shm /run/shm none rw,bind 0 0'; } |
437 sudo sh -c 'cat >>'"${fstab}"
442 d="$(readlink -f "${HOME}/chroot" 2>/dev/null || echo "${HOME}/chroot")"
445 sudo sh -c 'cat >>'"${target}"
446 mkdir -p "${s}"
449 sudo sh -c 'cat >/usr/local/bin/'"${target%bit}" <<'EOF'
455 # Word-wrap the text passed-in on stdin. Optionally, on continuation lines
461 local f="$(type -P fold)"
462 [ -z "${f}" ] && { cat; return; }
463 local c="$(stty -a </dev/tty 2>/dev/null |
464 sed 's/.*columns[[:space:]]*\([0-9]*\).*/\1/;t;d')"
465 [ -z "${c}" ] && { cat; return; }
467 local j="$(printf %s "${i}"|wc -c)"
468 if [ "${c}" -gt "${j}" ]; then
469 dd bs=1 count="${j}" 2>/dev/null
470 "${f}" -sw "$((${c}-${j}))" | sed '2,$s/^/'"${i}"'/'
472 "${f}" -sw "${c}"
477 …echo "Usage ${0##*/} [-h|--help] [-c|--clean] [-C|--clean-all] [-l|--list] [--] args" | wrap "Usag…
481 …echo " clean-all: remove all old chroot sessions for all environments" | wrap " …
488 for s in $(schroot -l --all-sessions); do
489 if [ -n "$1" ]; then
491 [ "${t#${chroot}-}" == "${t}" ] && continue
493 if ls -l /proc/*/{cwd,fd} 2>/dev/null |
494 fgrep -qs "/var/lib/schroot/mount/${t}"; then
499 sudo schroot -c "${s}" -e || rc=1
505 for e in $(schroot -l); do
507 [ -x "/usr/local/bin/${e}" ] || continue
508 if schroot -l --all-sessions 2>/dev/null |
510 grep -qs "^${e}-"; then
519 while [ "$#" -ne 0 ]; do
521 --) shift; break;;
522 -h|--help) shift; help;;
523 -l|--list) shift; list;;
524 -c|--clean) shift; clean "${chroot}";;
525 -C|--clean-all) shift; clean;;
533 # grand-child processes by scanning their environment.
534 session="$(schroot -c "${chroot}" -b)"
537 if [ $# -eq 0 ]; then
539 schroot -c "${session}" -r -p
543 schroot -c "${session}" -r -p "$p" -- "$@"
548 i=$(schroot -c "${session}" -r -p ls -- -id /proc/self/root/. |
549 awk '{ print $1 }') 2>/dev/null
551 while [ -n "$i" ]; do
554 # "sort | uniq -u" to do what amounts to a "set subtraction operation".
555 pids=$({ ls -id1 /proc/*/root/. 2>/dev/null |
556 sed -e 's,^[^0-9]*'$i'.*/\([1-9][0-9]*\)/.*$,\1,
560 echo "${other_pids}"; } | sort | uniq -u) >/dev/null 2>&1
565 [ -z "${pids}" ] && break
568 # side-effect of being unable to tell one session apart from another.
570 # We make a best-effort to avoid doing so.
571 k="$( ( xargs -0 -n1 </proc/$j/environ ) 2>/dev/null |
573 if [ -n "${k}" -a "${k#x}" != "${session}" ]; then
578 kill -9 $pids
584 # clean up the stale files by invoking us with "--clean" after having killed
586 schroot -c "${session}" -e
593 [ "${alt_repos}" = "y" -a \
594 -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] &&
595 sudo sed -i '/^deb .* [^ -]\+ main$/p
596 s/^\(deb .* [^ -]\+\) main/\1-security main/
600 :1;s/-security main/-updates main/
605 [ -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] &&
606 sudo sed -i 's/ main$/ main restricted universe multiverse/' \
610 if [ -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] &&
612 >&/dev/null; then
613 sudo sh -c '
620 [ "${add_srcs}" = "y" -a \
621 -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] &&
622 sudo sed -i '/^deb[^-]/p
623 s/^deb\([^-]\)/deb-src\1/' \
627 if [ -n "${http_proxy}" ]; then
628 sudo sh -c '
634 sudo "/usr/local/bin/${target%bit}" /bin/sh -c '
635 apt-get update; apt-get -y dist-upgrade' || :
638 for i in debian-keyring ubuntu-keyring locales sudo; do
639 [ -d "/var/lib/chroot/${target}/usr/share/doc/$i" ] ||
640 sudo "/usr/local/bin/${target%bit}" apt-get -y install "$i" || :
644 sudo "/usr/local/bin/${target%bit}" /bin/sh -c '
645 l='"${LANG:-en_US}"'; l="${l%%.*}"
646 [ -r /etc/locale.gen ] &&
647 sed -i "s/^# \($l\)/\1/" /etc/locale.gen
648 locale-gen $LANG en_US en_US.UTF-8' || :
650 # Enable multi-arch support, if available
651 sudo "/usr/local/bin/${target%bit}" dpkg --assert-multi-arch >&/dev/null &&
652 [ -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] && {
653 sudo sed -i 's/ / [arch=amd64,i386] /' \
655 [ -d /var/lib/chroot/${target}/etc/dpkg/dpkg.cfg.d/ ] &&
656 sudo "/usr/local/bin/${target%bit}" dpkg --add-architecture \
657 $([ "${arch}" = "32bit" ] && echo amd64 || echo i386) >&/dev/null ||
658 echo foreign-architecture \
660 sudo sh -c \
665 sudo "/usr/local/bin/${target%bit}" /bin/sh -c '
666 egrep -qs '"'^$(id -nu) '"' /etc/sudoers ||
667 echo '"'$(id -nu) ALL=(ALL) ALL'"' >>/etc/sudoers'
670 sudo "/usr/local/bin/${target%bit}" apt-get -y install \
671 autoconf automake1.9 dpkg-dev g++-multilib gcc-multilib gdb less libtool \
677 # runtime dependencies. The user can force it with the '-c' flag.
678 host_distro=$(grep -s DISTRIB_CODENAME /etc/lsb-release | \
679 cut -d "=" -f 2)
680 if [ "${copy_64}" = "y" -o \
681 "${host_distro}" = "${distname}" -a "${arch}" = 32bit ] && \
682 file /bin/bash 2>/dev/null | grep -q x86-64; then
683 readlinepkg=$(sudo "/usr/local/bin/${target%bit}" sh -c \
684 'apt-cache search "lib64readline.\$" | sort | tail -n 1 | cut -d " " -f 1')
685 sudo "/usr/local/bin/${target%bit}" apt-get -y install \
689 [ -d /usr/share/doc/"$i" ] || dep="$dep $i"
691 [ -n "$dep" ] && sudo apt-get -y install $dep
692 sudo mkdir -p "/var/lib/chroot/${target}/usr/local/lib/amd64"
693 for i in libbfd libpython; do
695 grep -s "$i" | awk '{ print $3 }')"
696 if [ -n "$lib" -a -r "$lib" ]; then
701 for path in /usr/lib /usr/lib/x86_64-linux-gnu; do
703 "/var/lib/chroot/${target}/usr/local/lib/amd64/" >&/dev/null || :
708 sudo sh -c "cat >'/var/lib/chroot/${target}/usr/local/bin/$i'" <<EOF
710 exec /lib64/ld-linux-x86-64.so.2 --library-path /usr/local/lib/amd64 \
718 # If the install-build-deps.sh script can be found, offer to run it now
719 script="$(dirname $(readlink -f "$0"))/install-build-deps.sh"
720 if [ -x "${script}" ]; then
730 # We prefer running the script in-place, but this might not be
735 sh -c "[ -x '${script}' ]" >&/dev/null; then
739 # Some distributions automatically start an instance of the system-
744 sudo /usr/local/bin/"${target%bit}" sh -c "${script};
746 /etc/init.d/cron stop >/dev/null 2>&1 || :;
747 /etc/init.d/rsyslog stop >/dev/null 2>&1 || :;
748 /etc/init.d/dbus stop >/dev/null 2>&1 || :;
751 [ -n "${tmp_script}" ] && rm -f "${tmp_script}"
752 [ $rc -ne 0 ] && exit $rc
765 # spindles (as indicated by "${bind_mount}" being non-empty).
773 mkdir -p "${HOME}/chroot/"
774 if [ ! -h "${HOME}/chroot" ] &&
775 ! egrep -qs '^[^[:space:]]*/chroot' /etc/fstab &&
776 { [ -n "${bind_mounts}" -a "${bind_mounts}" != "NONE" ] ||
778 ! egrep -qs '/var/lib/[^/]*chroot/.*/chroot' /proc/mounts; then
788 for i in $(echo "${bind_mounts}"|cut -d ' ' -f 1); do
789 if [ -d "$i" -a -w "$i" -a \( ! -a "$i/chroot" -o -w "$i/chroot/." \) ] &&
794 if [ -d "$j" -a -w "$j" -a \
795 \( ! -a "$j/chroot" -o -w "$j/chroot/." \) ] &&
800 if [ -d "$k" -a -w "$k" -a \
801 \( ! -a "$k/chroot" -o -w "$k/chroot/." \) ] &&
808 [ -n "${suggest}" ] && break
811 [ -n "${suggest}" ] && break
814 if [ -n "${suggest}" ]; then
827 [ -z "${dir}" ] && dir="${def_suggest}"
829 if ! [ -d "${dir}" -a -w "${dir}" ] ||
830 [ -a "${dir}/chroot" -a ! -w "${dir}/chroot/." ]; then
834 ln -s "${dir}/chroot" "${HOME}/chroot"
836 sudo "$i" mkdir -p "${dir}/chroot"
838 sudo sed -i "s,${HOME}/chroot,${dir}/chroot,g" /etc/schroot/mount-*
845 sudo schroot -c "${target%bit}" -p -- apt-get clean
846 sudo apt-get clean
866 "sudo ${target%bit} apt-get update").