:-'Generic Commit'
This commit is contained in:
parent
5c50493238
commit
ff7bf31822
@ -4,6 +4,21 @@ set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
# If the user is not root, use sudo
|
||||
SUDOCMD=""
|
||||
[ "$EUID" -eq 0 ] || SUDOCMD="sudo"
|
||||
|
||||
# If the user is not root, use the home directory of the user who ran the script
|
||||
USER_HOME="$HOME"
|
||||
if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then
|
||||
USER_HOME=$(eval echo "~${SUDO_USER}")
|
||||
fi
|
||||
|
||||
# test sudo is working or we're root (return non-zero if not root!)
|
||||
if ! "$SUDOCMD" true; then
|
||||
echo "Error: This script must be run as root or with sudo privileges." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_die() {
|
||||
echo -e "Error: $1" >&2
|
||||
@ -82,7 +97,7 @@ function install_packages() {
|
||||
HAVE_UPDATED=1
|
||||
fi
|
||||
|
||||
if ! sudo apt-get install -y "$pkg"; then
|
||||
if ! "$SUDOCMD" apt-get install -y "$pkg"; then
|
||||
print_error "Failed to install $pkg"
|
||||
exit 1
|
||||
fi
|
||||
@ -102,7 +117,7 @@ function install_headers() {
|
||||
cd "libassert/build" || exit 1
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
make -j
|
||||
sudo make install
|
||||
"$SUDOCMD" make install
|
||||
cd ../..
|
||||
rm -rf libassert
|
||||
fi
|
||||
@ -259,11 +274,6 @@ function installmusl() {
|
||||
echo "Installing musl toolchain"
|
||||
|
||||
# Set install directory
|
||||
if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then
|
||||
USER_HOME=$(eval echo "~${SUDO_USER}")
|
||||
else
|
||||
USER_HOME="$HOME"
|
||||
fi
|
||||
INSTALL_DIR="$USER_HOME/.musl-cross"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user