Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2958: Installer should not overwrite bazelrc #2959

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions scripts/packages/template_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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-)"
;;
Expand All @@ -69,7 +64,6 @@ for opt in "${@}"; do
--user)
bin="$HOME/bin"
base="$HOME/.bazel"
bazelrc="$HOME/.bazelrc"
;;
*)
usage
Expand All @@ -79,7 +73,6 @@ done

bin="${bin//%prefix%/${prefix}}"
base="${base//%prefix%/${prefix}}"
bazelrc="${bazelrc//%prefix%/${prefix}}"

test_write() {
local file="$1"
Expand Down Expand Up @@ -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."
Expand All @@ -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
Expand Down