Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

While doing project , I found a script that is bounced over my head. Can you help me to understand this script . Please explain this script step by step.

SCRIPT

if ! [ -f /usr/local/bin/XXX -a -f /usr/local/bin/YYY -a -f /usr/local/bin/ZZZ ]
then
    if [ "`uname`" = "Linux" ]
    then
        UUDECODE="uudecode -o /dev/stdout"
    else
        UUDECODE="uudecode -p"
    fi
    cat $0 | awk 'printme == "1" {print} /^DATA BEGINS HERE/ {printme = "1"}' | ${UUDECODE} | (cd /usr/local/bin ; sudo tar xzf - --unlink)
    sudo chmod AAAA /usr/local/bin/XXX /usr/local/bin/YYY
fi

My understanding so far

  1. This script checks if XXX , YYY , ZZZ is present in /usr/local/bin , is present or not.
  2. If not then it enters in the body of if.
  3. If current OS is Linux, then it do
  4. But after that I didn't understand.

Strange after running this script these three executables are in /usr/local/bin. Explain below script line by line please.

One thing that I mention that, at the end of script, there is some unreadable data is there, starting from "DATA BEGINS HERE". Is this script copies this data to /usr/local/bin ?

share|improve this question

1 Answer 1

If it is Linux, it sets UUDECODE to one form of calling the command uudecode, if not, another one. It isn't standard, so how to call it varies. Not very smart, if you ask me.

The line starting cat $0 does the real work. $0 is the name of the running process, i.e., of the current script. Again, will mostly work but can be fooled.

The contents of the script are piped to the awk script, which copies all the text after DATA BEGINS HERE to its output, which is piped to uudecode (the command set up before). uudecode takes text and makes a binary of it (the pair uuencode/uudecode where used to ship binaries around as text before HTTP and others became popular), the result is piped to the command in '()', which first changes into /usr/local/bin and then unpacks the input with tar there. The --unlink first deletes any existing file.

Where does this come from?!

share|improve this answer
    
This is related to my college project. –  devnull Mar 21 '13 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.