Chapter 9. Automating Your Setup with lnstcustom

Table of Contents

Preparing a Thumb Drive for lnstcustom
Using lnstcustom With a Web Server

This section is intended for those who are familiar with Linux based systems. If you are just learning Linux, it is recommended that you skip this section for now and come back to it later when you feel a bit more comfortable at the command line.

After using the Network Security Toolkit for awhile, you'll find yourself wishing their was a means to simplify the initialization process. If you have a thumb drive, flash drive, floppy disk, a hard disk, or even a web server, you are in luck - the lnstcustom command can simplify your setup.

It should be noted, that this automation is not completely hands free. You will need to invoke lnstcustom each time you boot, but you won't have to type much else.

You need to be familiar with writing bash (or sh) scripts prior to doing much automating. However, the Network Security Toolkit makes an excellent environment to hone those scripting skills.

Preparing a Thumb Drive for lnstcustom

This section is going to walk you through the creation of a simple setup.sh script that can be used by lnstcustom to automate the following:

  • Changing the default password.

  • Starting X.

After following these steps, you should be able to boot the Network Security Toolkit, log in, plug in your thumb drive, and type the following command:

[root@probe root]# lnstcustom test

After typing the above, you should see that the password is being changed, and after what seems a long time, the X desktop should come up (you will be be presented with the X configuration utility the first time invoked, but it will remember your settings for future invocations).

For this example, I'm going to borrow my wife's Creative Muvo Nomad MP3 player which also acts as a standard thumb drive (do me a favor and don't mention this to my wife). After plugging the MP3 player into a USB port, the following commands are entered:

[root@probe root]# mount -t vfat /dev/sda1 /mnt/memstick 1
[root@probe root]# mkdir /mnt/nst/test 2
[root@probe root]# jed /mnt/nst/test/setup.sh 3
1

This mount command will work for many thumb drives, however, you may need to change the /dev/sda1 or vfat parameters for your thumb drive (Hint: try "fdisk -l" for clues about the location and file system used on your thumb drive).

2

This command creates a directory for our "test" customization. This means we will need to specify test as the first argument to the lnstcustom command when we want to load this custom configuration (it also means that its easy to make many different customizations on the same thumb drive - just give each its own unique directory name).

3

This line is used to edit the setup.sh script. The commands we put in setup.sh will be run each time we run the command "lnstcustom test sda1 vfat". The jed editor was used in this example (I'm partial to the emacs key bindings - but vim is also available).

Here are the commands we will type into the setup.sh script.

#!/bin/bash

printf "letmein\nletmein\n" | nstpasswd 1

if [ -f "$NSTHOME/XF86Config" ]; then 2
  cp "$NSTHOME/XF86Config" "/etc/X11"
  /etc/rc.d/init.d/xfs start
  startx
else 3
  setup_x
  if [ -f "/etc/X11/XF86Config" ]; then
    cp "/etc/X11/XF86Config" "$NSTHOME/"
    startx
  fi
fi
1

This line makes use of the printf command to print the word letmein twice (on two separate lines). This is fed into the nstpasswd command to automate the changing of the password. Now, I would never recommend setting a real password to this value or in this fashion (its in plain text on your thumb drive). However, it is still better (more secure) than having the default password that comes on the Network Security Toolkit ISO.

2

This section checks to see if a configuration file for X is already available on the thumb drive. If it is, it copies it to the proper location, starts the X font server, and then starts X.

3

This section is run if a configuration file is needed for X in this case, we invoke the setup_x command to configure our system, save the configuration created (so we won't have to next time), and then start X.

Caution

The above assumes that you will be using the X configuration on the same system (or another system with identical hardware). NEVER use a X configuration created for one system on a different system (you may damage something). If you plan on using the same thumb drive on different systems, you should create a different directory for each system, or change the setup.sh script such that it ALWAYS invokes setup_x before invoking startx.

After saving the file (Control-X Control-S) and leaving the editor (Ctonrol-X Control-C), we will find ourselves back at the command prompt ready to try out the customization.

[root@probe root]# umount /mnt/memstick 1
[root@probe root]# lnstcustom test sda1 vfat 2

... Lots of output as passwords are changed and X starts ...

1

Before trying out our custom setup script we will umount the thumb drive (as it wouldn't have been mounted if we just started the system).

2

We invoke the lnstcustom command specifying the name of the directory that our setup.sh script can be found under and the device (sda1) and file system type (vfat) to use to mount it with. It should be noted that the default values are sda1 and vfat so, in this situation we could have omitted them and simply specified: lnstcustom test.

This should be enough information to get you started in creating your own customization scripts. You can do a lot if you use your imagination and just keep adding to your setup.sh script.