-
-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·216 lines (177 loc) Β· 6.68 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
Β·216 lines (177 loc) Β· 6.68 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
#!/usr/bin/env bash
# Β©AngelaMos | 2026
# install.sh
set -euo pipefail
REPO_OWNER="CarterPerez-dev"
REPO_NAME="portia"
BINARY="portia"
INSTALL_DIR="${PORTIA_INSTALL_DIR:-$HOME/.portia/bin}"
VERSION="${PORTIA_VERSION:-}"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
info() { echo -e " ${GREEN}+${NC} $1"; }
warn() { echo -e " ${YELLOW}!${NC} $1"; }
fail() { echo -e " ${RED}x${NC} $1"; exit 1; }
header() { echo -e "\n${BOLD}${CYAN}--- $1 ---${NC}\n"; }
TMP_DIR=""
cleanup() { [[ -n "$TMP_DIR" ]] && rm -rf "$TMP_DIR"; }
trap cleanup EXIT
# =========================================================================
# Banner
# =========================================================================
echo -e "${BOLD}"
echo -e " ${RED} βββ βββ βββ βββ β βββ ${NC}"
echo -e " ${CYAN} β βββ βββ β β βββ ${NC}"
echo -e "${NC}"
echo -e " ${DIM}Secrets scanner for codebases and git repositories${NC}"
# =========================================================================
# Detect System
# =========================================================================
header "Detecting system"
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
MINGW*|MSYS*|CYGWIN*) fail "Windows is not supported. Use: go install github.com/${REPO_OWNER}/${REPO_NAME}/cmd/portia@latest" ;;
*) fail "Unsupported OS: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) fail "Unsupported architecture: $ARCH" ;;
esac
info "System: ${OS}/${ARCH}"
# =========================================================================
# Resolve Version
# =========================================================================
if [[ -z "$VERSION" ]]; then
header "Fetching latest release"
if command -v curl &>/dev/null; then
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest" 2>/dev/null \
| grep '"tag_name":' \
| sed -E 's/.*"([^"]+)".*/\1/') || true
elif command -v wget &>/dev/null; then
VERSION=$(wget -qO- "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest" 2>/dev/null \
| grep '"tag_name":' \
| sed -E 's/.*"([^"]+)".*/\1/') || true
fi
fi
# =========================================================================
# Install: Pre-built Binary
# =========================================================================
INSTALLED=false
if [[ -n "$VERSION" ]]; then
info "Version: ${VERSION}"
header "Downloading pre-built binary"
ARCHIVE="${BINARY}_${VERSION#v}_${OS}_${ARCH}.tar.gz"
URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${VERSION}/${ARCHIVE}"
TMP_DIR=$(mktemp -d)
DOWNLOAD_OK=false
if command -v curl &>/dev/null; then
curl -fsSL "$URL" -o "$TMP_DIR/archive.tar.gz" 2>/dev/null && DOWNLOAD_OK=true
elif command -v wget &>/dev/null; then
wget -q "$URL" -O "$TMP_DIR/archive.tar.gz" 2>/dev/null && DOWNLOAD_OK=true
else
fail "Neither curl nor wget found"
fi
if [[ "$DOWNLOAD_OK" == "true" ]]; then
tar -xzf "$TMP_DIR/archive.tar.gz" -C "$TMP_DIR"
mkdir -p "$INSTALL_DIR"
mv "$TMP_DIR/$BINARY" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY"
INSTALLED=true
info "Installed to ${INSTALL_DIR}/${BINARY}"
else
warn "Pre-built binary not available for ${OS}/${ARCH}"
fi
fi
# =========================================================================
# Fallback: go install
# =========================================================================
if [[ "$INSTALLED" == "false" ]]; then
if command -v go &>/dev/null; then
GO_VER=$(go version | awk '{print $3}')
header "Building from source (${GO_VER})"
info "Running go install..."
GOBIN="$INSTALL_DIR" go install "github.com/${REPO_OWNER}/${REPO_NAME}/cmd/portia@latest"
INSTALLED=true
info "Installed to ${INSTALL_DIR}/${BINARY}"
else
echo ""
fail "No pre-built binary and Go is not installed.
Option 1 β Install Go, then:
go install github.com/${REPO_OWNER}/${REPO_NAME}/cmd/portia@latest
Option 2 β Install Go:
https://go.dev/dl/"
fi
fi
# =========================================================================
# PATH Setup
# =========================================================================
header "Configuring PATH"
PATH_UPDATED=false
case ":$PATH:" in
*":${INSTALL_DIR}:"*)
info "${INSTALL_DIR} already in PATH"
PATH_UPDATED=true
;;
esac
if [[ "$PATH_UPDATED" == "false" ]]; then
CURRENT_SHELL="$(basename "${SHELL:-/bin/bash}")"
TARGET=""
case "$CURRENT_SHELL" in
zsh)
[[ -f "$HOME/.zshrc" ]] && TARGET="$HOME/.zshrc"
;;
bash)
if [[ -f "$HOME/.bashrc" ]]; then
TARGET="$HOME/.bashrc"
elif [[ -f "$HOME/.bash_profile" ]]; then
TARGET="$HOME/.bash_profile"
fi
;;
fish)
mkdir -p "$HOME/.config/fish/conf.d"
echo "set -gx PATH \"$INSTALL_DIR\" \$PATH" > "$HOME/.config/fish/conf.d/portia.fish"
info "Added to ~/.config/fish/conf.d/portia.fish"
PATH_UPDATED=true
;;
esac
if [[ "$PATH_UPDATED" == "false" && -z "${TARGET:-}" ]]; then
[[ -f "$HOME/.profile" ]] && TARGET="$HOME/.profile"
fi
if [[ "$PATH_UPDATED" == "false" && -n "${TARGET:-}" ]]; then
if ! grep -q "$INSTALL_DIR" "$TARGET" 2>/dev/null; then
printf '\nexport PATH="%s:$PATH"\n' "$INSTALL_DIR" >> "$TARGET"
info "Added to ${TARGET}"
else
info "Already configured in ${TARGET}"
fi
fi
fi
# =========================================================================
# Done
# =========================================================================
echo ""
echo -e " ${GREEN}${BOLD}portia installed successfully${NC}"
echo ""
if ! command -v portia &>/dev/null; then
warn "Restart your shell or run:"
echo -e " ${BOLD}export PATH=\"${INSTALL_DIR}:\$PATH\"${NC}"
echo ""
fi
echo -e " ${DIM}Quick start:${NC}"
echo ""
echo -e " ${CYAN}portia scan [path]${NC} Scan a directory for secrets"
echo -e " ${CYAN}portia git [path]${NC} Scan git history for secrets"
echo -e " ${CYAN}portia init${NC} Create .portia.toml config"
echo -e " ${CYAN}portia config rules${NC} List all 150 detection rules"
echo ""
echo -e " ${DIM}Docs: https://github.com/${REPO_OWNER}/${REPO_NAME}${NC}"
echo ""