diff --git a/script/bootstrap b/script/bootstrap index 0e9b7474..e755172d 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -41,14 +41,25 @@ 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 +157,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:?}"