3 # apt-in-chroot - runs apt in a specified chroot
5 # Copyright (C) 2010 Martin Zobel-Helas <zobel@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 VALID_CHROOTS="$(/usr/bin/dchroot -l 2>&1 | /usr/bin/awk -F": " '{print $2}' | /usr/bin/tr ' ' '\n')"
23 VALID_CHROOTS_PARSE="$(/usr/bin/dchroot -l 2>&1 | /usr/bin/awk -F": " '{print $2}' | /bin/sed -e 's/ /|/g')"
27 echo "Usage: $bn <chroot> <apt sub-command> <package>"
29 echo " allowed chroots are ($VALID_CHROOTS_PARSE)"
31 echo " allowed apt sub-commands are:"
39 if [ "$#" -lt "3" ]; then
51 install|remove|purge|build-dep)
52 # those are the allowed apt sub-commands
55 echo "$APTCMD is not a valid apt sub-command"
60 grep -qFx $CHROOT <<< "$VALID_CHROOTS"
64 if [ "$RET" == "0" ]; then
66 echo "Will run '/usr/sbin/chroot $CHROOT_DIR/$CHROOT apt-get $APTCMD $PACKAGES'"
67 /usr/sbin/chroot $CHROOT_DIR/$CHROOT apt-get $APTCMD $PACKAGES
69 echo "$CHROOT not in $VALID_CHROOTS_PARSE"