Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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

    tar -xvzf $1 && cd [user input] && ./configure && make && make install && cd ~
    It's simple, probably too simple to ask about here. But if it's possible, someone tell me and it'll be appreciated.

  2. #2
    If I understand you correctly -- you might want to consider writing your script so that the command call is something like:

    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:

    ScriptName <filter> <tar file> <install directory>
    ScriptName <tar file> <filter> <install directory>
    This would enable you to use your script on more types of tar files.

    Or even better yet:

    ScriptName &#91;tar options&#93; <tar file> <install directory>     &#40;best - most logical&#41;
    ScriptName <tar file> &#91;tar options&#93; <install directory>     &#40;next best&#41;
    ScriptName <tar file> <install directory> &#91;tar options&#93;     &#40;easiest&#41;
    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)...

    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...)

  3. #3
    Linux Engineer
    Join Date
    Jan 2005
    Chicago (USA)
    I made one of those. Then I learned about the GNU Source Installer.

  4. $spacer_open
  5. #4
    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?

    # source compilation and installation script
    tar -xvzf $1 directory-name
    tar -xvjpf $1 directory-name
    cd directory-name
    # above is where I'm having troubles figuring out what to do, would I use $2 ?
    make install
    make clean
    I remember you said some stuff about checking for errors after each command, how would I go about doing that?

  6. #5
    ScriptName is simply the name of your script.

    $2 is the second argument handed to your script from the command-line:

    command arg1 arg2 arg3 ...
            $1   $2   $3
    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...

    Here is something I just "whipped up" (I got to get to work...) - it is a simple approach - it needs to be finished:

    if test $# -ne 1 ; then
      echo "Usage&#58;  $0 <tar file>"
      exit 1
    if test $NAME1 != $TAR_FILE ; then
      if test $NAME2 != $NAME1 ; then
    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";
      echo "Not able to identify tar file type for '$TAR_FILE'."
      exit 2
    echo "Executing&#58; tar $TAR_ARGS"
    tar $TAR_ARGS
    if test $? -ne 0 ; then
      echo "Extraction error!"
      exit 3
    I'm sure it can be improved upon and "fancied up" a bit...

  7. #6
    Thank you very much!

  8. #7
    You are very welcome. Have fun with it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts