From 55c01c4e547210dee37d96290aef8d3235d2c769 Mon Sep 17 00:00:00 2001 From: Robin Zhong Date: Fri, 12 Oct 2012 23:01:02 +0800 Subject: [PATCH] sudo request only can't write file to /usr/local/bin. thank for https://github.com/nnutter/git-gerrit 's great patch. --- install.sh | 16 ++++++++++++++-- install_local.sh | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index c6a04d9..a372598 100755 --- a/install.sh +++ b/install.sh @@ -40,14 +40,26 @@ tar -xzf $dst pushd $extract_dir 1>/dev/null # copy bin. -sudo cp $src_bin/* "$dst_bin" +echo "installing git-gerrit to /usr/local/bin..." +if [ -w "$dst_bin" ]; then + cp $src_bin/* "$dst_bin" +else + echo "request sudo authorization to install git-gerrit to /usr/local/bin:" + sudo cp $src_bin/* "$dst_bin" +fi if [ ! -d "$dst_completion" ] ; then mkdir -p "$dst_completion" fi # copy bash-completion. -sudo cp $src_completion/* "$dst_completion" +if [ -w "$dst_completion" ]; then + cp $src_completion/* "$dst_completion" +else + echo "request sudo authorization to install git-gerrit to /usr/local/bin:" + sudo cp $src_completion/* "$dst_completion" +fi + popd 1>/dev/null diff --git a/install_local.sh b/install_local.sh index 57b3284..c76f575 100755 --- a/install_local.sh +++ b/install_local.sh @@ -21,13 +21,24 @@ if [ "Darwin" = "$name" ] ; then fi # copy bin. -sudo cp $src_bin/* "$dst_bin" +echo "installing git-gerrit to /usr/local/bin..." +if [ -w "$dst_bin" ]; then + cp $src_bin/* "$dst_bin" +else + echo "request sudo authorization to install git-gerrit to /usr/local/bin:" + sudo cp $src_bin/* "$dst_bin" +fi if [ ! -d "$dst_completion" ] ; then mkdir -p "$dst_completion" fi # copy bash-completion. -sudo cp $src_completion/* "$dst_completion" +if [ -w "$dst_completion" ]; then + cp $src_completion/* "$dst_completion" +else + echo "request sudo authorization to install git-gerrit to /usr/local/bin:" + sudo cp $src_completion/* "$dst_completion" +fi echo "git-gerrit install success."