Creating a deb file
Debian and/or Ubuntu  --  By Rodney Richison

(This is an example to create a deb for the tool "vboxtool" which is a collection of scripts to manage virtualbox)
(It's just an example of how one can setup scripts to run at startup, quickly installable via a .deb file)


Create two directories

mkdir -p ~/vboxtool-0.3/debian


Go to parent directory

cd ~/vboxtool-0.3/

Create a file called create_deb.sh

vi create_deb.sh

Insert below in the file
*******************************************************************************

#!/bin/bash

package_dir=/home/rodney/vboxtool-0.3/debian
package_name=vboxtool-0.3-all.deb
control_files="control changelog postinst postrm"
# Files to be installed relevent to destination
data_dirs="usr/sbin/ etc/"

cd $package_dir

# write the control file
cat > control <<END
Package: vboxtool
Version: 0.3
Maintainer: rodney@rcrcomputing.com
Installed-Size: 32
Priority: optional
Section: base
Essential: NO
Recommends: virtualbox
Architecture: all
Maintainer: Rodney Richison [rodney@rcrcomputing.com]
Description: Tools for managing virtualbox. Feature auto-start at boot, backup, etc..
END

cat > changelog <<END
vboxtool (0.3) unstable; urgency=low

  * Initial Release.

 -- Rodney Richison <rodney@rcrcomputing.com>  Sat, 25 Oct 2008 08:44:50 -0500
END


# write the post-installation script
cat > postinst <<END
#!/bin/bash
update-rc.d vboxtoolinit defaults 99 10

echo VBoxTool Installed..
echo You MUST edit BOTH /etc/vboxtool config files.
END


# write the post-removal script
cat > postrm <<END
#!/bin/bash
update-rc.d -f vboxtoolinit remove
END

# *********************************************

# create the data tarball
# (the tar options "czvf" mean create, zip, verbose, and filename.)
tar czvf data.tar.gz $data_dirs
#usr/sbin/ etc/

# create the control tarball
tar czvf control.tar.gz $control_files
# control changelog postinst postrm

# create the debian-binary file
echo 2.0 > debian-binary

# create the ar (deb) archive
ar -r $package_name debian-binary control.tar.gz data.tar.gz

# move the new deb up a directory
mv $package_name ..

# remove the tarballs, and cd back up to where we started
rm data.tar.gz control.tar.gz
cd ..
#************* End of create_deb.sh ***************************

Of course, edit the file for correct path etc..

Now let's download vboxtool
# Current version on 10/25/08
wget http://internap.dl.sourceforge.net/sourceforge/vboxtool/vboxtool-0.3.zip

make a directory for the /etc/ and /usr/
mkdir -p ~/vboxtool-0.3/debian/usr/sbin
mkdir -p ~/vboxtool-0.3/debian/etc/init.d
mkdir -p ~/vboxtool-0.3/debian/etc/vboxtool


Copy files from the vboxtool zip file you downloaded

cp vboxtool ~/vboxtool-0.3/debian/usr/sbin/
cp vboxtoolinit ~/vboxtool-0.3/debian/etc/init.d/
cp changelog.txt ~/vboxtool-0.3/debian/etc/vboxtool/
cp copying.txt ~/vboxtool-0.3/debian/etc/vboxtool/
cp machines.conf ~/vboxtool-0.3/debian/etc/vboxtool/
cp readme.txt ~/vboxtool-0.3/debian/etc/vboxtool/
cp vboxtool.conf  ~/vboxtool-0.3/debian/etc/vboxtool/




This should finish the directory structure.

You should now have something like this

~/yourname/vboxtool-0.3
        /debian
                ---> create_deb.sh
                /usr/sbin
                        --->
vboxtool
                /etc/init.d
                        ---> vboxtoolinit
                /etc/vboxtool
                        ---> changelog.txt copying.txt machines.conf readme.txt vboxtool.conf

This is the directory structure template for you .deb file.

Now, go back to the vboxtoo-0.3 directory and run it (make sure to edit this file with your file path prefs.

chmod 755 create_deb.sh
./create_deb.sh

You should have a .deb file now..


NOTE: your see the create_deb script creates some files like postinst and preinst. These are very useful for commands that should be run after install or after removal etc..  There are other files you can have, but that's enough material for this short tutorial..