From 2ade315ddca7cb1eb64a2bcc44852cb8f38d7b8c Mon Sep 17 00:00:00 2001 From: Gu1llaum-3 Date: Thu, 4 Sep 2025 12:25:18 +0200 Subject: [PATCH] fix: resolve macOS permission errors during SSHM installation - Replace recursive find with direct file path check to avoid scanning protected directories - Backup old binary during installation to prevent interference from old version - Use full path for version verification to ensure new binary is tested - Fixes 'Operation not permitted' errors on macOS during installation process --- install/unix.sh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/install/unix.sh b/install/unix.sh index 56c2fbe..177028a 100644 --- a/install/unix.sh +++ b/install/unix.sh @@ -74,10 +74,10 @@ downloadBinary() { exit 1 fi - # Find the extracted binary - EXTRACTED_BINARY=$(find . -name "sshm-${OS}-${ARCH}" -type f) - if [ -z "$EXTRACTED_BINARY" ]; then - printf "${RED}Could not find extracted binary${NC}\n" + # Check if the expected binary exists (no find needed) + EXTRACTED_BINARY="./sshm-${OS}-${ARCH}" + if [ ! -f "$EXTRACTED_BINARY" ]; then + printf "${RED}Could not find extracted binary: $EXTRACTED_BINARY${NC}\n" exit 1 fi @@ -88,17 +88,37 @@ downloadBinary() { install() { printf "${YELLOW}Installing SSHM...${NC}\n" + # Backup old version if it exists to prevent interference during installation + OLD_BACKUP="" + if [ -f "$EXECUTABLE_PATH" ]; then + OLD_BACKUP="$EXECUTABLE_PATH.backup.$$" + runAsRoot mv "$EXECUTABLE_PATH" "$OLD_BACKUP" + fi + chmod +x "sshm-tmp" if [ $? -ne 0 ]; then printf "${RED}Failed to set permissions${NC}\n" + # Restore backup if installation fails + if [ -n "$OLD_BACKUP" ] && [ -f "$OLD_BACKUP" ]; then + runAsRoot mv "$OLD_BACKUP" "$EXECUTABLE_PATH" + fi exit 1 fi runAsRoot mv "sshm-tmp" "$EXECUTABLE_PATH" if [ $? -ne 0 ]; then printf "${RED}Failed to install binary${NC}\n" + # Restore backup if installation fails + if [ -n "$OLD_BACKUP" ] && [ -f "$OLD_BACKUP" ]; then + runAsRoot mv "$OLD_BACKUP" "$EXECUTABLE_PATH" + fi exit 1 fi + + # Clean up backup if installation succeeded + if [ -n "$OLD_BACKUP" ] && [ -f "$OLD_BACKUP" ]; then + runAsRoot rm -f "$OLD_BACKUP" + fi } cleanup() { @@ -161,7 +181,8 @@ main() { # Show version printf "${YELLOW}Verifying installation...${NC}\n" if command -v sshm >/dev/null 2>&1; then - sshm --version + # Use the full path to ensure we're using the newly installed version + "$EXECUTABLE_PATH" --version 2>/dev/null || echo "Version check failed, but installation completed" else printf "${RED}Warning: 'sshm' command not found in PATH. You may need to restart your terminal or add $INSTALL_DIR to your PATH.${NC}\n" fi