fix: enhance scripts to keep sudo credentials alive during installation
This commit is contained in:
+16
-11
@@ -90,24 +90,29 @@ def _ask(step: str, question: str, options: List[str], default: str) -> Optional
|
|||||||
|
|
||||||
|
|
||||||
def _detect_webots_home() -> str:
|
def _detect_webots_home() -> str:
|
||||||
"""Return the WEBOTS_HOME path for the locally installed Webots.
|
"""Return the WEBOTS_HOME path for the locally installed Linux Webots.
|
||||||
|
|
||||||
Checks the environment variable first, then the default deb install path,
|
Validates that the candidate directory contains the Linux 'webots' binary
|
||||||
then resolves the 'webots' symlink to find the real installation directory.
|
|
||||||
Returns an empty string if Webots cannot be located.
|
|
||||||
|
|
||||||
Возвращает путь WEBOTS_HOME для локально установленного Webots.
|
Возвращает путь WEBOTS_HOME для локально установленного Linux Webots.
|
||||||
Сначала проверяет переменную окружения, затем стандартный путь deb-установки,
|
|
||||||
затем разворачивает симлинк 'webots' до реальной директории установки.
|
|
||||||
Возвращает пустую строку если Webots не найден.
|
|
||||||
"""
|
"""
|
||||||
|
def _is_linux_webots(home: str) -> bool:
|
||||||
|
# Accept only directories that have the Linux 'webots' binary directly inside.
|
||||||
|
# Принимаем только директории с Linux-бинарником 'webots' напрямую внутри.
|
||||||
|
return (Path(home) / "webots").is_file()
|
||||||
|
|
||||||
if "WEBOTS_HOME" in os.environ:
|
if "WEBOTS_HOME" in os.environ:
|
||||||
return os.environ["WEBOTS_HOME"]
|
home = os.environ["WEBOTS_HOME"]
|
||||||
if _WEBOTS_DEFAULT_HOME.is_dir():
|
if _is_linux_webots(home):
|
||||||
|
return home
|
||||||
|
return ""
|
||||||
|
if _WEBOTS_DEFAULT_HOME.is_dir() and _is_linux_webots(str(_WEBOTS_DEFAULT_HOME)):
|
||||||
return str(_WEBOTS_DEFAULT_HOME)
|
return str(_WEBOTS_DEFAULT_HOME)
|
||||||
webots_bin = shutil.which("webots")
|
webots_bin = shutil.which("webots")
|
||||||
if webots_bin:
|
if webots_bin:
|
||||||
return str(Path(webots_bin).resolve().parent)
|
home = str(Path(webots_bin).resolve().parent)
|
||||||
|
if _is_linux_webots(home):
|
||||||
|
return home
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ export DEBIAN_FRONTEND=noninteractive
|
|||||||
|
|
||||||
PROGRESS() { echo "PROGRESS:$1:$2"; }
|
PROGRESS() { echo "PROGRESS:$1:$2"; }
|
||||||
|
|
||||||
|
# Keep sudo credentials alive throughout the installation so the build step that
|
||||||
|
# follows (rosdep/colcon) does not trigger a password prompt inside the TUI.
|
||||||
|
# Обновляем sudo-токен в фоне чтобы он не истёк за время установки и не запросил
|
||||||
|
# пароль повторно во время rosdep/colcon внутри TUI.
|
||||||
|
sudo -v
|
||||||
|
( while true; do sudo -v; sleep 240; done ) &
|
||||||
|
_SUDO_KEEPALIVE_PID=$!
|
||||||
|
trap 'kill "$_SUDO_KEEPALIVE_PID" 2>/dev/null || true' EXIT
|
||||||
|
|
||||||
PROGRESS 0 "Checking dpkg state..."
|
PROGRESS 0 "Checking dpkg state..."
|
||||||
echo "Checking dpkg state..."
|
echo "Checking dpkg state..."
|
||||||
sudo dpkg --configure -a
|
sudo dpkg --configure -a
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ export DEBIAN_FRONTEND=noninteractive
|
|||||||
|
|
||||||
PROGRESS() { echo "PROGRESS:$1:$2"; }
|
PROGRESS() { echo "PROGRESS:$1:$2"; }
|
||||||
|
|
||||||
|
# Keep sudo credentials alive throughout the installation so the build step that
|
||||||
|
# follows (rosdep/colcon) does not trigger a password prompt inside the TUI.
|
||||||
|
# Обновляем sudo-токен в фоне чтобы он не истёк за время установки и не запросил
|
||||||
|
# пароль повторно во время rosdep/colcon внутри TUI.
|
||||||
|
sudo -v
|
||||||
|
( while true; do sudo -v; sleep 240; done ) &
|
||||||
|
_SUDO_KEEPALIVE_PID=$!
|
||||||
|
trap 'kill "$_SUDO_KEEPALIVE_PID" 2>/dev/null || true' EXIT
|
||||||
|
|
||||||
PROGRESS 0 "Checking dpkg state..."
|
PROGRESS 0 "Checking dpkg state..."
|
||||||
echo "Checking dpkg state..."
|
echo "Checking dpkg state..."
|
||||||
sudo dpkg --configure -a
|
sudo dpkg --configure -a
|
||||||
|
|||||||
Reference in New Issue
Block a user