-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·109 lines (86 loc) · 2.46 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
106
107
108
109
#!/bin/bash
set -e
RELEASE="latest"
OS="$(uname -s)"
if [ -d "$HOME/.bwenv" ]; then
INSTALL_DIR="$HOME/.bwenv"
elif [ -n "$XDG_DATA_HOME" ]; then
INSTALL_DIR="$XDG_DATA_HOME/bwenv"
elif [ "$OS" = "Darwin" ]; then
INSTALL_DIR="$HOME/Library/Application Support/bwenv"
else
INSTALL_DIR="$HOME/.local/share/bwenv"
fi
FILENAME=bwenv-x86_64-unknown-linux-musl
download_bwenv() {
URL="https://github.com/titanom/bwenv/releases/latest/download/$FILENAME.zip"
DOWNLOAD_DIR=$(mktemp -d)
echo "Downloading $URL..."
mkdir -p "$INSTALL_DIR" &>/dev/null
if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then
echo "Download failed. Check that the release/filename are correct."
exit 1
fi
unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"
if [ -f "$DOWNLOAD_DIR/bwenv" ]; then
mv "$DOWNLOAD_DIR/bwenv" "$INSTALL_DIR/bwenv"
else
mv "$DOWNLOAD_DIR/$FILENAME/bwenv" "$INSTALL_DIR/bwenv"
fi
chmod u+x "$INSTALL_DIR/bwenv"
}
check_dependencies() {
echo "Checking dependencies for the installation script..."
echo -n "Checking availability of curl... "
if hash curl 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
echo -n "Checking availability of unzip... "
if hash unzip 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
if [ "$SHOULD_EXIT" = "true" ]; then
echo "Not installing bwenv due to missing dependencies."
exit 1
fi
}
ensure_containing_dir_exists() {
local CONTAINING_DIR
CONTAINING_DIR="$(dirname "$1")"
if [ ! -d "$CONTAINING_DIR" ]; then
echo " >> Creating directory $CONTAINING_DIR"
mkdir -p "$CONTAINING_DIR"
fi
}
setup_shell() {
CURRENT_SHELL="$(basename "$SHELL")"
if [ "$CURRENT_SHELL" = "bash" ]; then
CONF_FILE=$HOME/.bashrc
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Bash. Appending the following to $CONF_FILE:"
echo ""
echo ' # bwenv'
echo ' export PATH="'"$INSTALL_DIR"':$PATH"'
echo '' >>$CONF_FILE
echo '# bwenv' >>$CONF_FILE
echo 'export PATH="'"$INSTALL_DIR"':$PATH"' >>$CONF_FILE
else
echo "Could not infer shell type. Please set up manually."
exit 1
fi
echo ""
echo "In order to apply the changes, open a new terminal or run the following command:"
echo ""
echo " source $CONF_FILE"
}
check_dependencies
download_bwenv
if [ "$SKIP_SHELL" != "true" ]; then
setup_shell
fi