Posts: 51
swiftlinuxcreator
Joined: 15 Nov 2010
#1
I've been working on automating the remastering script, which I run by entering"remaster.sh" with no arguments. It's important for Swift Linux, because the remastering process not only takes a long time but also requires user input at various points throughout the process. (The long wait wouldn't be so bad if user input were only required at the very beginning and very end of the process.) In fact, the process of running the remastering script reminds me of the process of installing Windows.

I've been able to automate the process of copying files from the installed system to the new-squashfs system that makes up the ISO output file. The one part of the script that I haven't been able to fully automate is the chroot portion in the middle. This is the portion of the remastering script where I need to enter the apt-get command to give the new ISO the updated Synaptic settings, enter the dpkg -i commands in order to have the new packages installed, enter the apt-get remove --purge commands in order to remove packages from the new ISO, and enter"exit" to leave the chroot environment.

What I'm trying to do is automate the chroot portion of the script. Exactly how and where to I insert all those commands that I want executed automatically?

I'm pretty sure that what I need to change is in the chroot_env function, which I am reprinting here:
# Mounts filesystems and chroots to remastering environment, at exit unmounts all filesystems and perform cleanup for remastering environment
function chroot_env {
mount_all $1

# Assume root in our new squashfs
echo -e"Chrooting into your / \n"
echo -e"You should now be in the environment you want to remaster. To check please type \"ls\" - you should see a root directory tree."
echo -e"When done please type \"exit\" or press CTRL-D \n"
set_chroot_commands $1
chroot $1
umount_all $1
cleanup $1
}

The code for the set_chroot_commands function is:
# Execute commands automatically after you enter the chroot environment and at log out.
function set_chroot_commands {
# Backup original bash.bashrc
cp $1/etc/bash.bashrc $1/etc/bash.bashrc_original
echo '
# Commands to be run automatically after entering chroot

# Restore original file
mv /etc/bash.bashrc_original /etc/bash.bashrc

# Start a new session
/bin/bash

# Commands to run automatically when exiting from chroot environment (e.g., clean-up commands)
echo
echo -e"Cleaning chroot environment..."
apt-get clean
echo -e"Exiting chroot.\n"
exit' >> $1/etc/bash.bashrc
}
Posts: 1,062
Dave
Joined: 20 Jan 2010
#2
my best guess would be to enter it

Code: Select all

echo -e"When done please type \"exit\" or press CTRL-D \n"
set_chroot_commands $1
######### HERE  ##########

just to clarify though are you wanting the script to do the ( apt-get update )( apt-get -f install )( apt-get purge )( dpkg -i ) commands by itself. To me this seems kind of not needed because you only need to do it once per iso, and trying to get all the command / timing / waiting issues solved would be just as much work as doing the modifications yourself. Also would the commands that are automatically done not need to be changed for each new iso? This does not seem to make sense to me so I would just like to clarify that it is what you are trying to do.
Last edited by Dave on 18 Nov 2010, 01:40, edited 1 time in total.
Posts: 51
swiftlinuxcreator
Joined: 15 Nov 2010
#3
Yes, I really do want the script to enter those commands automatically. If I can fully automate the remastering process, then I can make changes to Swift Linux more frequently. At least I can let the remastering script do its work all by itself while I do other things. With the status quo, the remastering process stops and requires me to provide input during the middle of the process. I don't mind having to provide input at the very beginning and very end - I just hate having to provide input in the middle of the process. That's why I've automated everything that can be done outside chroot, but I want to extend to automation to within chroot.
Posts: 1,062
Dave
Joined: 20 Jan 2010
#4
Edited what I had said before but what is now said above that is were I would put all the commands.
Posts: 75
jhsu
Joined: 02 Jan 2010
#5
OK, I figured it out. The command to add is chroot $1 (command) for each command I want automatically executed in chroot.