-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
install.sh
120 lines (101 loc) · 4.21 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
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
# ZVM install script - v0.2.0 - ZVM: https://github.com/tristanisham/zvm
ARCH=$(uname -m)
OS=$(uname -s)
if [ $ARCH = "aarch64" ]; then
ARCH="arm64"
fi
if [ $ARCH = "x86_64" ]; then
ARCH="amd64"
fi
# echo "Installing zvm-$OS-$ARCH"
install_latest() {
echo -e "Downloading $1 in $(pwd)"
if [ "$(uname)" = "Darwin" ]; then
# Do something under MacOS platform
if command -v wget >/dev/null 2>&1; then
echo "wget is installed. Using wget..."
wget -q --show-progress --max-redirect 5 -O zvm.tar "https://github.com/tristanisham/zvm/releases/latest/download/$1"
else
echo "wget is not installed. Using curl..."
curl -L --max-redirs 5 "https://github.com/tristanisham/zvm/releases/latest/download/$1" -o zvm.tar
fi
mkdir -p $HOME/.zvm/self
tar -xf zvm.tar -C $HOME/.zvm/self
rm "zvm.tar"
elif [ $OS = "Linux" ]; then
# Do something under GNU/Linux platform
if command -v wget2 >/dev/null 2>&1; then
echo "wget2 is installed. Using wget2..."
wget2 -q --force-progress --max-redirect 5 -O zvm.tar "https://github.com/tristanisham/zvm/releases/latest/download/$1"
elif command -v wget >/dev/null 2>&1; then
echo "wget is installed. Using wget..."
wget -q --show-progress --max-redirect 5 -O zvm.tar "https://github.com/tristanisham/zvm/releases/latest/download/$1"
else
echo "wget is not installed. Using curl..."
curl -L --max-redirs 5 "https://github.com/tristanisham/zvm/releases/latest/download/$1" -o zvm.tar
fi
mkdir -p $HOME/.zvm/self
tar -xf zvm.tar -C $HOME/.zvm/self
rm "zvm.tar"
elif [ $OS = "MINGW32_NT" ] || [ $OS == "MINGW64_NT" ]; then
curl -L --max-redirs 5 "https://github.com/tristanisham/zvm/releases/latest/download/$1" -o zvm.zip
# Additional extraction steps for Windows can be added here
fi
}
if [ "$(uname)" = "Darwin" ]; then
# Do something under Mac OS X platform
install_latest "zvm-darwin-$ARCH.tar"
elif [ $OS = "Linux" ]; then
# Do something under GNU/Linux platform
install_latest "zvm-linux-$ARCH.tar"
elif [ $OS = "MINGW32_NT" ] || [ $OS == "MINGW64_NT" ]; then
install_latest "zvm-windows-$ARCH.zip"
fi
# Determine the target file
if [ -f "$HOME/.profile" ]; then
TARGET_FILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
TARGET_FILE="$HOME/.bashrc"
else
TARGET_FILE=""
fi
if [ -n "$TARGET_FILE" ]; then
# Check if variables are already present
if grep -q 'ZVM_INSTALL' "$TARGET_FILE"; then
echo "ZVM environment variables are already present in $TARGET_FILE"
exit 0
fi
# Append the export statements to the TARGET_FILE
echo "Adding ZVM environment variables to $TARGET_FILE"
{
echo
echo "# ZVM"
echo 'export ZVM_INSTALL="$HOME/.zvm/self"'
echo 'export PATH="$PATH:$HOME/.zvm/bin"'
echo 'export PATH="$PATH:$ZVM_INSTALL/"'
} >> "$TARGET_FILE"
echo "Run 'source $TARGET_FILE' to start using ZVM in this shell!"
echo "Run 'zvm i master' to install Zig"
else
echo
echo "No ~/.profile or ~/.bashrc file found."
echo "Run the following commands to set up ZVM environment variables in this session or append them to your shell's startup script:"
echo
if [[ "$TERM" == "xterm"* || "$TERM" == "screen"* || "$TERM" == "tmux"* ]]; then
# Colors
RED='\033[0;31m' # For strings
GREEN='\033[0;32m' # For commands
BLUE='\033[0;34m' # For variables
NC='\033[0m' # No Color
echo -e "${GREEN}export${NC} ${BLUE}ZVM_INSTALL${NC}${GREEN}=${NC}${RED}\"\$HOME/.zvm/self\"${NC}"
echo -e "${GREEN}export${NC} ${BLUE}PATH${NC}${GREEN}=${NC}${RED}\"\$PATH:\$HOME/.zvm/bin\"${NC}"
echo -e "${GREEN}export${NC} ${BLUE}PATH${NC}${GREEN}=${NC}${RED}\"\$PATH:\$ZVM_INSTALL/\"${NC}"
echo -e "Run 'zvm i master' to install Zig"
else
echo 'export ZVM_INSTALL="$HOME/.zvm/self"'
echo 'export PATH="$PATH:$HOME/.zvm/bin"'
echo 'export PATH="$PATH:$ZVM_INSTALL/"'
echo "Run 'zvm i master' to install Zig"
fi
fi