-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·121 lines (100 loc) · 2.71 KB
/
install.sh
File metadata and controls
executable file
·121 lines (100 loc) · 2.71 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
#!/usr/bin/env bash
set -euo pipefail
# passgen installer
# Usage: curl -fsSL https://raw.githubusercontent.com/flathead/passgen/master/install.sh | bash
REPO="https://github.com/flathead/passgen.git"
CLONE_DIR="${HOME}/.local/share/passgen"
BIN_DIR="${HOME}/.local/bin"
BIN_LINK="${BIN_DIR}/passgen"
CONFIG_DIR="${HOME}/.config/passgen"
# Colors
if [[ -t 1 ]]; then
RST=$'\033[0m'; BOLD=$'\033[1m'; DIM=$'\033[2m'
GREEN=$'\033[32m'; RED=$'\033[31m'; CYAN=$'\033[36m'
else
RST='' BOLD='' DIM='' GREEN='' RED='' CYAN=''
fi
info() { printf '%s[*]%s %s\n' "$CYAN" "$RST" "$1"; }
ok() { printf '%s[+]%s %s\n' "$GREEN" "$RST" "$1"; }
err() { printf '%s[-]%s %s\n' "$RED" "$RST" "$1" >&2; }
# --- checks ---
check_deps() {
local missing=()
for cmd in bash base64 sha256sum shuf tr git; do
if ! command -v "$cmd" &>/dev/null; then
missing+=("$cmd")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
err "Missing dependencies: ${missing[*]}"
err "Install them with your package manager and retry."
exit 1
fi
}
check_bash_version() {
local ver
ver="${BASH_VERSINFO[0]}"
if [[ "$ver" -lt 4 ]]; then
err "Bash 4+ required (found: ${BASH_VERSION})"
err "On macOS: brew install bash"
exit 1
fi
}
# --- install ---
do_install() {
info "passgen installer"
echo ""
check_bash_version
check_deps
mkdir -p "$BIN_DIR"
if [[ -d "$CLONE_DIR" ]]; then
info "Updating existing installation..."
git -C "$CLONE_DIR" pull --ff-only
else
info "Cloning passgen..."
git clone "$REPO" "$CLONE_DIR"
fi
chmod +x "${CLONE_DIR}/passgen"
# Create symlink
ln -sf "${CLONE_DIR}/passgen" "$BIN_LINK"
echo ""
ok "Installed: ${CLONE_DIR}/passgen"
ok "Symlink: ${BIN_LINK} -> ${CLONE_DIR}/passgen"
# Check PATH
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$BIN_DIR"; then
echo ""
info "Add ${BOLD}${BIN_DIR}${RST} to your PATH:"
echo ""
echo " ${DIM}# Add to ~/.bashrc or ~/.zshrc:${RST}"
echo " export PATH=\"\${HOME}/.local/bin:\${PATH}\""
echo ""
fi
echo ""
ok "Run ${BOLD}passgen${RST} to start"
info "Update anytime: ${DIM}passgen-update${RST} or ${DIM}cd ${CLONE_DIR} && git pull${RST}"
}
# --- uninstall ---
do_uninstall() {
info "Uninstalling passgen..."
if [[ -L "$BIN_LINK" ]]; then
rm -f "$BIN_LINK"
ok "Removed symlink ${BIN_LINK}"
elif [[ -f "$BIN_LINK" ]]; then
rm -f "$BIN_LINK"
ok "Removed ${BIN_LINK}"
fi
if [[ -d "$CLONE_DIR" ]]; then
rm -rf "$CLONE_DIR"
ok "Removed ${CLONE_DIR}"
fi
if [[ -d "$CONFIG_DIR" ]]; then
rm -rf "$CONFIG_DIR"
ok "Removed config ${CONFIG_DIR}"
fi
ok "Done"
}
# --- main ---
case "${1:-}" in
--uninstall) do_uninstall ;;
*) do_install ;;
esac