Armin K. wrote:
> On 10/09/2012 06:33 PM, Bruce Dubbs wrote:
>> Armin K. wrote:
>>
>>    >   From what I see, your command would attempt to use either sudo or su
>>    > even if ran as root user. Maybe some kind of "am I root?" checking
>>    > should be done there before trying to check for sudo or execute su if
>>    > sudo is not present.
>>
>> as_root()
>> {
>>      if   [ $EUID = 0 ];        then $*
>>      elif [ -x /usr/bin/sudo ]; then sudo $*
>>      else                            su -c \\"$*\\"
>>      fi
>> }
>>
>> export -f as_root
>>
>> The spacing may be slightly overdone.

> Looks better. But, I have a suggestion. Let's include the "script" into
> instructions, for example:
>
> if [ $EUID = 0 ]; then make install
> elif [ -x /usr/bin/sudo ]; then sudo make install
> else su -c "make install"
> fi
>
> Add it by default instead of "AS_ROOT make install", but explain how
> should it be used and what it really does.
>
> What do you say?

That would be OK, but I did like the idea of using a bash function from 
an educational perspective.  Perhaps a note describing that in the first 
instance would provide an option for users.

For that matter, the whole script could be made into a function:

build()
{
  for package in $(grep -v '^#' $1 | awk '{print $2}')
  do
   packagedir=${package%.tar.bz2}
   tar -xf $package
   pushd $packagedir
   ./configure $XORG_CONFIG

   if [ $EUID = 0 ]; then make install
   elif [ -x /usr/bin/sudo ]; then sudo make install
   else su -c "make install"
   fi

   popd
   rm -r $packagedir
  done

}

Then just

build ../proto-7.7.md5

The interesting (confusing) thing here is that $1 is the parameter to 
the build function and $2 is related to the awk command and not the 
function.

The script for the xorg libraries is different and uses AS_ROOT twice, 
but xorg apps and xorg fonts would use the same function with a 
different argument.

I'm just throwing this out for discussion.

   -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to