From 36ef79e70a5d24219276615a2d4b7a72472e3aa1 Mon Sep 17 00:00:00 2001 From: Nix Genco-Kamin Date: Sun, 23 Feb 2025 16:26:26 -0600 Subject: [PATCH 1/7] Remove cron --- setup.sh | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/setup.sh b/setup.sh index f205358..2fd240d 100755 --- a/setup.sh +++ b/setup.sh @@ -137,28 +137,6 @@ build_command() { fi } -# Function to create the cron job -create_cron_job() { - # Create a new script that checks if the process is running and if not, it starts it - echo '#!/bin/bash - - if ! pgrep -f "bbctl" > /dev/null - then - source ~/.bashrc - start-bb-server - fi' >~/check_and_run.sh - - # Make the script executable - chmod +x ~/check_and_run.sh - - # Open the crontab file and add the job - ( - crontab -l 2>/dev/null - echo "@reboot ~/check_and_run.sh - 0 * * * * ~/check_and_run.sh" - ) | crontab - -} - # Check if bbctl is installed cd echo 'Checking if bbctl is currently installed' @@ -305,7 +283,6 @@ n | N) esac build_command -create_cron_job install_xcode_tools check_macos_version From 4dd8d1fcb1cc15ced47680a9e4311cc601be08de Mon Sep 17 00:00:00 2001 From: Nix Genco-Kamin Date: Sun, 23 Feb 2025 16:41:28 -0600 Subject: [PATCH 2/7] Initial launchd setup --- setup.sh | 192 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 127 insertions(+), 65 deletions(-) diff --git a/setup.sh b/setup.sh index 2fd240d..1490bb4 100755 --- a/setup.sh +++ b/setup.sh @@ -24,7 +24,7 @@ check_macos_version() { echo "Checking macOS version" macos_version=$(sw_vers -productVersion) required_version="12.0.0" # Replace with the required version for Ventura - + if [[ $(printf '%s\n' "$required_version" "$macos_version" | sort -V | head -n1) != "$required_version" ]]; then echo "Your macOS version is $macos_version. BlueBubbles works best on macOS Ventura (version $required_version) and up. It is recommended to upgrade your macOS version." else @@ -61,7 +61,7 @@ download_bbctl() { echo "Making sure bbctl works" if ! command -v bbctl >/dev/null 2>&1; then echo "bbctl command not found! Please check the installation." - elif ! $(bbctl >/dev/null 2>&1); then + elif ! $(bbctl >/dev/null 2>&1); then echo "bbctl missing permissions! Attempting to grant now!" sudo chmod +x "${bbctl_path}" if ! $(bbctl >/dev/null 2>&1); then @@ -100,13 +100,13 @@ build_command() { echo read -r -p "Use default BlueBubbles URL '${DEFAULT_BB_URL}'? (correct option for most users) [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - read -p "Please enter your BlueBubbles URL: " bb_url + n | N) + echo + read -p "Please enter your BlueBubbles URL: " bb_url ;; - *) - echo "Using default URL" - bb_url=${DEFAULT_BB_URL} + *) + echo "Using default URL" + bb_url=${DEFAULT_BB_URL} ;; esac read -p "Please enter your BlueBubbles password: " bb_pass @@ -116,12 +116,12 @@ build_command() { echo "BlueBubbles Password: ${bb_pass}" read -r -p "Does that look correct? [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, let's try this again" - build_command + n | N) + echo + echo "Alright, let's try this again" + build_command ;; - *) echo "Great!" ;; + *) echo "Great!" ;; esac if "${use_tmux}"; then bb_command="tmux new-session -d -s bb-bridge bbctl run --param 'bluebubbles_url=${bb_url}' --param 'bluebubbles_password=${bb_pass}' --param 'imessage_platform=bluebubbles' sh-imessage && tmux ls | grep -i 'bb-bridge'" @@ -137,6 +137,52 @@ build_command() { fi } +# Function to create launchd agent +create_launchd_agent() { + echo "Generating laund plist" + cat > com.beeper.bridgemanager.imessage.plist << EOF + + + + + KeepAlive + + Crashed + + + Label + com.beeper.bridgemanager.imessage + ProgramArguments + + sh + -c + $bb_command + + RunAtLoad + + StandardErrorPath + /Users/Shared/errors.log + StandardOutPath + /Users/Shared/out.log + WorkingDirectory + /Users/Shared + EnvironmentVariables + + PATH + /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin + + + +EOF + echo "Moving launchd plist to local user LaunchAgent folder" + mv com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist + + echo "Starting launch agent" + launchctl load -w ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist + + echo "Bridge should be starting now. If you have any issues, logs can be found at /Users/Shared/out.log and /Users/Shared/errors.log" +} + # Check if bbctl is installed cd echo 'Checking if bbctl is currently installed' @@ -145,12 +191,12 @@ if ! [[ -z "${bbctl_name}" ]]; then echo 'bbctl found!' read -r -p "Re-install/update bbctl? (I honestly have no way to check if you're on latest) [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, no worries" - exit 0 + n | N) + echo + echo "Alright, no worries" + exit 0 ;; - *) echo "Proceeding" ;; + *) echo "Proceeding" ;; esac backup_bbctl logged_in="$(bbctl w 2>&1)" @@ -164,12 +210,12 @@ if ! [[ -z "${bbctl_name}" ]]; then if [[ "${running}" = *"RUNNING"* ]]; then read -r -p "The process must be killed to proceed. Can I do that for you? [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, exiting the script" - exit 0 + n | N) + echo + echo "Alright, exiting the script" + exit 0 ;; - *) echo "Finding bridge process" ;; + *) echo "Finding bridge process" ;; esac bridge_ps="$(pgrep 'bbctl')" echo "Shutting down bridge" @@ -183,19 +229,19 @@ if ! [[ -z "${bbctl_name}" ]]; then fi read -r -p "Some updates (such as the contact fix from 2/13/24) require creating a fresh bridge. Delete bridge now? [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, no worries" + n | N) + echo + echo "Alright, no worries" ;; - *) - echo "Alright, deleting bridge" - bbctl delete sh-imessage + *) + echo "Alright, deleting bridge" + bbctl delete sh-imessage ;; esac else echo "No existing iMessage bridge found" fi - + else echo "No login found! Please follow the next steps to log in" bbctl login @@ -205,13 +251,13 @@ if ! [[ -z "${bbctl_name}" ]]; then if ! [[ -z "${bridge_exists}" ]]; then read -r -p "Some updates (such as the contact fix from 2/13/24) require creating a fresh bridge. Delete bridge now? [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, no worries" + n | N) + echo + echo "Alright, no worries" ;; - *) - echo "Alright, deleting bridge" - bbctl delete sh-imessage + *) + echo "Alright, deleting bridge" + bbctl delete sh-imessage ;; esac else @@ -222,12 +268,12 @@ if ! [[ -z "${bbctl_name}" ]]; then else read -r -p "bbctl not found in path! Install now? [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, no worries" - exit 0 + n | N) + echo + echo "Alright, no worries" + exit 0 ;; - *) echo "Proceeding" ;; + *) echo "Proceeding" ;; esac download_bbctl logged_in="$(bbctl w 2>&1)" @@ -240,13 +286,13 @@ else if ! [[ -z "${bridge_exists}" ]]; then read -r -p "Some updates (such as the contact fix from 2/13/24) require creating a fresh bridge. Delete bridge now? [Y/n] " -n 1 case "$REPLY" in - n | N) - echo - echo "Alright, no worries" + n | N) + echo + echo "Alright, no worries" ;; - *) - echo "Alright, deleting bridge" - bbctl delete sh-imessage + *) + echo "Alright, deleting bridge" + bbctl delete sh-imessage ;; esac fi @@ -256,13 +302,13 @@ fi if command -v tmux >/dev/null 2>&1; then read -r -p "Would you like to use tmux to run the bridge? It's optional, but it lets you start the bridge without needing to keep the terminal window open, so it's handy [Y/n] " -n 1 case "$REPLY" in - n | N) - echo "Alright, no worries" - use_tmux=false + n | N) + echo "Alright, no worries" + use_tmux=false ;; - *) - echo "Okie dokie, using tmux" - use_tmux=true + *) + echo "Okie dokie, using tmux" + use_tmux=true ;; esac else @@ -271,14 +317,14 @@ fi read -r -p "Would you like to add an alias to your shell to be able to start the bridge by simply running \`start-bb-server\` instead of specifying parameters each time? [Y/n] " -n 1 case "$REPLY" in -n | N) - echo "Alright, sounds good!" - use_alias=false - echo "Time to create your run command" + n | N) + echo "Alright, sounds good!" + use_alias=false + echo "Time to create your run command" ;; -*) - echo "Okie dokie, setting that up now!" - use_alias=true + *) + echo "Okie dokie, setting that up now!" + use_alias=true ;; esac @@ -291,11 +337,27 @@ if "${use_alias}"; then echo "start-bb-server"; else echo "${bb_command}"; fi echo -read -r -p "Looks like we're done here! Would you like to start the bridge now? [Y/n] " -n 1 +read -r -p "Would you like to set up a launchd agent to start up the bridge automatically on login? [Y/n] " -n 1 case "$REPLY" in -n | N) echo "Alright, sounds good! Have a nice day, and feel free to reach out to @matchstick in the iMessage bridge matrix room if you have any issues :)" ;; -*) - echo "Alright, starting now! Have a nice day, and feel free to reach out to @matchstick in the iMessage bridge matrix room if you have any issues :)" - eval "${bb_command}" + n | N) + echo "Alright, sounds good!" + echo + read -r -p "Looks like we're done here! Would you like to start the bridge now? [Y/n] " -n 1 + case "$REPLY" in + n | N) echo "Alright, sounds good! Have a nice day, and feel free to reach out to @matchstick in the iMessage bridge matrix room if you have any issues :)" ;; + *) + echo "Alright, starting now! Have a nice day, and feel free to reach out to @matchstick in the iMessage bridge matrix room if you have any issues :)" + eval "${bb_command}" + ;; + esac + ;; + *) + echo "Okie dokie, setting that up now!" + create_launchd_agent + echo "Have a nice day, and feel free to reach out to @matchstick in the iMessage bridge matrix room if you have any issues :)" ;; esac + +echo + + From 2d829de2669206544fc9bfd1a17afaa1b25f1e88 Mon Sep 17 00:00:00 2001 From: Nix Genco-Kamin Date: Sun, 23 Feb 2025 16:43:29 -0600 Subject: [PATCH 3/7] Remove extra space --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 1490bb4..962b602 100755 --- a/setup.sh +++ b/setup.sh @@ -180,7 +180,7 @@ EOF echo "Starting launch agent" launchctl load -w ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist - echo "Bridge should be starting now. If you have any issues, logs can be found at /Users/Shared/out.log and /Users/Shared/errors.log" + echo "Bridge should be starting now. If you have any issues, logs can be found at /Users/Shared/out.log and /Users/Shared/errors.log" } # Check if bbctl is installed From c9032ba06267e7f28f0d06d310a2976fb191d573 Mon Sep 17 00:00:00 2001 From: Nix Genco-Kamin Date: Mon, 24 Feb 2025 09:34:03 -0600 Subject: [PATCH 4/7] add command to create user LaunchAgents folder if it doesn't exist, add template plist, replace placeholders in plist instead of attempting to write plist from text in script --- helpers/template.plist | 39 +++++++++++++++++++++++++++++++ setup.sh | 53 ++++++++++++++---------------------------- 2 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 helpers/template.plist diff --git a/helpers/template.plist b/helpers/template.plist new file mode 100644 index 0000000..344f08f --- /dev/null +++ b/helpers/template.plist @@ -0,0 +1,39 @@ + + + + + + Label + com._NAME_.bb-bridge + + + ProgramArguments + + /bin/bash + -c + _PLACEHOLDER_ + + + + RunAtLoad + + + + KeepAlive + + + + EnvironmentVariables + + PATH + /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin + + + + StandardOutPath + /tmp/bb-bridge.out + StandardErrorPath + /tmp/bb-bridge.err + + \ No newline at end of file diff --git a/setup.sh b/setup.sh index 962b602..85f72ff 100755 --- a/setup.sh +++ b/setup.sh @@ -140,47 +140,28 @@ build_command() { # Function to create launchd agent create_launchd_agent() { echo "Generating laund plist" - cat > com.beeper.bridgemanager.imessage.plist << EOF - - - - - KeepAlive - - Crashed - - - Label - com.beeper.bridgemanager.imessage - ProgramArguments - - sh - -c - $bb_command - - RunAtLoad - - StandardErrorPath - /Users/Shared/errors.log - StandardOutPath - /Users/Shared/out.log - WorkingDirectory - /Users/Shared - EnvironmentVariables - - PATH - /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin - - - -EOF + # Get path of helper script + current_dir=$(dirname "$(realpath $0)") + helper_dir="$current_dir/helpers" + + # Create new plist with command and name for process substituted + sed -e "s}_PLACEHOLDER_}$bb_command}g" -e "s}_NAME_}$(id -un)}g" $helper_dir/template.plist > $helper_dir/com.beeper.bridgemanager.imessage.plist + + # Create user LaunchAgents folder if it doesn't exist + if ! [ -d ~/Library/LaunchAgents ]; then + echo "Creating user LaunchAgents directory" + mkdir ~/Library/LaunchAgents + fi + + # Move created plist echo "Moving launchd plist to local user LaunchAgent folder" - mv com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist + mv $helper_dir/com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist + # Start created plist echo "Starting launch agent" launchctl load -w ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist - echo "Bridge should be starting now. If you have any issues, logs can be found at /Users/Shared/out.log and /Users/Shared/errors.log" + echo "Bridge should be starting now. If you have any issues, logs can be found at /tmp/bb-bridge.out and /tmp/bb-bridge.err" } # Check if bbctl is installed From 676d2e850598cf00e3885130fc95a78b6df62dbf Mon Sep 17 00:00:00 2001 From: Nix Genco-Kamin Date: Mon, 24 Feb 2025 09:38:12 -0600 Subject: [PATCH 5/7] Change mv command --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 85f72ff..8787dd0 100755 --- a/setup.sh +++ b/setup.sh @@ -155,7 +155,7 @@ create_launchd_agent() { # Move created plist echo "Moving launchd plist to local user LaunchAgent folder" - mv $helper_dir/com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents/com.beeper.bridgemanager.imessage.plist + mv $helper_dir/com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents # Start created plist echo "Starting launch agent" From f3e1e3cd3d4df52d2b9bc6e84d7511b2de2797f8 Mon Sep 17 00:00:00 2001 From: Nix Date: Mon, 24 Feb 2025 09:41:39 -0600 Subject: [PATCH 6/7] Remove fancy schmancy path handling, fix typo --- setup.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/setup.sh b/setup.sh index 8787dd0..0e9d3fd 100755 --- a/setup.sh +++ b/setup.sh @@ -139,13 +139,10 @@ build_command() { # Function to create launchd agent create_launchd_agent() { - echo "Generating laund plist" - # Get path of helper script - current_dir=$(dirname "$(realpath $0)") - helper_dir="$current_dir/helpers" - + # Create new plist with command and name for process substituted - sed -e "s}_PLACEHOLDER_}$bb_command}g" -e "s}_NAME_}$(id -un)}g" $helper_dir/template.plist > $helper_dir/com.beeper.bridgemanager.imessage.plist + echo "Generating launchd plist" + sed -e "s}_PLACEHOLDER_}$bb_command}g" -e "s}_NAME_}$(id -un)}g" helpers/template.plist > helpers/com.beeper.bridgemanager.imessage.plist # Create user LaunchAgents folder if it doesn't exist if ! [ -d ~/Library/LaunchAgents ]; then @@ -155,7 +152,7 @@ create_launchd_agent() { # Move created plist echo "Moving launchd plist to local user LaunchAgent folder" - mv $helper_dir/com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents + mv helpers/com.beeper.bridgemanager.imessage.plist ~/Library/LaunchAgents # Start created plist echo "Starting launch agent" From b986d24c21b995831da677f364e52122ac6da7a7 Mon Sep 17 00:00:00 2001 From: Nix Date: Mon, 24 Feb 2025 09:47:26 -0600 Subject: [PATCH 7/7] Remove uneccessary cd --- setup.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.sh b/setup.sh index 0e9d3fd..362651c 100755 --- a/setup.sh +++ b/setup.sh @@ -162,7 +162,6 @@ create_launchd_agent() { } # Check if bbctl is installed -cd echo 'Checking if bbctl is currently installed' bbctl_name="$(compgen -c | grep -i 'bbctl')" if ! [[ -z "${bbctl_name}" ]]; then