-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathINSTALL
More file actions
executable file
·79 lines (63 loc) · 2.4 KB
/
Copy pathINSTALL
File metadata and controls
executable file
·79 lines (63 loc) · 2.4 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
#!/bin/bash
set -e
cd "$(dirname "$0")"
IS_INSTALLED_FILE="$HOME/.config/sshmgr/is_installed"
if [ -f "$IS_INSTALLED_FILE" ]; then
echo "sshmgr is already installed! Have fun!"
exit 0
fi
echo "checking dependencies..."
missing=""
for cmd in fzf jq; do
if ! command -v "$cmd" &>/dev/null; then
missing="$missing $cmd"
fi
done
if [ -n "$missing" ]; then
echo "missing required dependencies:$missing"
echo "install them first, e.g.:"
echo " macOS: brew install fzf jq fping"
echo " Debian/Ubuntu: sudo apt-get install fzf jq fping"
exit 1
fi
echo "required dependencies (fzf, jq) found."
if ! command -v fping &>/dev/null; then
echo "warning: fping is not installed - 'sshmgr -p' and the online status preview will not work."
fi
if [ -z "$EDITOR" ]; then
echo "warning: \$EDITOR is not set - 'sshmgr -e' needs it (e.g. export EDITOR=nano)."
fi
# creating config directory and empty hosts file
echo "creating config directory in $HOME/.config/sshmgr ..."
mkdir -p "$HOME/.config/sshmgr"
if [ ! -f "$HOME/.config/sshmgr/known_hosts.json" ]; then
echo "creating empty hosts file..."
printf '{\n "hosts": []\n}\n' >"$HOME/.config/sshmgr/known_hosts.json"
echo "this file can be edited later with sshmgr -e or sshmgr --edit"
fi
# installing sshmgr.sh to $HOME/.local/bin/sshmgr/
echo "installing sshmgr.sh to $HOME/.local/bin/sshmgr/ ..."
mkdir -p "$HOME/.local/bin/sshmgr"
cp "sshmgr.sh" "$HOME/.local/bin/sshmgr/"
# the manual page, into the user local man directory
echo "installing the manual page ..."
mkdir -p "$HOME/.local/share/man/man1"
cp "sshmgr.1" "$HOME/.local/share/man/man1/"
# man only looks there when the path is exported
if ! grep -q 'MANPATH' "$HOME/.bashrc" 2>/dev/null; then
echo 'export MANPATH="$HOME/.local/share/man:${MANPATH:-}"' >>"$HOME/.bashrc"
echo "added MANPATH to .bashrc, so 'man sshmgr' finds it"
else
echo "MANPATH already set in .bashrc, make sure it includes \$HOME/.local/share/man"
fi
# adding alias to .bashrc in home directory
if ! grep -q 'alias sshmgr=' "$HOME/.bashrc" 2>/dev/null; then
echo "adding alias to .bashrc ..."
echo 'alias sshmgr="bash $HOME/.local/bin/sshmgr/sshmgr.sh"' >>"$HOME/.bashrc"
else
echo "alias already present in .bashrc, skipping."
fi
touch "$IS_INSTALLED_FILE"
echo "Installation complete!"
echo "You can now remove the cloned directory."
echo "note that you need to reopen the terminal (or run 'source ~/.bashrc') to apply"