From 462c9790a0983fd23188302564dea1752b189780 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 10 Sep 2022 20:47:43 +0900 Subject: [PATCH] Avoid using sudo on protoc installation --- CHANGELOG.md | 2 ++ README.md | 2 +- main.sh | 30 ++++++++++++------------------ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b88fd307..1b2839a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] +- Avoid using sudo on `protoc` installation. + ## [1.12.4] - 2022-09-10 - Update `cargo-llvm-cov@latest` to 0.5.0. diff --git a/README.md b/README.md index 801f734d..c14b2e92 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ https://spdx.org/licenses | [**mdbook**](https://github.com/rust-lang/mdBook) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/rust-lang/mdBook/releases) | Linux, macOS, Windows | [MPL-2.0](https://github.com/rust-lang/mdBook/blob/HEAD/LICENSE) | | [**mdbook-linkcheck**](https://github.com/Michael-F-Bryan/mdbook-linkcheck) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases) | Linux, macOS, Windows | [MIT](https://github.com/Michael-F-Bryan/mdbook-linkcheck/blob/HEAD/LICENSE) | | [**nextest**](https://github.com/nextest-rs/nextest) (alias: `cargo-nextest`) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/nextest-rs/nextest/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/nextest-rs/nextest/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/nextest-rs/nextest/blob/HEAD/LICENSE-MIT) | -| [**protoc**](https://github.com/protocolbuffers/protobuf) | `/usr/local/bin` | [GitHub Releases](https://github.com/protocolbuffers/protobuf/releases) | Linux, macOS, Windows | [BSD-3-Clause](https://github.com/protocolbuffers/protobuf/blob/HEAD/LICENSE) | +| [**protoc**](https://github.com/protocolbuffers/protobuf) | `$HOME/.install-action/bin` | [GitHub Releases](https://github.com/protocolbuffers/protobuf/releases) | Linux, macOS, Windows | [BSD-3-Clause](https://github.com/protocolbuffers/protobuf/blob/HEAD/LICENSE) | | [**shellcheck**](https://www.shellcheck.net) | `/usr/local/bin` | [GitHub Releases](https://github.com/koalaman/shellcheck/releases) | Linux, macOS, Windows | [GPL-3.0-or-later](https://github.com/koalaman/shellcheck/blob/HEAD/LICENSE) | | [**shfmt**](https://github.com/mvdan/sh) | `/usr/local/bin` | [GitHub Releases](https://github.com/mvdan/sh/releases) | Linux, macOS, Windows | [BSD-3-Clause](https://github.com/mvdan/sh/blob/HEAD/LICENSE) | | [**valgrind**](https://valgrind.org) | `/snap/bin` | [snap](https://snapcraft.io/install/valgrind/ubuntu) | Linux | [GPL-2.0-or-later](https://valgrind.org/docs/manual/license.gpl.html) | diff --git a/main.sh b/main.sh index 1690bf44..c3f897b2 100755 --- a/main.sh +++ b/main.sh @@ -284,22 +284,19 @@ for tool in "${tools[@]}"; do esac miner_patch_version="${version#*.}" base_url="https://github.com/${repo}/releases/download/v${miner_patch_version}/protoc-${miner_patch_version}" - bin_dir="/usr/local/bin" - include_dir="/usr/local/include" + # Copying files to /usr/local/include requires sudo. + bin_dir="${HOME}/.install-action/bin" + include_dir="${HOME}/.install-action/include" + if [[ ! -d "${bin_dir}" ]]; then + mkdir -p "${bin_dir}" + mkdir -p "${include_dir}" + echo "${bin_dir}" >>"${GITHUB_PATH}" + export PATH="${PATH}:${bin_dir}" + fi case "${OSTYPE}" in linux*) url="${base_url}-linux-x86_64.zip" ;; darwin*) url="${base_url}-osx-x86_64.zip" ;; - cygwin* | msys*) - url="${base_url}-win64.zip" - bin_dir="${HOME}/.install-action/bin" - include_dir="${HOME}/.install-action/include" - if [[ ! -d "${bin_dir}" ]]; then - mkdir -p "${bin_dir}" - mkdir -p "${include_dir}" - echo "${bin_dir}" >>"${GITHUB_PATH}" - export PATH="${PATH}:${bin_dir}" - fi - ;; + cygwin* | msys*) url="${base_url}-win64.zip" ;; *) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;; esac mkdir -p .install-action-tmp @@ -310,12 +307,9 @@ for tool in "${tools[@]}"; do unzip tmp.zip mv "bin/protoc${exe}" "${bin_dir}/" mkdir -p "${include_dir}/" + cp -r include/. "${include_dir}/" case "${OSTYPE}" in - linux* | darwin*) sudo cp -r include/. "${include_dir}/" ;; - cygwin* | msys*) - cp -r include/. "${include_dir}/" - bin_dir=$(sed <<<"${bin_dir}" 's/^\/c\//C:\\/') - ;; + cygwin* | msys*) bin_dir=$(sed <<<"${bin_dir}" 's/^\/c\//C:\\/') ;; esac if [[ -z "${PROTOC:-}" ]]; then info "setting PROTOC environment variable"