| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | # Replacing a running controller or proxy would break its verified identity. |
| 4 | # Do not stop another user's work from a privileged package script. |
| 5 | if [ "${1:-}" = upgrade ] || [ "${1:-}" = install ] || [ "${1:-}" = remove ]; then |
| 6 | for process in /proc/[0-9]*; do |
| 7 | executable=$(readlink "$process/exe" 2>/dev/null || true) |
| 8 | # Restricted /proc setups may hide another user's executable link from |
| 9 | # package scripts. Check the launch path too; never silently bypass a |
| 10 | # running packaged program just because readlink was denied. |
| 11 | if [ -z "$executable" ]; then |
| 12 | executable=$(tr '\000' '\n' < "$process/cmdline" 2>/dev/null | head -n 1) || executable= |
| 13 | fi |
| 14 | case "$executable" in |
| 15 | /usr/bin/claude-cage|/usr/bin/cage-desktop|/usr/lib/claude-cage/cage|/usr/lib/claude-cage/cage-desktop|/usr/lib/claude-cage/mihomo|/usr/lib/claude-cage/*' (deleted)') |
| 16 | echo 'Cage is running. Save work, stop the environment, and quit Cage before changing the installation.' >&2 |
| 17 | exit 1 |
| 18 | ;; |
| 19 | esac |
| 20 | done |
| 21 | fi |