Results 1 to 7 of 7
For programs on Linux. I'd like it to be fully automated, from extracting the contents all the way to make install. But I have one problem, I need to know ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-23-2005 #1Just Joined!
- Join Date
- May 2005
- Posts
- 97
Going to make a source-compile script
For programs on Linux. I'd like it to be fully automated, from extracting the contents all the way to make install. But I have one problem, I need to know how to take user input to cd to the extracted directory. so far I have
It's simple, probably too simple to ask about here. But if it's possible, someone tell me and it'll be appreciated.Code:tar -xvzf $1 && cd [user input] && ./configure && make && make install && cd ~
- 10-23-2005 #2
If I understand you correctly -- you might want to consider writing your script so that the command call is something like:
Then,Code:ScriptName <tar file> <install directory>
$1 ==> <tar file>
$2 ==> <install directory>
Also consider:
It is not necessary to put everything in one line - only in aliases do you need to do that - in scripts, you have the luxury of writing it out line-by-line, adding comments, etc...
It would be good/better to check the error status after './configure', 'make', and 'make install' (and possibly after the execution of some other commands - hint, hint
) - so that you can prevent program execution from continuing if something goes wrong - not to mention, it gives you the ability to output a more user-friendly error message, control the exit code, etc.
You could add another argument to your script:
This would enable you to use your script on more types of tar files.Code:ScriptName <filter> <tar file> <install directory> or ScriptName <tar file> <filter> <install directory>
Or even better yet:
Here, you have to do a little more work - because '[tar options]' may or may not exist. But the idea is to be able to pass other "special case" options to tar (including filter options)...Code:ScriptName [tar options] <tar file> <install directory> (best - most logical) or ScriptName <tar file> [tar options] <install directory> (next best) or ScriptName <tar file> <install directory> [tar options] (easiest)
You could probably even determine automatically what filter to use based on the name of the file ["extensions"]...
If you prefer your script ask the user for the install path after invoking the script -- there is nothing wrong with that - it is a matter of preference (it's your script
) -- the rest can stay the same... If you definitely want to ask the user from the script after invoking the script (instead of handing it to the program from the command line) - please post and indicate that is what you had in mind... (and we can go that route...)
- 10-23-2005 #3Linux Engineer
- Join Date
- Jan 2005
- Location
- Chicago (USA)
- Posts
- 1,028
I made one of those. Then I learned about the GNU Source Installer.
- 10-24-2005 #4Just Joined!
- Join Date
- May 2005
- Posts
- 97
Hm..ISOS that looks pretty fun.

I'm not quite sure what you mean by ScriptName though, or what $2 is.
Sooo, let's say I want to be able to handle both .tar.gz and .tar.bz2 files, I'm assuming I'd use or, correct?
I remember you said some stuff about checking for errors after each command, how would I go about doing that?Code:#!/bin/bash # source compilation and installation script # tar -xvzf $1 directory-name or tar -xvjpf $1 directory-name # cd directory-name # above is where I'm having troubles figuring out what to do, would I use $2 ? # ./configure make make install make clean
- 10-25-2005 #5
ScriptName is simply the name of your script.
$2 is the second argument handed to your script from the command-line:
After looking at your post again, I now realize you don't need any more arguments to your script for what you are intending to do...Code:command arg1 arg2 arg3 ... $1 $2 $3
Here is something I just "whipped up" (I got to get to work...) - it is a simple approach - it needs to be finished:
I'm sure it can be improved upon and "fancied up" a bit...Code:#!/bin/bash if test $# -ne 1 ; then echo "Usage: $0 <tar file>" exit 1 fi EXT1="" EXT2="" EXTRACT_DIR="" TAR_FILE=$1 NAME1="${TAR_FILE%.*}" if test $NAME1 != $TAR_FILE ; then EXT1="${TAR_FILE#$NAME1}" EXTRACT_DIR="$NAME1" NAME2="${NAME1%.*}" if test $NAME2 != $NAME1 ; then EXT2="${NAME1#$NAME2}" EXTRACT_DIR="$NAME2" fi fi if test "$EXT1" = ".tar" ; then TAR_ARGS="-xvf $TAR_FILE" ; elif test "$EXT1" = ".gz" -a "$EXT2" = ".tar" ; then TAR_ARGS="-xvzf $TAR_FILE" ; elif test "$EXT1" = ".bz2" -a "$EXT2" = ".tar" ; then TAR_ARGS="-xvjpf $TAR_FILE"; else echo "Not able to identify tar file type for '$TAR_FILE'." exit 2 fi echo "Executing: tar $TAR_ARGS" tar $TAR_ARGS if test $? -ne 0 ; then echo "Extraction error!" exit 3 fi cd $EXTRACT_DIR
- 10-29-2005 #6Just Joined!
- Join Date
- May 2005
- Posts
- 97
Thank you very much!
- 10-29-2005 #7


Reply With Quote
