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
This commit is contained in:
Gu1llaum-3 2025-09-04 12:25:18 +02:00
parent 2deec405f7
commit 2ade315ddc

View File

@ -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