Here’s bash script that can be added to a compressed tar file to create a single image extractor/installer. To create the final image, simply create a compressed tar file and concatenate it with this script. Don’t forget to set the read and execute bits.
cat install_script.sh.in my_tar_image.tar.gz > install_script.sh
chmod a+r+x install_script.sh
Here is the script. Remove the gif extension. Make sure there is new line character after the %%%% delimiter: