3 # apt-in-chroot - runs apt in a specified chroot
5 # Copyright (C) 2010 Martin Zobel-Helas <zobel@debian.org>
6 # Copyright (C) 2012 Peter Palfrader <peter@palfrader.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 echo "Usage: $bn <chroot> <apt sub-command> [<package>]"
30 echo " allowed apt sub-commands are:"
39 if [ "$#" -lt "2" ]; then
52 if [ -x /usr/bin/dchroot ] ; then
53 chroots=$(dchroot -l 2>&1 | awk -F": " '{print $2}' | tr ' ' '\n')
55 suffix[${#suffix[*]}]="_$(dpkg --print-architecture)"
56 elif [ -x /usr/bin/schroot ] ; then
57 chroots=$(schroot -l | awk -F":" '{print $2}' | grep -- '-dchroot$' )
60 suffix[${#suffix[*]}]="-dchroot"
61 suffix[${#suffix[*]}]="-$(dpkg --print-architecture)-dchroot"
63 echo >&2 "Cannot find chroot wrapper."
69 for (( i = 0 ; i < ${#suffix[*]} ; i++ )); do
70 if [ "$c" == "$CHROOT${suffix[$i]}" ]; then
76 if ! [ -n "$requested_chroot" ]; then
77 echo >&2 "$CHROOT is not a valid dchroot. Available chroots are:"
83 install|remove|purge|build-dep|update)
84 # those are the allowed apt sub-commands
87 echo "$APTCMD is not a valid apt sub-command"
93 if [ "$method" = "dchroot" ]; then
94 echo "Will run '/usr/sbin/chroot $CHROOT_DIR/$requested_chroot apt-get $APTCMD $PACKAGES'"
95 /usr/sbin/chroot $CHROOT_DIR/"$requested_chroot" apt-get "$APTCMD" $PACKAGES
96 elif [ "$method" = "schroot" ]; then
97 echo "Will run 'schroot -c $requested_chroot apt-get $APTCMD $PACKAGES'"
98 #/usr/sbin/chroot $CHROOT_DIR/"$requested_chroot" apt-get "$APTCMD" $PACKAGES
100 echo >&2 "Invalid method."