#!/bin/bash
# Change the next two variables to save some mouse clicks if you always have your
# source.iso and chroot dir in the same locations. NO TRAILING SLASH!
DESTDIR=/tmp/chroot # Change this to your preferred chroot destination.
SRCDIR=/home/$LOGNAME # Change this to preferred iso source location.
app="VL2chroot" # Name of this script.
unset MYGUI
if [ "$DISPLAY" ] || ! skill -n "X" &>/dev/null; then
MYGUI=1
if [ -z $MYGUI ]; then
echo "No X server running; we can't run zenity"
exit 1
fi
fi
if [ ! -x /usr/bin/zenity ]; then
echo "zenity is not installed or not executable"
echo "This script is worthless without it. Bye..."
exit 1
fi
if [ $UID != 0 ]; then
zenity --error --title "${app}" --text="You need to be root to run me."
exit 1
fi
# Little "progress" thingie while extracting packages.
spanner(){
PROC=$1;COUNT=0
echo -n "Please wait "
while [ -d /proc/$PROC ];do
while [ "$COUNT" -lt 10 ];do
echo -ne '\033[1;34m|' ; sleep 0.1
((COUNT++))
done
until [ "$COUNT" -eq 1 ];do
echo -ne '\b\b\033[1;34m|' ; sleep 0.1
((COUNT -= 1))
done
done
echo -e '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\033[1;32m [DONE] '
tput sgr0
}
CWD=$(pwd)
MNT=/mnt/loop
umount $MNT > /dev/null 2>&1
bail () {
zenity --error --text="${1}\nAborting"
umount $MNT > /dev/null 2>&1
exit 1
}
HRLINE="_____________________________________________________________________________________\n\n\n"
text="This utility will help you create a clean chroot\nenviorment from a \
Vectorlinux iso.\n${HRLINE}Would you like to begin by selecting your \
ISO now? Click OK to continue, Cancel to abort."
zenity --question --title "${app}" --width 400 --height 250 --text "$text" || bail "Maybe next time ;)"
ISO=$(zenity --file-selection --title "${app}- Please select ISO file." --filename=$SRCDIR/) || bail "You closed the browser dialog"
while [ ${ISO/*./} != iso ]; do
ISO=$(zenity --file-selection --title "${app}- Not valid .iso, please reselect." --filename=$SRCDIR/) || bail "You closed the browser dialog"
done
CHROOT="${DESTDIR}/$(basename $ISO .iso)"
text="You selected:\n$ISO\n\nBased on the iso name, your chroot will \
be:\n$CHROOT\n${HRLINE}Click OK to accept, Cancel to select your own directory."
zenity --question --title "${app}- Destination chroot dir" --width 400 --height 250 --text "$text" || CHROOT=$(zenity --file-selection --title "${app}- Select or create chroot dir." --directory --filename=$DESTDIR/) || bail "You closed the browser dialog"
mount -o loop $ISO $MNT || bail "Couldn't mount ISO"
. $MNT/veclinux/SETUP.CONF
STATUS=""
REQUIRED_BULK="veclinux.tlz vlconfig.tlz"
REQUIRED_BULK_LAST="vlconfig2.tlz"
OPTIONAL_BULK=$(cd $MNT/veclinux/optional; ls *t?z)
OPTIONAL_PACKAGES=$(cd $MNT/packages; ls -R */*t?z)
for OPTIONALPKGS in $OPTIONAL_PACKAGES; do
OPTIONALPKGS_GUI="$OPTIONALPKGS_GUI TRUE $OPTIONALPKGS "
done
for OPTIONALBULK in $OPTIONAL_BULK; do
OPTIONALBULK_GUI="$OPTIONALBULK_GUI TRUE $OPTIONALBULK "
done
STATUSUPDATE () {
STATUS="$STATUS$1"
}
STATUSUPDATE "Source iso:\t\t$ISO\nDestination chroot:\t$CHROOT\n"
text="Please select all OPTIONAL BULK packages you would like to install. \
\nThe following bulk packages are required and will be installed:"
BULKPKGS=$(zenity --list --title "${app}- Select optional bulks" --width 400 --height 300 --text "${STATUS}${HRLINE}${text}\n\n\t\t\t$REQUIRED_BULK $REQUIRED_BULK_LAST" \
--checklist --column "Pick" --column "Optional Bulk Packages" $OPTIONALBULK_GUI --separator=" ") || bail
STATUSUPDATE "Required bulks:\t$REQUIRED_BULK $REQUIRED_BULK_LAST\nOptional bulks:\t\t$BULKPKGS\n"
text="Please select all packages you would like installed and click OK\nClicking \
Cancel will abort this Wizard.\n\nCareful not un-check needed packages!"
PKGS=$(zenity --list --title "${app}- Select packages" --width 400 --height 500 --text "${STATUS}${HRLINE}${text}" \
--checklist --column "Pick" --column "Packages" $OPTIONALPKGS_GUI --separator=" ") || bail
PKGCOUNT=0
for PACK in $PKGS; do
TIDYPKGS="$TIDYPKGS\t\t\t\t$PACK\n"
((PKGCOUNT++))
done
STATUSUPDATE "\nAdditional packages:\n\n${TIDYPKGS}\n"
text="Enter your VectorLinux packager name.
\"export VL_ PACKAGER=YOURNAME\"
Will be added to /etc/profile.d in your new chroot.
Leave blank or cancel to disregard."
VL_PACKAGER="$(zenity --entry --title "${app}- Packager name" --text "$text" --entry-text="${VL_PACKAGER:-""}")"
if [ ! -z "$VL_PACKAGER" ]; then
STATUSUPDATE "VL_PACKAGER:\t\t$VL_PACKAGER\n"
else
STATUSUPDATE "VL_PACKAGER:\t\tUntouched\n"
unset VL_PACKAGER
fi
if [ $(echo $VERSION | cut -d " " -f1 | sed 's|\.||') -ge "59" ]; then
# toolchain is capable of handling gnu hash
text="The LDFLAGS can be set to optimize with \"-Wl,--hash-style=gnu\". \
Click \"OK\" to have these flags exported in the chroot, or \
\"Cancel\" to leave them unchanged."
zenity --question --title "${app}- LDFLAGS" --width 400 --text "${STATUS}${HRLINE}${text}"
if [ $? = "0" ]; then
GNUHASH="yes"
STATUSUPDATE "LDFLAGS:\t\t\t-Wl,--hash-style=gnu\n"
else
GNUHASH="no"
STATUSUPDATE "LDFLAGS:\t\t\tUntouched\n"
fi
fi
text="If your network is up when we create the chroot, we can install the \
\"requiredbuilder\" package. The new chroots /etc/slapt-get/slap-getrc \
will be modified to enable \"testing\", and then slapt-get will be run and \
updated, finally requiredbuilder will be installed. This will be done \
automatically for you when the chroot is created. To accept all this, \
click \"OK\" to decline, click \"Cancel\"."
zenity --question --title "${app}- Ready chroot for action" --width 400 --text "${STATUS}${HRLINE}${text}"
if [ $? = "0" ]; then
REQUIREDBUILDER="yes"
STATUSUPDATE "slapt-get:\t\t\tTo be updated\nrequiredbuilder:\tTo be installed\n"
else
REQUIREDBUILDER="no"
STATUSUPDATE "slapt-get:\t\t\tUntouched\nrequiredbuilder:\tNot be installed\n"
fi
text="Please review all information above and click OK to proceed with chroot \
creation. Click Cancel to abort."
zenity --question --title "${app}- Ready to create chroot?" --width 400 --text "${STATUS}${HRLINE}${text}" || bail
#make the chroot dir
mkdir -p $CHROOT
#change to the chroot dir
cd $CHROOT
CONFIGTXT="Enter-and-configure-new-chroot."
ALLPKGS="$REQUIRED_BULK $BULKPKGS $PKGS $REQUIRED_BULK_LAST $CONFIGTXT"
#extract the bulks
for BULKS in $REQUIRED_BULK; do
echo -n "Extracting required bulk: $(basename $BULKS), "
lzma -cd $MNT/veclinux/required/${BULKS} | tar xp > /dev/null 2>&1 & spanner $!
unset NUMLINE
done
#extract optional bulks
for OPTBULKS in $BULKPKGS; do
echo -n "Extracting optional bulk: $(basename $OPTBULKS), "
lzma -cd $MNT/veclinux/optional/${OPTBULKS} | tar xp > /dev/null 2>&1 & spanner $!
done
for PKG in $PKGS; do
echo -n "Installing: $(basename $PKG), "
installpkg -R $(pwd) $MNT/packages/$PKG > /dev/null 2>&1 & spanner $!
done
#extract the vlconfig2 bulk last
echo -n "Extracting required bulk: $REQUIRED_BULK_LAST, "
lzma -cd $MNT/veclinux/required/$REQUIRED_BULK_LAST | tar xp > /dev/null 2>&1 & spanner $!
CONFIGCHROOT () {
# Setting timezone to your current settings.
cp -a /etc/localtime* etc/
# I can't access the network in chroot without it.
cp -a /etc/resolv.conf etc/
# Disable xmodmap in roots .bashrc. Causes ugliness when chrooting. And in this wizard.
sed -i 's|xmodmap|#xmodmap|' root/.bashrc
# create /etc/vector-version
if [ "$VERSION" = '5.8 Standard Final' ]; then
builddate='12-16-06'
fi
echo "$VERSION built on $builddate (chroot)" > etc/vector-version
# Simple edit so hostname in chroot terminal is switched to "basename of iso (CHROOT)".
# Less confusing when multiple terminal windows open.
sed -i 's|PS_CYAN}\\h:|PS_CYAN}'"$(basename $ISO .iso)"' (CHROOT):|' etc/profile.d/vasm.sh
if [ ! -z "$VL_PACKAGER" ]; then
echo "export VL_PACKAGER=\"$VL_PACKAGER\"" >> etc/profile.d/vasm.sh
fi
if [ $GNUHASH = "yes" ]; then
echo 'export LDFLAGS="-Wl,--hash-style=gnu"' >> etc/profile.d/vasm.sh
fi
# Create temporary script to run in chroot and setup stuff.
cat > setup << EOF
#!/bin/bash
source /etc/profile
echo "Working as chroot for first time"
sleep 2
echo "caching fonts..."
/usr/bin/fc-cache
echo "updating libraries..."
/sbin/ldconfig
EOF
if [ $REQUIREDBUILDER = "yes" ]; then
VER=$(echo $VERSION | cut -d " " -f1)
if [ $(ls var/log/packages/|grep bash|cut -d "-" -f3) = "x86_64" ]; then
REPODIR=VL64-${VER}
else
REPODIR=veclinux-${VER}
fi
echo "SOURCE=ftp://ftp.osuosl.org/pub/vectorlinux/$REPODIR/testing/" >> etc/slapt-get/slapt-getrc
echo "slapt-get --update" >> setup
echo "slapt-get --install requiredbuilder" >> setup
fi
cat >> setup << EOF
sleep 2
exit
EOF
chmod +x setup
# Entering chroot and running that script in new terminal.
xterm -title "Setting up Chroot $CHROOT..." -geometry -0+0 -fa Mono -fs 12 -fg white -bg black -cr green -sb -rightbar -j \
-e "chroot . ./setup" || bail
# Not everyone will have xfce and Terminal. Comment out 2 above lines, and uncomment line below
# if you prefer Terminal.
#terminal -e "chroot . ./setup" --title="Setting up Chroot $CHROOT..." || bail
}
echo -n "Configuring new chroot, "
CONFIGCHROOT > /dev/null 2>&1 & spanner $!
# Done, now cleanup.
rm setup
cd $CWD
umount $MNT
text="Your new chroot is ready in:\n$CHROOT\nEnter the directory in a \
terminal and run: \"chroot . /bin/bash\""
zenity --info --title "${app}- Chroot complete" --text "$text"