From ecf71cedfe98a76f66327fff2ccb8ec34831c095 Mon Sep 17 00:00:00 2001 From: Mason Tran Date: Tue, 6 Feb 2024 23:30:34 -0500 Subject: [PATCH] [script] remove usage of sudo from bootstrap --- script/bootstrap | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/script/bootstrap b/script/bootstrap index 0e9b7474..295c9fcf 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -41,14 +41,29 @@ script_dir="$(realpath "$(dirname "${script_path}")")" repo_dir="$(dirname "${script_dir}")" # ============================================================================== +# Fancy red-colored `error` function with `stderr` redirection with `exit`. +error() +{ + { + printf '\E[31m' + echo "$@" + printf '\E[0m' + } >&2 + exit 1 +} install_packages_apt() { + # Test for root user. + if [ "$EUID" -ne 0 ]; then + error "Please re-run this script as root or with sudo" + fi + echo 'Installing script dependencies...' - # apt-get update and install dependencies - sudo apt-get update - sudo apt-get --no-install-recommends install -y \ + # Install dependencies + apt-get update + apt-get --no-install-recommends install -y \ coreutils \ openjdk-17-jre \ python3-setuptools \ @@ -146,8 +161,10 @@ install_arm_toolchain() # Extract tar xf "${toolchain_dir}/${tarball}" --directory "${toolchain_dir}/${extract_dir}" --strip-components=1 - # Link - sudo ln -s -f "${toolchain_dir}"/"${extract_dir}"/bin/* /usr/local/bin/ + # Link if root + if [ "$EUID" -eq 0 ]; then + ln -s -f "${toolchain_dir}"/"${extract_dir}"/bin/* /usr/local/bin/ + fi # Cleanup rm -rf "${toolchain_dir:?}/${tarball:?}"