I was trying to add some documentation packages today, and kept getting
annoyed that it would not let me - I was not root. I decided that it
should know that I was the admin, and let me do it anyway.

This is what I came up with:

$HOME/bin/aptitude
-- >% -- CUT HERE -- %< --
#!/bin/sh

PROGRAM=/usr/bin/aptitude
SUDO=/usr/bin/sudo
NEED_ROOT=255

$PROGRAM ${1:-"$@"}
if [ $? -eq $NEED_ROOT ]
then
        exec $SUDO $PROGRAM ${1:-"$@"}
fi
-- >% -- CUT HERE -- %< --

This can be expanded to other programs:

$HOME/bin/apt-get
-- >% -- CUT HERE -- %< --
#!/bin/sh

PROGRAM=/usr/bin/aptitude
SUDO=/usr/bin/sudo
NEED_ROOT=255

$PROGRAM ${1:-"$@"}
if [ $? -eq $NEED_ROOT ]
then
        exec $SUDO $PROGRAM ${1:-"$@"}
fi
-- >% -- CUT HERE -- %< --


or

$HOME/bin/yum
-- >% -- CUT HERE -- %< --
#!/bin/sh

PROGRAM=/usr/bin/yum
SUDO=/usr/bin/sudo
NEED_ROOT=1

$PROGRAM ${1:-"$@"}
if [ $? -eq $NEED_ROOT ]
then
        exec $SUDO $PROGRAM ${1:-"$@"}
fi
-- >% -- CUT HERE -- %< --
(for yum, a $? of 1 means any sort of error, so a mistyped sub-command
will cause yum to run twice, with the same result)

Enjoy!

-john


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to