From 5708cbdc7236a53cf6dd587063a9df27e034e0f8 Mon Sep 17 00:00:00 2001 From: detiam Date: Mon, 18 Mar 2024 03:59:23 +0800 Subject: [PATCH] optimize deps installation - add `-packages_skip` - able run without root --- README.md | 3 ++- build_linux_deps.sh | 54 +++++++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 07b893e8..0faf4a61 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,8 @@ This will: Additional arguments you can pass to this script: * `-j `: build with `` parallel jobs, by default 70% of the available threads * `-verbose`: output compiler/linker commands used by `CMAKE` -* `-packages_only`: install the required Linux packages via `apt isntall` and exit (don't rebuild) +* `-packages_skip`: skip package installation via `apt install` and continue build +* `-packages_only`: install the required Linux packages via `apt install` and exit (don't rebuild) --- diff --git a/build_linux_deps.sh b/build_linux_deps.sh index cdb7ef72..47754b6d 100644 --- a/build_linux_deps.sh +++ b/build_linux_deps.sh @@ -12,12 +12,6 @@ # https://linux.die.net/man/1/nm #nm -D --defined-only libsteam.so | grep " T " - -if [ "$(id -u)" -ne 0 ]; then - echo "Please run as root" >&2 - exit 1 -fi - # common stuff script_dir=$( cd -- "$( dirname -- "${0}" )" &> /dev/null && pwd ) deps_dir="$script_dir/build/deps/linux" @@ -38,6 +32,7 @@ deps_archives=( # < 0: deduce, > 1: force PARALLEL_THREADS_OVERRIDE=-1 VERBOSITY='' +INSTALL_PACKAGES=1 INSTALL_PACKAGES_ONLY=0 for (( i=1; i<=$#; i++ )); do @@ -52,6 +47,8 @@ for (( i=1; i<=$#; i++ )); do #echo "[?] Overriding parralel build jobs count with $PARALLEL_THREADS_OVERRIDE" elif [[ "$var" = "-verbose" ]]; then VERBOSITY='-v' + elif [[ "$var" = "-packages_skip" ]]; then + INSTALL_PACKAGES=0 elif [[ "$var" = "-packages_only" ]]; then INSTALL_PACKAGES_ONLY=1 else @@ -66,19 +63,12 @@ last_code=0 ############## required packages ############## echo // installing required packages -apt update -y -last_code=$((last_code + $?)) - -apt install "coreutils" -y # echo, printf, etc... -last_code=$((last_code + $?)) -apt install "tar" -y # we need to extract packages -last_code=$((last_code + $?)) -apt install "binutils" -y # (optional) contains the tool 'readelf' mainly, and other usefull binary stuff -#apt install cmake git wget unzip -y all_packages=( + "coreutils" # echo, printf, etc... + "tar" # we need to extract packages "build-essential" - "gcc-multilib" # needed for 32-bit builds + "gcc-multilib" # needed for 32-bit builds "g++-multilib" "clang" "libglx-dev" # needed for overlay build (header files such as GL/glx.h) @@ -86,13 +76,33 @@ all_packages=( "binutils" # (optional) contains the tool 'readelf' mainly, and other usefull binary stuff ) -for dep in "${all_packages[@]}"; do - apt install "$dep" -y - last_code=$((last_code + $?)) -done +if [[ "$INSTALL_PACKAGES" -ne 0 ]]; then + if [ "$(id -u)" -ne 0 ]; then + # if sudo exist, use sudo. + if type sudo > /dev/null 2>&1; then + apt_run() { sudo apt "$@" -y || exit $? ; } + else + echo "Please run as root, install sudo or pass '-packages_skip' argument." >&2 + exit 1 + fi + else + apt_run() { apt "$@" -y || exit $? ; } + fi -# exit early if we should install packages only, used by CI mainly -[[ "$INSTALL_PACKAGES_ONLY" -ne 0 ]] && exit $last_code + apt_run update + last_code=$((last_code + $?)) + + for dep in "${all_packages[@]}"; do + apt_run install "$dep" + last_code=$((last_code + $?)) + done + + # exit early if we should install packages only, used by CI mainly + [[ "$INSTALL_PACKAGES_ONLY" -ne 0 ]] && exit $last_code +else + echo "Package installation skipped, please be sure the follow packages correspond to your distro is installed." + echo "${all_packages[*]}" +fi echo; echo;