Automating a .deb Debian package for Fasteroids

Automating a .deb Debian package for Fasteroids

Many versions of Fasteroids ago I made a 3rd download available in the form of a .deb install-able Debian software package. To create the Debian package I followed a tutorial that involved copying a template and editing a number of files manually. Not only is this not the prescribed method for creating Debian packages, but it was a lot of manual work that left room for a lot of editing errors. I've always known that I wanted to create an install-able Debian package to help take care of dependency issues, but there is a pretty big learning curve from what I understand. The curve continues, but I've started working on a shell script to automate the process of creating a .deb Debian package based on a single folder in a sandbox directory.

The script works something like this: there's a directory called sandbox and in that directory are the shell script and the directory/folder containing the fasteroids code. For example: and a folder called fasteroids-2.5/. The shell script looks at the directory name then stores the entire directory name in one variable, the version in another variable, and the first part of the directory name (minus the version) in a third variable.

From there the shell script changes into the fasteroids-2.5/ sub-directory, creates a .desktop file and marks that file as executable. The shell script then goes up a directory to the sandbox directory, tar's and gzip's the directory, moves the resulting file fasteroids-2.5.tar.gz into the fasteroids-2.5/ sub-directory, changes into that directory and runs dh_make against that tarred and gzipped file.

The tarred and gzipped file is then removed and the shell script proceeds into the newly created (by dh_make) debian directory within the fasteroids-2.5/ directory. There the script erases some files I'm not going to use (ex files, and for now the README files). Finally it makes a bunch of changes to the control file within the fasteroids-2.5/debian directory.

This is as far as I've gotten so far. I know there's a lot more work to be done, but the following script is at least a start. Here's my sloppy shell script for the world to criticize:

# created by Charles McColm for Fasteroids game on Xubuntu

dirname=$(ls -d */ | sed 's/.$//')
program=$(echo $dirname | sed -n 's/[-].*//p')
version=$(echo $dirname | sed -n 's/.*-//p')
cd $dirname
touch $dirname.desktop
echo "[Desktop Entry]" >> $dirname.desktop
echo "Version="$version >> $dirname.desktop
echo "Name="$dirname >> $dirname.desktop
echo "Exec="$program >> $dirname.desktop
echo "Icon="$dirname >> $dirname.desktop
echo "Type=Application" >> $dirname.desktop
echo "Categories=Games" >> $dirname.desktop
echo "Terminal=false" >> $dirname.desktop
chmod +x $dirname.desktop
cd ..
tar -cvzf $dirname.tar.gz $dirname
mv $dirname.tar.gz $dirname
cd $dirname
dh_make -e -f $dirname.tar.gz
rm $dirname.tar.gz
cd debian
rm *.ex
rm *.EX
sed -i '/Section: unknown/c\Section: games' control
sed -i '/Homepage: /c\Homepage:' control
sed -i '/Depends: ${shlibs:Depends}, ${misc:Depends}/c\Depends: ${shlibs:Depends}, ${misc:Depends}, libcurl4, libopenal1' control
ex -sc '%s/\(\Description:\).*/\1/ | x' control
sed -i '/Description:/c\Description: Asteroids-like game running at 1024x768' control
sed -i '/ /c\ Fasteroids is an Asteroids-like game.' control