Click to See Complete Forum and Search --> : A bash script for compiling programs automatically


ecks
05-24-2004, 07:51 PM
We all know how tedious it can be to install programs from source. First, you have to uncompress it, then put that in your appropriate directory, then type ./configure, make and make install. Well, I made a simple script that installs everything in the designated directories with just one command. You might have to configure it to your needs, for example, set your default downlad folder, the folder where you want to uncompress everything, and where you want it installed. I didn't want to put too many switches, I wanted to keep it simple. So, after you uncompress everything, it asks you if you want to install everything or install it yourself. Pressing y for yes will install it, and pressing n for no will exit. So far, it automatically checks whether it's a .tar.gz file or a .tar.bz2 file, but other formats are very easy to implement in. I would like to thank maccorin for helping me figure how to get that working. That's it, with all that said, I hope someone actually finds this script usefull. Here it is:

#!/bin/bash

download_dir=/home/ecks/Desktop
src_dir=/usr/local/src
input=$1

help()
{
if [ -z "$#" ] ;
then
echo "Usage: `basename $0` filename"
fi
}
check_file()
{
file_exist=`ls | grep $input`

if [ -z $file_exist ] ; then
echo "No such file in current directory"
exit
fi
}

check_root()
{
user=`whoami`
if [ $user != "root" ] ; then
echo "You need to log in as root to use this script"
exit
fi
}

cd_dir()
{
tar_dir=`echo $input | perl -pe 's|(.*?)\.[^\d].*|$1|'`
cd $src_dir/$tar_dir
}

check_compressed_type()
{
compressed_type=`echo $input | perl -pe 's|.*?\.([^\d].*)|$1|'`

case $compressed_type in
"tar.gz")tar -x -z -f $input;;
"tar.bz2")tar -x -j -f;;
"*")echo "No recognized compression method found.";;
esac
# please put any other compression forms if you know them
}

make_env()
{
cd $download_dir
check_file
check_root
mv $input $src_dir
cd $src_dir
check_file
check_compressed_type
cd_dir
}

make_check()
{

echo -n "Do you want to compile the program with regular options? "
read answer

case $answer in
"y")return;;
"n")echo "Ok, no compiling...";exit;;
"*")echo -n "Please press y)es or n)o: ";make_check;;
esac
}

make_file()
{
./configure --prefix=/usr/local
make
make install
make clean
}

# this puts all the files in it's appropriate directories
make_env

# this asks whether you want to install the fiile
make_check

# this actually installs the file
make_file

bosox79
05-24-2004, 09:42 PM
ecks,

Thanks a bunch, this could be very handy for me when I get lazy:)