"I want to change a software package to an rpm."
checkinstall does what you want to do:
With checkinstall you unpack a tarball, cd to the proper directory, and then do:
and checkinstall will create a rpm package for you in the /usr/src tree.
If you want to chug onward and finish your script then take a look at the checkinstall source code to learn what to do.
Be prepared. Create a LifeBoat CD.