Add sudo_clobber and sudo_append functions so that we can "echo"

and "cat" stuff and pipe it to something that can write to a
file as root. For example:

echo "foo" | sudo_append /tmp/bar

will append "foo" to the file /tmp/bar as root. While

echo "foo" | sudo_clobber /tmp/bar

will truncate /tmp/bar and then write "foo" to the file.

Review URL: http://codereview.chromium.org/1610021
This commit is contained in:
tedbo 2010-04-12 10:52:40 -07:00
parent 30fa208c87
commit 373c3903c2

View File

@ -149,8 +149,8 @@ esac
# Functions
function setup_board_warning {
echo
echo "$V_REVERSE================= WARNING ======================$V_VIDOFF"
echo
echo "$V_REVERSE================= WARNING ======================$V_VIDOFF"
echo
echo "*** No default board detected in " \
"$GCLIENT_ROOT/src/scripts/.default_board"
@ -162,8 +162,8 @@ function setup_board_warning {
# Sets the default board variable for calling script
function get_default_board {
DEFAULT_BOARD=
DEFAULT_BOARD=
if [ -f "$GCLIENT_ROOT/src/scripts/.default_board" ] ; then
DEFAULT_BOARD=`cat "$GCLIENT_ROOT/src/scripts/.default_board"`
fi
@ -323,3 +323,17 @@ function eretry () {
function remove_quotes() {
echo "$1" | sed -e "s/^'//; s/'$//"
}
# Writes stdin to the given file name as root using sudo in overwrite mode.
#
# $1 - The output file name.
function sudo_clobber() {
sudo tee "$1" > /dev/null
}
# Writes stdin to the given file name as root using sudo in append mode.
#
# $1 - The output file name.
function sudo_append() {
sudo tee -a "$1" > /dev/null
}