Repository: bazelbuild/bazel
Issue: Bazel installer should not overwrite ~/.bazelrc
Labels: P2

The Bazel installer currently moves ~/.bazelrc to ~/.bazelrc.bak and creates an empty file instead, which is rather annoying. We should change the installer to not touch the file.

Issue comments:
You mean that having a ~/.bazelrc is no longer mandatory so the installer
shouldn't try to create one?
On Sat, 6 May 2017 at 10:29 Philipp Wollermann <notifications@github.com>
wrote:

> The Bazel installer currently moves ~/.bazelrc to ~/.bazelrc.bak and
> creates an empty file instead, which is rather annoying. We should change
> the installer to not touch the file as that mechanism is no longer needed.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/bazelbuild/bazel/issues/2958>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABUIF0cdPZ5QOWcjcBL7paMGWpth2imdks5r3CFmgaJpZM4NSqOC>
> .
>

@ittaiz I don't think a ~/.bazelrc was ever mandatory, Bazel should work just fine without any configuration files like /etc/bazelrc or ~/.bazelrc. :)

The installer currently always wants to create an empty ~/.bazelrc file. If the user has already created a ~/.bazelrc file (and possibly put some config flags there), it will be moved to ~/.bazelrc.bak, which is annoying, because your next step is probably to just move it back to ~/.bazelrc.

Instead the installer should just not touch the file at all - if it doesn't exist already, don't create one. If one exists, leave it as is.
On May 6, 2017 4:37 PM, "Philipp Wollermann" <notifications@github.com>
wrote:

@ittaiz <https://github.com/ittaiz> I don't think a ~/.bazelrc was ever
mandatory, Bazel should work just fine without any configuration files like
/etc/bazelrc or ~/.bazelrc. :)

The installer currently always wants to create an empty ~/.bazelrc file. If
the user has already created one (and possibly put some config flags
there), it will be moved to ~/.bazelrc.bak, which is annoying, because you
basically have to immediately move it back.

Instead it should just not touch the file at all - if it doesn't exist
already, don't create one. If one exists, leave it as is.

+1


—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/bazelbuild/bazel/issues/2958#issuecomment-299664397>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAIwlomGv_P6P-fhkfrcd_9sfkesGVYks5r3NoKgaJpZM4NSqOC>
.

Ok. I just don't understand what you meant by "that mechanism is no longer
needed" but I guess it's not that important.
On Sun, 7 May 2017 at 0:04 doug tangren <notifications@github.com> wrote:

> On May 6, 2017 4:37 PM, "Philipp Wollermann" <notifications@github.com>
> wrote:
>
> @ittaiz <https://github.com/ittaiz> I don't think a ~/.bazelrc was ever
> mandatory, Bazel should work just fine without any configuration files like
> /etc/bazelrc or ~/.bazelrc. :)
>
> The installer currently always wants to create an empty ~/.bazelrc file. If
> the user has already created one (and possibly put some config flags
> there), it will be moved to ~/.bazelrc.bak, which is annoying, because you
> basically have to immediately move it back.
>
> Instead it should just not touch the file at all - if it doesn't exist
> already, don't create one. If one exists, leave it as is.
>
> +1
>
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/bazelbuild/bazel/issues/2958#issuecomment-299664397>,
> or mute the thread
> <
> https://github.com/notifications/unsubscribe-auth/AAAIwlomGv_P6P-fhkfrcd_9sfkesGVYks5r3NoKgaJpZM4NSqOC
> >
> .
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <https://github.com/bazelbuild/bazel/issues/2958#issuecomment-299665809>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABUIF5bMaAvWmwGSuY78O4Vytc1IxsiZks5r3OBGgaJpZM4NSqOC>
> .
>

@ittaiz No problem and sorry for the misunderstanding. With "that mechanism", I just meant "the part of the installer that deals with the ~/.bazelrc", but re-reading my issue description I can see now how that might be confusing. I removed the part of the sentence.

Pull request review comments:

Patch that resolved the issue:
diff --git a/scripts/packages/template_bin.sh b/scripts/packages/template_bin.sh
index c35b2463d64388..906a3871d3bcea 100755
--- a/scripts/packages/template_bin.sh
+++ b/scripts/packages/template_bin.sh
@@ -41,25 +41,20 @@ usage() {
   echo "  --prefix=/some/path set the prefix path (default=/usr/local)." >&2
   echo "  --bin= set the binary folder path (default=%prefix%/bin)." >&2
   echo "  --base= set the base install path (default=%prefix%/lib/bazel)." >&2
-  echo "  --bazelrc= set the path to bazelrc (default=/etc/bazel.bazelrc)." >&2
   echo "  --user configure for user install, expands to:" >&2
-  echo '      --bin=$HOME/bin --base=$HOME/.bazel --bazelrc=$HOME/.bazelrc' >&2
+  echo '      --bin=$HOME/bin --base=$HOME/.bazel' >&2
   exit 1
 }
 
 prefix="/usr/local"
 bin="%prefix%/bin"
 base="%prefix%/lib/bazel"
-bazelrc="/etc/bazel.bazelrc"
 
 for opt in "${@}"; do
   case $opt in
     --prefix=*)
       prefix="$(echo "$opt" | cut -d '=' -f 2-)"
       ;;
-    --bazelrc=*)
-      bazelrc="$(echo "$opt" | cut -d '=' -f 2-)"
-      ;;
     --bin=*)
       bin="$(echo "$opt" | cut -d '=' -f 2-)"
       ;;
@@ -69,7 +64,6 @@ for opt in "${@}"; do
     --user)
       bin="$HOME/bin"
       base="$HOME/.bazel"
-      bazelrc="$HOME/.bazelrc"
       ;;
     *)
       usage
@@ -79,7 +73,6 @@ done
 
 bin="${bin//%prefix%/${prefix}}"
 base="${base//%prefix%/${prefix}}"
-bazelrc="${bazelrc//%prefix%/${prefix}}"
 
 test_write() {
   local file="$1"
@@ -133,7 +126,6 @@ fi
 # Test for write access
 test_write "${bin}"
 test_write "${base}"
-test_write "${bazelrc}"
 
 # Do the actual installation
 echo -n "Uncompressing."
@@ -159,17 +151,7 @@ echo -n .
 ln -s "${base}/bin/bazel" "${bin}/bazel"
 echo -n .
 
-if [ -f "${bazelrc}" ]; then
-  echo
-  echo "${bazelrc} already exists, moving it to ${bazelrc}.bak."
-  mv "${bazelrc}" "${bazelrc}.bak"
-fi
-
-# Not necessary, but this way it matches the Debian package.
-touch "${bazelrc}"
-if [ "${UID}" -eq 0 ]; then
-  chmod 0644 "${bazelrc}"
-else
+if [ "${UID}" -ne 0 ]; then
   # Uncompress the bazel base install for faster startup time
   "${bin}/bazel" help >/dev/null
 fi


Test patch: