From dcd9cf520e60b54473cc713fba810fce6c6b48cf Mon Sep 17 00:00:00 2001 From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com> Date: Tue, 21 May 2024 23:46:19 +0200 Subject: [PATCH] Modified README and added warning in bridge.c --- README.md | 3 +- bridge.c | 2 +- macos.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 macos.sh diff --git a/README.md b/README.md index 7857044..62f01e6 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ Logs are stored in `C:\windows\logs\bridge.log`. ## macOS -On macOS, follow [these instructions](https://enderice2.github.io/rpc-bridge/installation.html#macos). +The steps to install are almost the same. The only difference is that if you want the service to work, you will have to use [this script](macos.sh) to install a launch agent that will symlink the `$TMPDIR` to a static path (`/tmp/rpc-bridge/tmpdir`). +To do so, download it, make it executable (`chmod +x macos.sh`) and run `./macos.sh install`. You can uninstall the agent by running `./macos.sh uninstall`. ## Compiling from source diff --git a/bridge.c b/bridge.c index cbcd818..07a5dbb 100644 --- a/bridge.c +++ b/bridge.c @@ -262,7 +262,7 @@ void ConnectToSocket(int fd) DWORD dwAttrib = GetFileAttributes(runtime); if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { - print("IPC directory does not exist: %s\n", runtime); + print("IPC directory does not exist: %s. If you're on MacOS, see the github guide on how to install the launchd service.\n", runtime); // Handle the case where the directory doesn't exist // For example, create the directory if (!RunningAsService) diff --git a/macos.sh b/macos.sh new file mode 100644 index 0000000..5748c9a --- /dev/null +++ b/macos.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Define target directory +TARGET_DIR=/tmp/rpc-bridge/tmpdir +P_DIR=$(dirname "$TARGET_DIR") +FILE_PATH=$P_DIR/link + +# Function to create the symlink and launch agent +function install_link() { + + if [ ! -d "$P_DIR" ]; then + mkdir -p "$P_DIR" + fi + + cat << EOF > "$FILE_PATH" +#!/bin/bash +TARGET_DIR=/tmp/rpc-bridge/tmpdir +if [ ! -d "\$TARGET_DIR" ]; then + mkdir -p "\$TARGET_DIR" +fi +rm -rf "\$TARGET_DIR" +ln -s "\$TMPDIR" "\$TARGET_DIR" +EOF + + chmod +x "$FILE_PATH" + + # Launch agent plist file path + PLIST_FILE=~/Library/LaunchAgents/com.rpc-bridge.tmp-symlink.plist + + # Create the launch agent plist with escaped variable + cat << EOF > "$PLIST_FILE" + + + + + Label + com.rpc-bridge.tmp-symlink + ProgramArguments + + $FILE_PATH + + RunAtLoad + + + +EOF + + # Load the launch agent + launchctl load "$PLIST_FILE" + echo "Symlink created and launch agent installed." +} + +# Function to remove the symlink and launch agent (unchanged) +function remove_link() { + # Remove the symlink + rm -rf "$TARGET_DIR" + + # Launch agent plist file path + PLIST_FILE=~/Library/LaunchAgents/com.rpc-bridge.tmp-symlink.plist + + # Unload the launch agent + launchctl unload "$PLIST_FILE" + + # Remove the files + rm -f "$PLIST_FILE" + rm -f "$FILE_PATH" + echo "Symlink removed and launch agent uninstalled." +} + +# Check for user input +if [ $# -eq 0 ]; then + echo "Usage: $0 (install|remove)" + exit 1 +fi + +# Action based on user input +case $1 in + install) + install_link + ;; + remove) + remove_link + ;; + *) + echo "Invalid argument. Please use 'install' or 'remove'." + exit 1 + ;; +esac \ No newline at end of file