-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·142 lines (125 loc) · 4.48 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·142 lines (125 loc) · 4.48 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
#!/bin/bash
#
# RustHound install/uninstall helper.
#
# Builds the release binary from the committed lockfile, installs it to ~/.local/bin, and
# installs the bundled default rules file into the same configuration directory the
# application itself resolves.
set -euo pipefail
INSTALL_DIR="$HOME/.local/bin"
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# This must match main.rs, which resolves the directory with dirs::config_dir(): that is
# ~/Library/Application Support on macOS and $XDG_CONFIG_HOME (default ~/.config) elsewhere.
# Using ~/.config on macOS would install a rules file the application never looks at.
config_dir() {
if [ "$(uname -s)" = "Darwin" ]; then
printf '%s' "$HOME/Library/Application Support/rusthound"
else
printf '%s' "${XDG_CONFIG_HOME:-$HOME/.config}/rusthound"
fi
}
CONFIG_DIR="$(config_dir)"
RULES_FILE="$CONFIG_DIR/rules.toml"
install_rusthound() {
echo "Starting RustHound installation..."
if ! command -v cargo >/dev/null 2>&1; then
echo "Rust was not found. Install it from https://rustup.rs/ and try again." >&2
exit 1
fi
echo "Rust detected. Building the project..."
cd "$REPO_ROOT"
if ! cargo build --locked --release; then
echo "Build failed. Fix the errors above and try again." >&2
exit 1
fi
echo "Build finished. Installing the executable..."
mkdir -p "$INSTALL_DIR"
if ! cp target/release/rusthound "$INSTALL_DIR/"; then
echo "Could not copy the executable. Check permissions on $INSTALL_DIR." >&2
exit 1
fi
echo "Installed executable: $INSTALL_DIR/rusthound"
mkdir -p "$CONFIG_DIR"
if [ -f "$RULES_FILE" ]; then
# Never overwrite rules the user has edited. Keep the bundled default beside them
# so the difference can be inspected.
echo "Keeping your existing rules: $RULES_FILE"
if cp rules.toml "$RULES_FILE.new"; then
echo "Wrote the bundled default to $RULES_FILE.new so you can diff the two."
else
echo "Could not write $RULES_FILE.new; your existing rules are untouched." >&2
exit 1
fi
else
if ! cp rules.toml "$RULES_FILE"; then
echo "Could not install the default rules to $RULES_FILE." >&2
exit 1
fi
echo "Installed default rules: $RULES_FILE"
fi
echo ""
echo "Next steps:"
echo "1. Edit $RULES_FILE to match your logs."
echo "2. Make sure $INSTALL_DIR is on your PATH. If it is not, add this line to ~/.bashrc or ~/.zshrc:"
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo " Then run 'source ~/.bashrc' or 'source ~/.zshrc'."
echo ""
echo "Usage: rusthound --file /path/to/your/logfile.log --rules \"$RULES_FILE\""
echo "Installation complete."
}
uninstall_rusthound() {
local purge_config="$1"
echo "Starting RustHound removal..."
if [ -f "$INSTALL_DIR/rusthound" ]; then
rm "$INSTALL_DIR/rusthound"
echo "Removed executable: $INSTALL_DIR/rusthound"
else
echo "Executable not found: $INSTALL_DIR/rusthound"
fi
if [ "$purge_config" = "yes" ]; then
if [ -d "$CONFIG_DIR" ]; then
rm -rf "$CONFIG_DIR"
echo "Removed configuration directory: $CONFIG_DIR"
else
echo "Configuration directory not found: $CONFIG_DIR"
fi
elif [ -d "$CONFIG_DIR" ]; then
echo "Kept your configuration: $CONFIG_DIR"
fi
echo ""
echo "Removal complete."
if [ "$purge_config" != "yes" ]; then
echo "Your rules were kept. To delete them too, choose the purge option."
fi
echo "Note: if you added $INSTALL_DIR to your PATH, remove that line from ~/.bashrc or ~/.zshrc manually."
}
echo "RustHound install/uninstall menu"
echo "--------------------------------"
echo "1. Install RustHound"
echo "2. Uninstall RustHound (keep configuration)"
echo "3. Uninstall RustHound and delete configuration"
echo "4. Exit"
echo "--------------------------------"
read -r -p "Choose an option (1-4): " choice
case "$choice" in
1)
install_rusthound
;;
2)
uninstall_rusthound no
;;
3)
read -r -p "Delete $CONFIG_DIR as well? This cannot be undone. (y/N): " confirm
case "$confirm" in
y|Y) uninstall_rusthound yes ;;
*) echo "Cancelled." ;;
esac
;;
4)
echo "Exiting."
;;
*)
echo "Invalid choice. Enter 1, 2, 3, or 4." >&2
exit 1
;;
esac