Find the answer to your Linux question:
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.
  1. #1
    Just 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

    Code:
    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
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    If I understand you correctly -- you might want to consider writing your script so that the command call is something like:

    Code:
    ScriptName <tar file> <install directory>
    Then,
    $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:

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

    Or even better yet:

    Code:
    ScriptName &#91;tar options&#93; <tar file> <install directory>     &#40;best - most logical&#41;
    or
    ScriptName <tar file> &#91;tar options&#93; <install directory>     &#40;next best&#41;
    or
    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
    Location
    Chicago (USA)
    Posts
    1,028
    I made one of those. Then I learned about the GNU Source Installer.

  4. #4
    Just 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?

    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
    I remember you said some stuff about checking for errors after each command, how would I go about doing that?

  5. #5
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    ScriptName is simply the name of your script.

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

    Code:
    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:

    Code:
    #!/bin/bash
    
    if test $# -ne 1 ; then
      echo "Usage&#58;  $0 <tar file>"
      exit 1
    fi
    EXT1=""
    EXT2=""
    EXTRACT_DIR=""
    TAR_FILE=$1
    NAME1="$&#123;TAR_FILE%.*&#125;"
    if test $NAME1 != $TAR_FILE ; then
      EXT1="$&#123;TAR_FILE#$NAME1&#125;"
      EXTRACT_DIR="$NAME1"
      NAME2="$&#123;NAME1%.*&#125;"
      if test $NAME2 != $NAME1 ; then
        EXT2="$&#123;NAME1#$NAME2&#125;"
        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&#58; tar $TAR_ARGS"
    tar $TAR_ARGS
    if test $? -ne 0 ; then
      echo "Extraction error!"
      exit 3
    fi
    cd $EXTRACT_DIR
    I'm sure it can be improved upon and "fancied up" a bit...

  6. #6
    Just Joined!
    Join Date
    May 2005
    Posts
    97
    Thank you very much!

  7. #7
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    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
  •