Skip to content

Instantly share code, notes, and snippets.

@sampowers
Last active August 29, 2015 14:00
Show Gist options
  • Save sampowers/fce0e184ad6c9dfaff58 to your computer and use it in GitHub Desktop.
Save sampowers/fce0e184ad6c9dfaff58 to your computer and use it in GitHub Desktop.
#!/bin/bash
# roto-chrooter, (C) 2005 Sam Powers <sam@rm-r.net>. Licensed under GNU GPL.
VER="1.4"
# You can edit the default suite and chroot dir here, or by setting one of the
# below two env vars $_SUITE or $_CHROOT_DIR prior to running the script:
test $_CHROOT_DIR || export _CHROOT_DIR="/chroot"
test $_SUITE || export _SUITE="sarge"
test $_MIRROR || export _MIRROR="http://http.us.debian.org/debian"
# pdmenu https://joeyh.name/code/pdmenu/
# check for dependent programs
DEPPROGS="sudo pdmenu debootstrap dchroot"
for i in $DEPPROGS; do
if [ -z `which $i` ]; then
echo "Please install sudo, pdmenu, debootstrap, and dchroot!"
echo "I can't find $i"
exit; fi
done
# i am become root, destroyer of filesystems
if [ `whoami` != "root" ]; then
echo "Hey, just so you know, I'm about to run myself as root for you."
exec sudo $0
fi
if [ ! -d $_CHROOT_DIR ]; then mkdir $_CHROOT_DIR ; fi
setup_chroot () {
echo "$1 $2" >> /etc/dchroot.conf
echo "$1" > "${2}/etc/debian_chroot"
}
if [ "x$1" = "xcreate" ]; then
if [ -z $2 ]; then echo "Enter a name for the chroot, please." ;exit;fi
CHPATH="${_CHROOT_DIR}/$2"
debootstrap "$_SUITE" $CHPATH "$_MIRROR"
setup_chroot "$2" "$CHPATH"
exit ; fi
if [ "x$1" = "xchroot_cp" ]; then
cd $_CHROOT_DIR
cp -au "$2" "$3"
setup_chroot "$3" "${_CHROOT_DIR}/$3"
exit ; fi
if [ "x$1" = "xchroot_login" ]; then
clear
exec dchroot -c $2
fi
if [ "x$1" = "xchroot_rm" ]; then
clear
echo "I'm about to run 'rm -rfv $_CHROOT_DIR/$2' (from $PWD)"
echo "Is that okay? This might be dangerous if I messed it up."
echo "Press enter to continue or ^C to bail out."
read
rm -rfv "$_CHROOT_DIR"/"$2"
echo "Please remove this entry from /etc/dchroot.conf manually."
exit ; fi
if [ "x$1" = "xabout" ]; then
echo "<-- Back"
echo " "
echo "'roto-chrooter' is a script that I hacked up to provide a"
echo "nice looking frontend to dchroot, which does a good job of"
echo "handling the functional side of things. With this program,"
echo "you can create, copy, delete, or log into a set of chroot"
echo "environments."
echo " "
echo "This program is released under the terms of the GNU GPL,"
echo "either version 2 or any newer version, at your option."
echo " "
echo "It was written by Sam Powers <sam@rm-r.net>"
exit;fi
# handle the unhandled, or else the recursion would blow pdmenu sky high)
test $1 && exit
# FIXME: i should be creating the menus dynamically in pdmenu instead of using
# this godawful hack.. also i should possibly read the list via dchroot.
_LCHROOTS=$(echo -e $(for f in `ls $_CHROOT_DIR`; do
echo -n "\texec:`basename $f`::$0 chroot_login \"$f\"\n"
done))
_RMCHROOTS=$(echo -e $(for f in `ls $_CHROOT_DIR`; do
echo -n "\texec:`basename $f`:clear,pause:$0 chroot_rm \"$f\"\n"
done))
_CCHROOTS=$(echo -e $(for f in `ls $_CHROOT_DIR`; do
echo -n "\texec:`basename $f`:edit,pause:$0 chroot_cp \"$f\" \"~Copy to\::~\"\n"
done))
pdmenu -c - << EOF
title:roto-chrooter chroot manager v$VER by Sam Powers <sam@rm-r.net>
menu:main:-=-=-roto-chrooter-=-=-
show:_Log in..::loginmenu
show:_Copy..::copymenu
show:_Delete..::rmmenu
exec:Create _New..:edit,pause:$0 create \
"~Please enter a name for this chroot or ESC to cancel:~"
nop
nop:Options\:
exec:Sui_te:edit,setenv:echo _SUITE="~set to?:${_SUITE}~"
exec:_Mirror:edit,setenv:echo _MIRROR="~Enter debian mirror URI:${_MIRROR}~"
nop
exec:About..:display:$0 about
exit:E_xit
menu:loginmenu:-=-Log in-=-
exit:<-- Back
nop
$_LCHROOTS
menu:copymenu:-=-Copy-=-
exit:<-- Back
nop
$_CCHROOTS
menu:rmmenu:-=-Delete-=-
exit:<-- Back
nop
$_RMCHROOTS
EOF
echo
echo "Welcome back to the real system (`hostname`). Always ski in control."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment