fix: linuxmint distro detection and rustup default toolchain issue for sudo users
Some checks are pending
Build & Release / Build & test (push) Waiting to run
Build & Release / Build .deb (push) Blocked by required conditions

This commit is contained in:
Khoa Vo 2026-06-29 20:50:15 +07:00
parent efa831bd0b
commit d9091ff66f

View file

@ -40,7 +40,7 @@ install_dependencies() {
echo -e "Installing ${mode} dependencies..." echo -e "Installing ${mode} dependencies..."
case "$DISTRO" in case "$DISTRO" in
ubuntu|debian|raspbian|pop|mint|neon) ubuntu|debian|raspbian|pop|mint|linuxmint|neon)
apt-get update -y apt-get update -y
if [ "$mode" = "build" ]; then if [ "$mode" = "build" ]; then
apt-get install -y build-essential pkg-config libx11-dev libxtst-dev libdbus-1-dev libevdev-dev apt-get install -y build-essential pkg-config libx11-dev libxtst-dev libdbus-1-dev libevdev-dev
@ -71,6 +71,14 @@ install_dependencies() {
# Check for Rust compiler (needed only for source build) # Check for Rust compiler (needed only for source build)
check_rust() { check_rust() {
if [ -n "${SUDO_USER:-}" ]; then
local user_home
user_home="$(getent passwd "$SUDO_USER" 2>/dev/null | cut -d: -f6 || echo "/home/$SUDO_USER")"
export CARGO_HOME="$user_home/.cargo"
export RUSTUP_HOME="$user_home/.rustup"
export PATH="$CARGO_HOME/bin:$PATH"
fi
if ! command -v cargo >/dev/null 2>&1; then if ! command -v cargo >/dev/null 2>&1; then
echo -e "${YELLOW}Rust toolchain not found.${NC}" echo -e "${YELLOW}Rust toolchain not found.${NC}"
read -p "Would you like to install Rust toolchain now? [Y/n] " -n 1 -r read -p "Would you like to install Rust toolchain now? [Y/n] " -n 1 -r
@ -81,11 +89,8 @@ check_rust() {
fi fi
echo "Installing Rust via rustup.rs..." echo "Installing Rust via rustup.rs..."
# Run rustup installer as the original non-root user if SUDO_USER is set # Run rustup installer as the original non-root user if SUDO_USER is set
local user_cmd=""
if [ -n "${SUDO_USER:-}" ]; then if [ -n "${SUDO_USER:-}" ]; then
su - "$SUDO_USER" -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" su - "$SUDO_USER" -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
# Add to PATH for this script session
export PATH="/home/$SUDO_USER/.cargo/bin:$PATH"
else else
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH" export PATH="$HOME/.cargo/bin:$PATH"