Skip to content

Commit f3d31f9

Browse files
committed
Run all hooks at the same time
There is a 60 second limit on hook time
1 parent ff5b1d1 commit f3d31f9

File tree

4 files changed

+74
-34
lines changed

4 files changed

+74
-34
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
# Log to both stderr and log file
5+
LOG_FILE="/tmp/reva-clone-ghidra.log"
6+
exec > >(tee -a "${LOG_FILE}") 2>&1
7+
8+
# Only run in remote (web) environments
9+
if [ "${CLAUDE_CODE_REMOTE}" != "true" ]; then
10+
echo "[Clone Ghidra Hook] Local environment detected. Skipping."
11+
exit 0
12+
fi
13+
14+
echo "[Clone Ghidra Hook] Cloning Ghidra source..."
15+
16+
GHIDRA_GIT=$(readlink -f "${CLAUDE_PROJECT_DIR}/../ghidra")
17+
18+
if [ ! -d "${GHIDRA_GIT}" ]; then
19+
git clone --depth 1 "https://github.com/NationalSecurityAgency/ghidra.git" "${GHIDRA_GIT}"
20+
echo "Cloned Ghidra to ${GHIDRA_GIT}"
21+
gradle -I gradle/support/fetchDependencies.gradle
22+
else
23+
echo "Ghidra source already exists at ${GHIDRA_GIT}"
24+
fi
25+
26+
echo "[Clone Ghidra Hook] Complete!"
Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,20 @@
22
set -ex
33

44
# Log to both stderr and log file
5-
LOG_FILE="/tmp/reva-claude-startup-hook.log"
5+
LOG_FILE="/tmp/reva-install-ghidra.log"
66
exec > >(tee -a "${LOG_FILE}") 2>&1
77

88
# Only run in remote (web) environments
99
if [ "${CLAUDE_CODE_REMOTE}" != "true" ]; then
10-
echo "[SessionStart Hook] Local environment detected. Skipping remote setup."
10+
echo "[Install Ghidra Hook] Local environment detected. Skipping."
1111
exit 0
1212
fi
1313

14-
echo "[SessionStart Hook] Remote environment detected. Starting setup..."
15-
16-
echo "=== Setting up Claude Code Web Environment for ReVa ==="
17-
18-
GHIDRA_GIT=$(readlink -f "${CLAUDE_PROJECT_DIR}/../ghidra")
19-
20-
if [ ! -d "${GHIDRA_GIT}" ]; then
21-
git clone --depth 1 "https://github.com/NationalSecurityAgency/ghidra.git" "${GHIDRA_GIT}"
22-
echo "Cloned Ghidra to ${GHIDRA_GIT}"
23-
fi
14+
echo "[Install Ghidra Hook] Installing Ghidra binary..."
2415

2516
# Install Ghidra latest
2617
if [ ! -d "/opt/ghidra" ]; then
27-
echo "Installing Ghidra (latest)..."
18+
echo "Downloading Ghidra (latest)..."
2819

2920
# Get latest Ghidra release info using jq
3021
RELEASE_JSON=$(curl -s https://api.github.com/repos/NationalSecurityAgency/ghidra/releases/latest)
@@ -47,33 +38,22 @@ if [ ! -d "/opt/ghidra" ]; then
4738
GHIDRA_DIR=$(find /opt -maxdepth 1 -type d -name "ghidra_*_PUBLIC" | head -n 1)
4839
mv "$GHIDRA_DIR" /opt/ghidra
4940
rm /tmp/ghidra.zip
41+
42+
echo "Ghidra installed to /opt/ghidra"
43+
else
44+
echo "Ghidra binary already exists at /opt/ghidra"
5045
fi
5146

5247
export GHIDRA_INSTALL_DIR="/opt/ghidra"
5348

54-
# Verify installations
55-
echo "Verifying installations..."
56-
java -version
57-
gradle --version
58-
echo "GHIDRA_INSTALL_DIR=$GHIDRA_INSTALL_DIR"
59-
ls -la "$GHIDRA_INSTALL_DIR" | head -n 5
60-
6149
# Persist environment variables for all subsequent bash commands
6250
if [ -n "$CLAUDE_ENV_FILE" ]; then
6351
echo 'export GHIDRA_INSTALL_DIR="/opt/ghidra"' >> "$CLAUDE_ENV_FILE"
64-
echo 'export PATH="/opt/gradle/bin:$PATH"' >> "$CLAUDE_ENV_FILE"
6552
fi
6653

67-
# Pre-fetch Gradle dependencies
68-
pushd ${CLAUDE_PROJECT_DIR} > /dev/null
69-
echo "Pre-fetching Gradle dependencies..."
70-
gradle copyDependencies
71-
popd > /dev/null
54+
# Verify installation
55+
echo "Verifying Ghidra installation..."
56+
echo "GHIDRA_INSTALL_DIR=$GHIDRA_INSTALL_DIR"
57+
ls -la "$GHIDRA_INSTALL_DIR" | head -n 5
7258

73-
echo "=== Environment setup complete! ==="
74-
echo ""
75-
echo "Environment variables set:"
76-
echo " GHIDRA_INSTALL_DIR=/opt/ghidra"
77-
echo " ghidra cloned to ../ghidra"
78-
echo ""
79-
echo "Ready to build with: gradle buildExtension"
59+
echo "[Install Ghidra Hook] Complete!"

.claude/hooks/setup-gradle.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
# Log to both stderr and log file
5+
LOG_FILE="/tmp/reva-setup-gradle.log"
6+
exec > >(tee -a "${LOG_FILE}") 2>&1
7+
8+
# Only run in remote (web) environments
9+
if [ "${CLAUDE_CODE_REMOTE}" != "true" ]; then
10+
echo "[Setup Gradle Hook] Local environment detected. Skipping."
11+
exit 0
12+
fi
13+
14+
echo "[Setup Gradle Hook] Pre-fetching Gradle dependencies..."
15+
16+
# Verify Java and Gradle
17+
java -version
18+
gradle --version
19+
20+
# Pre-fetch Gradle dependencies
21+
pushd "${CLAUDE_PROJECT_DIR}" > /dev/null
22+
echo "Fetching dependencies..."
23+
gradle copyDependencies
24+
popd > /dev/null
25+
26+
echo "[Setup Gradle Hook] Complete!"

.claude/settings.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
"hooks": [
1515
{
1616
"type": "command",
17-
"command": "${CLAUDE_PROJECT_DIR}/.claude/setup-environment.sh"
17+
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/clone-ghidra-source.sh"
18+
},
19+
{
20+
"type": "command",
21+
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/install-ghidra-binary.sh"
22+
},
23+
{
24+
"type": "command",
25+
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/setup-gradle.sh"
1826
}
1927
]
2028
}

0 commit comments

Comments
 (0)