Skip to content

Commit e9952e9

Browse files
Added linux setup script
1 parent 28dd0eb commit e9952e9

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

utils/setup.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GO_INSTALL_DIR="/usr/local"
5+
GO_PROFILE_SNIPPET='
6+
# >>> Go setup >>>
7+
export GOPATH="$HOME/go"
8+
export PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
9+
# <<< Go setup <<<
10+
'
11+
12+
detect_arch() {
13+
case "$(uname -m)" in
14+
x86_64) echo "amd64" ;;
15+
aarch64 | arm64) echo "arm64" ;;
16+
*) echo "unsupported"; exit 1 ;;
17+
esac
18+
}
19+
20+
install_go() {
21+
if command -v go >/dev/null 2>&1; then
22+
echo "[=] Go already installed: $(go version)"
23+
return
24+
fi
25+
26+
echo "[+] Installing latest Go..."
27+
28+
ARCH=$(detect_arch)
29+
GO_TARBALL=$(curl -s https://go.dev/VERSION?m=text | head -n 1)
30+
DOWNLOAD_URL="https://go.dev/dl/${GO_TARBALL}.linux-${ARCH}.tar.gz"
31+
32+
echo "[+] Downloading $DOWNLOAD_URL"
33+
curl -LO "$DOWNLOAD_URL"
34+
35+
echo "[+] Removing old Go (if any)"
36+
sudo rm -rf ${GO_INSTALL_DIR}/go
37+
38+
echo "[+] Extracting Go..."
39+
sudo tar -C ${GO_INSTALL_DIR} -xzf "${GO_TARBALL}.linux-${ARCH}.tar.gz"
40+
41+
rm -f "${GO_TARBALL}.linux-${ARCH}.tar.gz"
42+
43+
echo "[+] Configuring environment..."
44+
45+
for shellrc in "$HOME/.bashrc" "$HOME/.zshrc"; do
46+
[ -f "$shellrc" ] || touch "$shellrc"
47+
if ! grep -q "Go setup" "$shellrc"; then
48+
echo "$GO_PROFILE_SNIPPET" >> "$shellrc"
49+
echo "[+] Updated $shellrc"
50+
else
51+
echo "[=] Go config already exists in $shellrc"
52+
fi
53+
done
54+
55+
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
56+
57+
echo "[+] Go installed successfully: $(go version)"
58+
}
59+
60+
install_pdtm() {
61+
if command -v pdtm >/dev/null 2>&1; then
62+
echo "[=] PDTM already installed"
63+
return
64+
fi
65+
66+
echo "[+] Installing PDTM..."
67+
go install github.com/projectdiscovery/pdtm/cmd/pdtm@latest
68+
69+
export PATH=$PATH:$HOME/go/bin
70+
71+
echo "[+] Verifying PDTM..."
72+
if command -v pdtm >/dev/null 2>&1; then
73+
echo "[+] PDTM installed successfully"
74+
else
75+
echo "[-] PDTM installation failed"
76+
exit 1
77+
fi
78+
}
79+
80+
post_install() {
81+
echo "[+] Installing core ProjectDiscovery tools (optional but recommended)..."
82+
pdtm -install-all || true
83+
}
84+
85+
main() {
86+
install_go
87+
install_pdtm
88+
post_install
89+
90+
echo ""
91+
echo "[✓] Setup complete"
92+
echo "Reload your shell:"
93+
echo " source ~/.bashrc OR source ~/.zshrc"
94+
}
95+
96+
main

0 commit comments

Comments
 (0)