From 93cb66500f328580bbfd5cd9018020d1f7db7fbc Mon Sep 17 00:00:00 2001 From: Martin Zobel-Helas Date: Thu, 18 Mar 2010 22:35:40 +0100 Subject: [PATCH] add apt-in-chroot --- apt-in-chroot | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 apt-in-chroot diff --git a/apt-in-chroot b/apt-in-chroot new file mode 100755 index 0000000..279b95f --- /dev/null +++ b/apt-in-chroot @@ -0,0 +1,72 @@ +#!/bin/sh +# +# apt-in-chroot - runs apt in a specified chroot +# +# Copyright (C) 2010 Martin Zobel-Helas +# +# 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; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# + +VALID_CHROOTS="$(/usr/bin/dchroot -l 2>&1 | /usr/bin/awk -F": " '{print $2}' | /usr/bin/tr ' ' '\n')" +VALID_CHROOTS_PARSE="$(/usr/bin/dchroot -l 2>&1 | /usr/bin/awk -F": " '{print $2}' | /bin/sed -e 's/ /|/g')" + +usage() { + bn="`basename "$0"`" + echo "Usage: $bn " + echo "" + echo " allowed chroots are ($VALID_CHROOTS_PARSE)" + echo "" + echo " allowed apt sub-commands are:" + echo " + install" + echo " + remove" + echo " + purge" + echo " + build-dep" +} + + +if [ "$#" -lt "3" ]; then + usage >&2 + exit 1 +fi + +CHROOT_DIR="/chroot" +CHROOT=$1; shift +APTCMD=$1; shift +PACKAGES=$* + + +case "$APTCMD" in +install|remove|purge|build-dep) + # those are the allowed apt sub-commands + ;; +*) + echo "$APTCMD is not a valid apt sub-command" + ;; +esac + +grep -qFx $CHROOT <<< "$VALID_CHROOTS" + +RET=$? + +if [ "$RET" == "0" ]; then + # valid chroot + echo "Will run '/usr/sbin/chroot $CHROOT_DIR/$CHROOT apt-get $APTCMD $PACKAGES'" + /usr/sbin/chroot $CHROOT_DIR/$CHROOT apt-get $APTCMD $PACKAGES +else + echo "$CHROOT not in $VALID_CHROOTS_PARSE" + exit 1 +fi + + -- 2.30.2