Skip to content

Commit 0d8a1dc

Browse files
Adding proper Copyright headers
1 parent e68332c commit 0d8a1dc

1 file changed

Lines changed: 241 additions & 0 deletions

File tree

support/openclaw_detection copy.sh

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#!/bin/bash
2+
####################################################################################################
3+
# Jamf Source Available License
4+
# Copyright 2025, Jamf Software LLC.
5+
# Persons receiving this software are permitted to use, adapt, and share it for
6+
# purposes associated with the function of their licensed Jamf products so long
7+
# as the Jamf copyright and these terms are included in any copies or derivitive
8+
# works.
9+
#
10+
# THIS SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL JAMF
13+
# SOFTWARE, LLC OR ANY OF ITS AFFILIATES BE LIABLE FOR ANY CLAIM, DAMAGES OR
14+
# OTHER LIABILITY, WHETHER IN CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF
15+
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER DEALINGS IN THE
16+
# SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17+
# CONSEQUENTIAL OR PUNITIVE DAMAGES AND OTHER DAMAGES SUCH AS LOSS OF USE,
18+
# PROFITS, SAVINGS, TIME OR DATA, BUSINESS INTERRUPTION, OR PROCUREMENT OF
19+
# SUBSTITUTE GOODS OR SERVICES.
20+
#
21+
####################################################################################################
22+
23+
################################################################################
24+
# Detects OpenClaw installations including:
25+
# - CLI binary (npm/pnpm global install)
26+
# - LaunchAgent services (current and legacy)
27+
# - macOS companion app
28+
# - Configuration directories
29+
# - Running processes/gateway
30+
# - Docker containers
31+
################################################################################
32+
33+
# Initialize detection arrays
34+
declare -a findings
35+
36+
# Function to check if a command exists
37+
command_exists() {
38+
command -v "$1" >/dev/null 2>&1
39+
}
40+
41+
# Function to check Docker containers
42+
check_docker() {
43+
if command_exists docker; then
44+
# Check for running OpenClaw containers
45+
if docker ps --format '{{.Names}}' 2>/dev/null | grep -qi openclaw; then
46+
container_names=$(docker ps --format '{{.Names}}' 2>/dev/null | grep -i openclaw | tr '\n' ', ' | sed 's/,$//')
47+
findings+=("Docker-Running:${container_names}")
48+
fi
49+
50+
# Check for stopped OpenClaw containers
51+
if docker ps -a --format '{{.Names}}' 2>/dev/null | grep -qi openclaw; then
52+
all_containers=$(docker ps -a --format '{{.Names}}' 2>/dev/null | grep -i openclaw | wc -l | tr -d ' ')
53+
if [[ $all_containers -gt 0 ]]; then
54+
findings+=("Docker-Containers:${all_containers}")
55+
fi
56+
fi
57+
fi
58+
}
59+
60+
# Function to check for CLI installation
61+
check_cli() {
62+
# Check common npm global bin locations
63+
local npm_prefix=""
64+
65+
if command_exists npm; then
66+
npm_prefix=$(npm prefix -g 2>/dev/null)
67+
if [[ -f "${npm_prefix}/bin/openclaw" ]]; then
68+
# Get version if possible
69+
local version=$("${npm_prefix}/bin/openclaw" --version 2>/dev/null | head -1)
70+
findings+=("CLI-NPM:${npm_prefix}/bin/openclaw")
71+
[[ -n "$version" ]] && findings+=("Version:${version}")
72+
fi
73+
fi
74+
75+
# Check standard locations
76+
if [[ -f "/usr/local/bin/openclaw" ]]; then
77+
findings+=("CLI-Binary:/usr/local/bin/openclaw")
78+
fi
79+
80+
# Check if openclaw command is available in PATH
81+
if command_exists openclaw && [[ ! " ${findings[@]} " =~ " CLI-" ]]; then
82+
local openclaw_path=$(which openclaw 2>/dev/null)
83+
findings+=("CLI-Path:${openclaw_path}")
84+
fi
85+
}
86+
87+
# Function to check macOS app
88+
check_macos_app() {
89+
if [[ -d "/Applications/OpenClaw.app" ]]; then
90+
# Get app version from Info.plist if available
91+
local app_version=""
92+
if [[ -f "/Applications/OpenClaw.app/Contents/Info.plist" ]]; then
93+
app_version=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "/Applications/OpenClaw.app/Contents/Info.plist" 2>/dev/null)
94+
fi
95+
findings+=("App:/Applications/OpenClaw.app")
96+
[[ -n "$app_version" ]] && findings+=("AppVersion:${app_version}")
97+
fi
98+
99+
# Check user Applications folders
100+
for user_home in /Users/*; do
101+
[[ ! -d "$user_home" ]] && continue
102+
[[ "$user_home" == "/Users/Shared" ]] && continue
103+
104+
if [[ -d "${user_home}/Applications/OpenClaw.app" ]]; then
105+
local username=$(basename "$user_home")
106+
findings+=("App-User:${username}")
107+
fi
108+
done
109+
}
110+
111+
# Function to check LaunchAgents
112+
check_launch_agents() {
113+
for user_home in /Users/*; do
114+
[[ ! -d "$user_home" ]] && continue
115+
[[ "$user_home" == "/Users/Shared" ]] && continue
116+
117+
local username=$(basename "$user_home")
118+
local launch_agents_dir="${user_home}/Library/LaunchAgents"
119+
120+
# Check current naming convention
121+
if [[ -f "${launch_agents_dir}/bot.molt.gateway.plist" ]]; then
122+
# Check if it's loaded
123+
local is_loaded=$(sudo -u "$username" launchctl list 2>/dev/null | grep -c "bot.molt.gateway")
124+
if [[ $is_loaded -gt 0 ]]; then
125+
findings+=("LaunchAgent-Active:${username}")
126+
else
127+
findings+=("LaunchAgent-Installed:${username}")
128+
fi
129+
fi
130+
131+
# Check legacy naming convention
132+
if [[ -f "${launch_agents_dir}/com.openclaw.gateway.plist" ]]; then
133+
findings+=("LaunchAgent-Legacy:${username}")
134+
fi
135+
136+
# Check for profile-based agents (bot.molt.*)
137+
local profile_agents=$(find "${launch_agents_dir}" -name "bot.molt.*.plist" 2>/dev/null | wc -l | tr -d ' ')
138+
if [[ $profile_agents -gt 0 ]]; then
139+
findings+=("LaunchAgent-Profiles:${username}:${profile_agents}")
140+
fi
141+
done
142+
}
143+
144+
# Function to check configuration directories
145+
check_config_dirs() {
146+
local found_configs=0
147+
148+
for user_home in /Users/*; do
149+
[[ ! -d "$user_home" ]] && continue
150+
[[ "$user_home" == "/Users/Shared" ]] && continue
151+
152+
local username=$(basename "$user_home")
153+
local config_dir="${user_home}/.openclaw"
154+
155+
if [[ -d "$config_dir" ]]; then
156+
found_configs=$((found_configs + 1))
157+
158+
# Check for main config file
159+
if [[ -f "${config_dir}/openclaw.json" ]]; then
160+
findings+=("Config:${username}")
161+
162+
# Check workspace
163+
if [[ -d "${config_dir}/workspace" ]]; then
164+
findings+=("Workspace:${username}")
165+
fi
166+
167+
# Check for credentials
168+
if [[ -f "${config_dir}/credentials/profiles.json" ]]; then
169+
findings+=("Credentials:${username}")
170+
fi
171+
fi
172+
fi
173+
174+
# Check for workspace directory (could be separate)
175+
if [[ -d "${user_home}/openclaw/workspace" ]]; then
176+
findings+=("Workspace-Alt:${username}")
177+
fi
178+
done
179+
180+
[[ $found_configs -gt 0 ]] && findings+=("ConfigDirs:${found_configs}")
181+
}
182+
183+
# Function to check running processes
184+
check_processes() {
185+
# Check for openclaw processes
186+
if pgrep -f "openclaw" >/dev/null 2>&1; then
187+
local process_count=$(pgrep -f "openclaw" | wc -l | tr -d ' ')
188+
findings+=("Process-Running:${process_count}")
189+
190+
# Check if Gateway is running on default port
191+
if lsof -i :18789 >/dev/null 2>&1; then
192+
findings+=("Gateway-Port:18789")
193+
fi
194+
fi
195+
196+
# Check for node processes that might be running openclaw
197+
if pgrep -f "node.*openclaw" >/dev/null 2>&1; then
198+
local node_count=$(pgrep -f "node.*openclaw" | wc -l | tr -d ' ')
199+
[[ $node_count -gt 0 ]] && findings+=("Node-Process:${node_count}")
200+
fi
201+
}
202+
203+
# Function to check for source installation
204+
check_source_install() {
205+
for user_home in /Users/*; do
206+
[[ ! -d "$user_home" ]] && continue
207+
[[ "$user_home" == "/Users/Shared" ]] && continue
208+
209+
local username=$(basename "$user_home")
210+
211+
# Check common locations for git clone
212+
for dir in "${user_home}/openclaw" "${user_home}/Documents/openclaw" "${user_home}/Projects/openclaw" "${user_home}/src/openclaw"; do
213+
if [[ -d "$dir" ]] && [[ -f "$dir/package.json" ]]; then
214+
# Verify it's actually openclaw by checking package.json
215+
if grep -q '"name": "openclaw"' "$dir/package.json" 2>/dev/null; then
216+
findings+=("Source:${username}:${dir}")
217+
fi
218+
fi
219+
done
220+
done
221+
}
222+
223+
# Run all checks
224+
check_docker
225+
check_cli
226+
check_macos_app
227+
check_launch_agents
228+
check_config_dirs
229+
check_processes
230+
check_source_install
231+
232+
# Format and return results
233+
if [[ ${#findings[@]} -eq 0 ]]; then
234+
echo "<result>Not Installed</result>"
235+
else
236+
# Join findings with semicolon separator
237+
result=$(IFS=';'; echo "${findings[*]}")
238+
echo "<result>${result}</result>"
239+
fi
240+
241+
exit 0

0 commit comments

Comments
 (0)