Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·475 lines (421 loc) · 15.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·475 lines (421 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/bin/bash
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Description:
# This script initializes the development environment for the Google Ads API Developer Assistant.
# It performs the following steps:
# 1. Verifies that required tools (jq, git) are installed.
# 2. Clones or updates the 'google-ads-python' repository into a specified directory.
# Exit on any error, and on undefined variables.
set -eu
# Function to print errors to stderr
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
# --- Project Directory Resolution ---
# Determine the root directory of the current git repository.
if ! PROJECT_DIR_ABS=$(git rev-parse --show-toplevel 2>/dev/null); then
err "ERROR: This script must be run from within the google-ads-api-developer-assistant git repository."
exit 1
fi
readonly PROJECT_DIR_ABS
echo "Detected project root: ${PROJECT_DIR_ABS}"
# --- Configuration ---
readonly PLUGIN_SOURCE_DIR="${PROJECT_DIR_ABS}/plugins/google-ads-api-developer-assistant"
readonly ALL_LANGS="python php ruby java dotnet"
# Helper functions for repo info (Replacing associative arrays for Bash 3.2 compatibility)
get_repo_url() {
case "$1" in
python) echo "https://github.com/googleads/google-ads-python.git" ;;
php) echo "https://github.com/googleads/google-ads-php.git" ;;
ruby) echo "https://github.com/googleads/google-ads-ruby.git" ;;
java) echo "https://github.com/googleads/google-ads-java.git" ;;
dotnet) echo "https://github.com/googleads/google-ads-dotnet.git" ;;
esac
}
get_repo_name() {
case "$1" in
python) echo "google-ads-python" ;;
php) echo "google-ads-php" ;;
ruby) echo "google-ads-ruby" ;;
java) echo "google-ads-java" ;;
dotnet) echo "google-ads-dotnet" ;;
esac
}
readonly PLUGIN_TARGET_DIR="${HOME}/.gemini/config/plugins/google-ads-api-developer-assistant"
# --- Defaults ---
TYPE=""
INSTALL_PYTHON=true
INSTALL_PHP=false
INSTALL_RUBY=false
INSTALL_JAVA=false
INSTALL_DOTNET=false
ANY_SELECTED=false
# --- Help Function ---
usage() {
echo "Usage: $0 <agy|claude> [OPTIONS]"
echo " $0 --type <agy|claude> [OPTIONS]"
echo " Installs the Google Ads API Developer Assistant as a plugin for Antigravity or Claude Code."
echo ""
echo " Required Argument:"
echo " <agy|claude> Target platform: 'agy' (Antigravity) or 'claude' (Claude Code)"
echo ""
echo " Options:"
echo " -h, --help Show this help message and exit"
echo " --type TYPE Target platform ('agy' or 'claude')"
echo " --agy Install for Antigravity (shorthand for --type agy)"
echo " --claude Install for Claude Code (shorthand for --type claude)"
echo " --all Include all client libraries (Python, PHP, Ruby, Java, .NET)"
echo " --php Include google-ads-php client library"
echo " --ruby Include google-ads-ruby client library"
echo " --java Include google-ads-java client library"
echo " --dotnet Include google-ads-dotnet client library"
echo ""
echo " By default, the Python client library is included in the plugin."
echo ""
echo " Examples:"
echo " $0 agy (Installs Antigravity plugin with Python client library)"
echo " $0 claude (Installs Claude Code plugin via claude CLI)"
echo " $0 agy --java (Installs Antigravity plugin with Java and Python client libraries)"
echo " $0 claude --php --dotnet (Installs Claude Code plugin with PHP, .NET, and Python client libraries)"
echo ""
}
# --- Argument Parsing ---
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
agy|claude|claudecode)
TYPE="$1"
if [[ "${TYPE}" == "claudecode" ]]; then
TYPE="claude"
fi
shift
;;
--type)
if [[ $# -lt 2 ]]; then
err "ERROR: --type requires an argument ('agy' or 'claude')."
usage
exit 1
fi
TYPE=$(echo "$2" | tr '[:upper:]' '[:lower:]')
if [[ "${TYPE}" == "claudecode" ]]; then
TYPE="claude"
fi
shift 2
;;
--type=*)
TYPE=$(echo "${1#*=}" | tr '[:upper:]' '[:lower:]')
if [[ "${TYPE}" == "claudecode" ]]; then
TYPE="claude"
fi
shift
;;
--agy)
TYPE="agy"
shift
;;
--claude|--claudecode)
TYPE="claude"
shift
;;
--all)
INSTALL_PHP=true
INSTALL_RUBY=true
INSTALL_JAVA=true
INSTALL_DOTNET=true
ANY_SELECTED=true
shift
;;
--php)
INSTALL_PHP=true
ANY_SELECTED=true
shift
;;
--ruby)
INSTALL_RUBY=true
ANY_SELECTED=true
shift
;;
--java)
INSTALL_JAVA=true
ANY_SELECTED=true
shift
;;
--dotnet)
INSTALL_DOTNET=true
ANY_SELECTED=true
shift
;;
*)
err "ERROR: Unknown argument: $1"
usage
exit 1
;;
esac
done
# --- Validate Required Type ---
if [[ -z "${TYPE}" ]]; then
err "ERROR: Missing required type argument: 'agy' or 'claude'."
usage
exit 1
fi
if [[ "${TYPE}" != "agy" && "${TYPE}" != "claude" ]]; then
err "ERROR: Invalid type '${TYPE}'. Must be 'agy' or 'claude'."
usage
exit 1
fi
# --- Environment Verification ---
check_python() {
local py_cmd=""
for cmd in python3 python; do
if command -v "${cmd}" &>/dev/null; then
if "${cmd}" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' &>/dev/null; then
py_cmd="${cmd}"
break
fi
fi
done
if [[ -n "${py_cmd}" ]]; then
local py_ver
py_ver=$("${py_cmd}" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")' 2>/dev/null || true)
echo "Found Python ${py_ver} (${py_cmd})"
return 0
fi
local found_ver=""
for cmd in python3 python; do
if command -v "${cmd}" &>/dev/null; then
found_ver=$("${cmd}" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")' 2>/dev/null || true)
if [[ -n "${found_ver}" ]]; then
found_ver="${cmd} (${found_ver})"
break
fi
fi
done
err "ERROR: Python 3.10 or higher is required."
if [[ -n "${found_ver}" ]]; then
err "Incompatible Python version detected: ${found_ver}."
else
err "No Python interpreter was found on PATH."
fi
err "Please install Python 3.10 or later and ensure it is available in your PATH."
err "See: https://www.python.org/downloads/"
return 1
}
check_antigravity() {
local found_antigravity=false
local antigravity_detail=""
if command -v agy &>/dev/null; then
found_antigravity=true
antigravity_detail="Antigravity CLI (agy) found at $(command -v agy)"
elif command -v antigravity &>/dev/null; then
found_antigravity=true
antigravity_detail="Antigravity CLI (antigravity) found at $(command -v antigravity)"
fi
if [[ "${found_antigravity}" == "false" ]]; then
if [[ -n "${ANTIGRAVITY_APP_DIR:-}" || -n "${ANTIGRAVITY_LS_ADDRESS:-}" || -n "${ANTIGRAVITY_PORT:-}" || -n "${JETSKI_HOME:-}" || -n "${GEMINI_HOME:-}" ]]; then
found_antigravity=true
antigravity_detail="Antigravity environment detected via environment variables"
elif [[ -d "${HOME}/.gemini" || -d "${HOME}/.antigravity" ]]; then
found_antigravity=true
antigravity_detail="Antigravity configuration/installation found in home directory (~/.gemini or ~/.antigravity)"
elif [[ -d "/Applications/Antigravity.app" || -d "${HOME}/Applications/Antigravity.app" || -d "/Applications/Google Antigravity.app" ]]; then
found_antigravity=true
antigravity_detail="Antigravity Desktop application found on macOS"
elif [[ -d "/opt/Antigravity" || -d "/usr/share/antigravity" || -d "/usr/local/share/antigravity" ]]; then
found_antigravity=true
antigravity_detail="Antigravity Desktop installation found on Linux"
fi
fi
if [[ "${found_antigravity}" == "true" ]]; then
echo "Found Antigravity: ${antigravity_detail}"
return 0
fi
err "ERROR: Antigravity CLI or Antigravity Desktop/Web is not installed."
err "The Google Ads API Developer Assistant requires an active Antigravity environment."
err "Please install Antigravity CLI ('agy' or 'antigravity') or Antigravity Desktop/Web to continue."
return 1
}
check_claudecode() {
local found_claude=false
local claude_detail=""
if command -v claude &>/dev/null; then
found_claude=true
claude_detail="Claude Code CLI (claude) found at $(command -v claude)"
fi
if [[ "${found_claude}" == "true" ]]; then
echo "Found Claude Code: ${claude_detail}"
return 0
fi
err "ERROR: Claude Code CLI ('claude') is not installed or not in PATH."
err "Please install Claude Code CLI to continue."
return 1
}
check_environment() {
echo "Checking environment for ${TYPE}..."
local env_ok=true
if ! check_python; then
env_ok=false
fi
if [[ "${TYPE}" == "agy" ]]; then
if ! check_antigravity; then
env_ok=false
fi
elif [[ "${TYPE}" == "claude" ]]; then
if ! check_claudecode; then
env_ok=false
fi
fi
if [[ "${env_ok}" != "true" ]]; then
err "ERROR: Environment check failed. Aborting installation."
exit 1
fi
echo "Environment check passed."
}
# Run environment verification before proceeding with installation
check_environment
# Helper to check if a language is enabled
is_enabled() {
case "$1" in
python) [[ "${INSTALL_PYTHON}" == "true" ]] ;;
php) [[ "${INSTALL_PHP}" == "true" ]] ;;
ruby) [[ "${INSTALL_RUBY}" == "true" ]] ;;
java) [[ "${INSTALL_JAVA}" == "true" ]] ;;
dotnet) [[ "${INSTALL_DOTNET}" == "true" ]] ;;
*) return 1 ;;
esac
}
# --- Clone/Update Repositories ---
clone_or_update() {
local repo_url="$1"
local clone_path="$2"
local log_file="$3"
local repo_name
repo_name=$(basename "${clone_path}")
{
echo "Managing repository ${repo_name} in ${clone_path}"
if [[ -d "${clone_path}/.git" ]]; then
echo "Directory ${clone_path} already exists. Updating..."
if ! (cd "${clone_path}" && git pull); then
echo "WARN: Failed to update ${repo_name}. Continuing..."
else
echo "Successfully updated ${repo_name}."
fi
elif [[ -d "${clone_path}" ]]; then
echo "WARN: Directory ${clone_path} exists but is not a git repo. Skipping."
else
echo "Cloning ${repo_url} into ${clone_path}"
if ! git clone "${repo_url}" "${clone_path}"; then
err "ERROR: Failed to clone ${repo_url}"
exit 1
fi
echo "Successfully cloned ${repo_name}."
fi
} > "${log_file}" 2>&1
}
# Helper to detect latest API version from client_libs and pre-seed config/api_version.txt
detect_and_seed_api_version() {
local search_dir="$1"
local target_config_dir="$2"
if [[ -d "${search_dir}" ]]; then
local latest_v=""
latest_v=$(find "${search_dir}" -mindepth 1 -maxdepth 1 -type d -name 'v*' 2>/dev/null | sed 's/.*\/v//' | grep -E '^[0-9]+$' | sort -n | tail -n 1)
if [[ -n "${latest_v}" ]]; then
mkdir -p "${target_config_dir}"
echo "v${latest_v}" > "${target_config_dir}/api_version.txt"
echo "Configured API version v${latest_v} in ${target_config_dir}/api_version.txt"
fi
fi
}
# --- Plugin Installation ---
if ! command -v git &> /dev/null; then
err "ERROR: git is not installed. Please install it to continue."
exit 1
fi
if [[ ! -d "${PLUGIN_SOURCE_DIR}" ]]; then
err "ERROR: Plugin directory '${PLUGIN_SOURCE_DIR}' does not exist."
exit 1
fi
TEMP_LOG_DIR=$(mktemp -d)
cleanup() {
rm -rf "${TEMP_LOG_DIR}"
}
trap cleanup EXIT
if [[ "${TYPE}" == "claude" ]]; then
echo "Preparing Claude Code plugin files at ${PLUGIN_SOURCE_DIR}..."
mkdir -p "${PLUGIN_SOURCE_DIR}/client_libs"
# Add all enabled client libraries (including Python by default) to plugin source structure
for lang in python php ruby java dotnet; do
if is_enabled "$lang"; then
repo_name=$(get_repo_name "$lang")
target_lib_path="${PLUGIN_SOURCE_DIR}/client_libs/${repo_name}"
url=$(get_repo_url "$lang")
log_file="${TEMP_LOG_DIR}/install_${lang}.log"
if [[ ! -d "${target_lib_path}" ]]; then
echo "Cloning ${repo_name} into plugin client_libs..."
clone_or_update "$url" "${target_lib_path}" "${log_file}"
if [[ -f "${log_file}" ]]; then
cat "${log_file}"
fi
fi
fi
done
# Pre-seed latest API version
detect_and_seed_api_version "${PLUGIN_SOURCE_DIR}/client_libs/google-ads-python/google/ads/googleads" "${PLUGIN_SOURCE_DIR}/config"
detect_and_seed_api_version "${PLUGIN_SOURCE_DIR}/client_libs/google-ads-python/google/ads/googleads" "${PROJECT_DIR_ABS}/config"
echo "Registering marketplace in Claude Code..."
claude plugin marketplace add ${PROJECT_DIR_ABS}
echo "Installing plugin in Claude Code..."
claude plugin install google-ads-api-developer-assistant@google-ads-assistant-local
echo "Plugin installation for claude complete."
echo ""
echo "In your Claude Code session, run /reload-plugins to activate the plugin."
exit 0
fi
# Antigravity installation
echo "Installing plugin for agy into: ${PLUGIN_TARGET_DIR}"
mkdir -p "$(dirname "${PLUGIN_TARGET_DIR}")"
rm -rf "${PLUGIN_TARGET_DIR}"
cp -r "${PLUGIN_SOURCE_DIR}" "${PLUGIN_TARGET_DIR}"
# Ensure plugin client_libs directory exists
mkdir -p "${PLUGIN_TARGET_DIR}/client_libs"
# Add all enabled client libraries (including Python by default) to plugin structure
for lang in python php ruby java dotnet; do
if is_enabled "$lang"; then
repo_name=$(get_repo_name "$lang")
target_lib_path="${PLUGIN_TARGET_DIR}/client_libs/${repo_name}"
source_lib_path="${PLUGIN_SOURCE_DIR}/client_libs/${repo_name}"
url=$(get_repo_url "$lang")
log_file="${TEMP_LOG_DIR}/install_${lang}.log"
if [[ -d "${source_lib_path}" ]]; then
echo "Adding ${repo_name} to plugin client_libs from local repository..."
rm -rf "${target_lib_path}"
cp -r "${source_lib_path}" "${target_lib_path}"
else
echo "Cloning ${repo_name} into plugin client_libs..."
clone_or_update "$url" "${target_lib_path}" "${log_file}"
if [[ -f "${log_file}" ]]; then
cat "${log_file}"
fi
fi
fi
done
# Pre-seed latest API version in plugin and project config
detect_and_seed_api_version "${PLUGIN_TARGET_DIR}/client_libs/google-ads-python/google/ads/googleads" "${PLUGIN_TARGET_DIR}/config"
detect_and_seed_api_version "${PLUGIN_TARGET_DIR}/client_libs/google-ads-python/google/ads/googleads" "${PROJECT_DIR_ABS}/config"
echo "Plugin installation for agy complete."
echo ""
echo "Restart your Antigravity / agy host to activate the plugin."