#!/bin/zsh set -euo pipefail project_dir="${0:A:h}" app_dir="$HOME/Library/Application Support/RazerTilt/Razer Tilt Mapper.app" agent_file="$HOME/Library/LaunchAgents/local.razer-tilt.plist" service="gui/$(/usr/bin/id -u)/local.razer-tilt" if [[ ! -x "$project_dir/.build/Razer Tilt Mapper.app/Contents/MacOS/RazerTiltMapper" ]]; then /bin/zsh "$project_dir/build.sh" fi /usr/bin/codesign --verify --strict "$project_dir/.build/Razer Tilt Mapper.app" /bin/mkdir -p "${app_dir:h}" "${agent_file:h}" "$HOME/Library/Logs" if /bin/launchctl print "$service" >/dev/null 2>&1; then /bin/launchctl bootout "$service" fi /usr/bin/ditto "$project_dir/.build/Razer Tilt Mapper.app" "$app_dir" # Use plutil so spaces or XML characters in the home path are encoded safely. /usr/bin/plutil -create xml1 "$agent_file" /usr/bin/plutil -insert Label -string local.razer-tilt "$agent_file" /usr/bin/plutil -insert ProgramArguments -json '[]' "$agent_file" /usr/bin/plutil -insert ProgramArguments.0 -string "$app_dir/Contents/MacOS/RazerTiltMapper" "$agent_file" /usr/bin/plutil -insert RunAtLoad -bool true "$agent_file" /usr/bin/plutil -insert KeepAlive -bool true "$agent_file" /usr/bin/plutil -insert ThrottleInterval -integer 10 "$agent_file" /usr/bin/plutil -insert ProcessType -string Interactive "$agent_file" /usr/bin/plutil -insert StandardOutPath -string "$HOME/Library/Logs/RazerTiltMapper.log" "$agent_file" /usr/bin/plutil -insert StandardErrorPath -string "$HOME/Library/Logs/RazerTiltMapper.log" "$agent_file" /bin/chmod 644 "$agent_file" /usr/bin/plutil -lint "$agent_file" /bin/launchctl enable "$service" /bin/launchctl bootstrap "gui/$(/usr/bin/id -u)" "$agent_file" /bin/launchctl print "$service" print "Installed: $app_dir"