This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·105 lines (91 loc) · 2.38 KB
/
install.sh
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
#!/usr/bin/env bash
#
# Installer script for ego
#
# Downloads and links ego locally
# Run with:
# curl -sL https://raw.githubusercontent.com/mongodb-labs/ego/master/install.sh | bash
#
declare -r SCRIPT="ego"
declare -r REPO="mongodb-labs/ego"
{ # ensure the entire install script is downloaded
EGO_HOME="${HOME}/.${SCRIPT}"
# Ensure ego's work dirs are created
if [ ! -d "$EGO_HOME" ]; then
mkdir -p "${EGO_HOME}"
fi
if [ ! -d "$EGO_HOME/bin" ]; then
mkdir -p "${EGO_HOME}/bin"
fi
has_command() {
if ! command -v "$1" > /dev/null 2>&1
then return 1;
else return 0;
fi
}
download() {
echo "Downloading $*..."
if has_command curl; then
HTTPS_PROXY=${HTTPS_PROXY:-$https_proxy}
"$(command -v curl)" --silent --location --remote-name "$@"
elif has_command wget; then
https_proxy=${https_proxy:-$HTTPS_PROXY}
"$(command -v wget)" -q "$@"
else
echo "Could not find curl or wget on target host; cannot proceed!"
echo
exit 1
fi
}
link() {
# Add ego to the user's PATH
if [ ! -f "$1" ]; then
# Do nothing if the file does not exist
return
fi
if grep -qs "# EGO" "$1"; then
# Already linked, do nothing
return
fi
# Add ego to the user's shell PATH
(
echo ""
echo "# EGO"
echo "export PATH=\"$EGO_HOME/bin:\$PATH\""
) >> "$1"
echo "Added ${SCRIPT} to PATH via $1"
}
link_fish() {
if [ ! -f "$1" ]; then
# Do nothing if the file does not exist
return
fi
if grep -qs "# EGO" "$1"; then
# Already linked, do nothing
return
fi
# Add ego to fish's path
(
echo ""
echo "# EGO"
echo "fish_add_path $EGO_HOME/bin"
) >> "$1"
echo "Added ${SCRIPT} to PATH via $1"
}
echo "Installing ${SCRIPT}..."
echo
pushd "${EGO_HOME}/bin" > /dev/null || ( echo "Could not change dir to ${EGO_HOME}; exiting"; exit 1 )
download "https://raw.githubusercontent.com/${REPO}/master/bin/${SCRIPT}"
chmod u+x "${SCRIPT}"
popd > /dev/null || exit 2
echo "Linking ego in the system path..."
link "${HOME}/.zshrc"
link "${HOME}/.bashrc"
link "${HOME}/.profile"
link "${HOME}/.bash_profile"
link_fish "${HOME}/.config/fish/config.fish"
echo "Installation complete!"
echo
echo "Please report any issues at: https://github.com/${REPO}/issues"
echo
} # ensure the entire install script is downloaded