-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·109 lines (94 loc) · 3.17 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
GITHUB_USER="amir-s"
REPO_NAME="dev"
# Fetch the latest version tag from GitHub
echo -n "🔍 Fetching tha latest version"
VERSION=$(curl -s "https://api.github.com/repos/${GITHUB_USER}/${REPO_NAME}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "❌ Error: Unable to fetch the latest version information from GitHub."
exit 1
fi
echo -e "\r✅ Latest version available: $VERSION "
# Detect OS and architecture
echo -n "🔍 Detecting OS and architecture "
OS=""
ARCH=""
case "$(uname -s)" in
Linux*) OS="linux";;
Darwin*) OS="macos";;
*) echo "❌ Unsupported OS"; exit 1;;
esac
case "$(uname -m)" in
x86_64) ARCH="x86_64";;
arm64|aarch64) ARCH="arm64";;
*) echo "❌ Unsupported architecture"; exit 1;;
esac
SHELL_NAME=$(basename "$SHELL")
PROFILE_FILE=""
case "$SHELL_NAME" in
bash)
PROFILE_FILE="$HOME/.bashrc"
;;
zsh)
PROFILE_FILE="$HOME/.zshrc"
;;
fish)
PROFILE_FILE="$HOME/.config/fish/config.fish"
;;
*)
echo "❌ Unsupported shell: $SHELL_NAME. Please add $INSTALL_PATH to your PATH manually."
exit 1
;;
esac
echo -e "\r✅ Detected $OS-$ARCH using $SHELL_NAME "
BINARY_NAME="dev-${OS}-${ARCH}"
DOWNLOAD_URL="https://github.com/${GITHUB_USER}/${REPO_NAME}/releases/download/${VERSION}/${BINARY_NAME}"
# Download the binary
echo -n "⬇️ Downloading ${BINARY_NAME} "
curl -sL -o "${BINARY_NAME}" "${DOWNLOAD_URL}"
if [ $? -ne 0 ]; then
echo "❌ Download failed!"
exit 1
fi
echo -e "\r✅ Downloaded ${BINARY_NAME} "
# Define the install path in ~/.local/bin
INSTALL_PATH="$HOME/.local/bin"
mkdir -p "${INSTALL_PATH}"
echo -n "🚚 Moving binaries to ${INSTALL_PATH}"
mv "${BINARY_NAME}" "${INSTALL_PATH}/dev-cli"
chmod +x "${INSTALL_PATH}/dev-cli"
echo -e "\r✅ Moving binaries to ${INSTALL_PATH}"
# Add ~/.local/bin to PATH if it's not already there
echo -n "🔧 Adding ${INSTALL_PATH} to PATH"
if ! grep -q "export PATH=\"$INSTALL_PATH:\$PATH\"" "$PROFILE_FILE"; then
case "$SHELL_NAME" in
bash | zsh)
echo "" >> "$PROFILE_FILE"
echo "export PATH=\"$INSTALL_PATH:\$PATH\"" >> "$PROFILE_FILE"
;;
fish)
echo "" >> "$PROFILE_FILE"
echo "set -gx PATH $INSTALL_PATH \$PATH" >> "$PROFILE_FILE"
;;
esac
fi
echo -e "\r✅ Added ${INSTALL_PATH} to PATH "
# add eval "$(dev-cli shell init zsh)" to the shell profile if it doesn't exist
echo -n "🔧 Adding init script to $SHELL_NAME"
if ! grep -q "eval \"\$(dev-cli shell init $SHELL_NAME)\"" "$PROFILE_FILE"; then
case "$SHELL_NAME" in
bash | zsh)
echo "" >> "$PROFILE_FILE"
echo "eval \"\$(dev-cli shell init $SHELL_NAME)\"" >> "$PROFILE_FILE"
;;
fish)
echo "" >> "$PROFILE_FILE"
echo "eval (dev-cli shell init $SHELL_NAME)" >> "$PROFILE_FILE"
;;
esac
fi
echo -e "\r✅ Added init script to $SHELL_NAME "
echo -e "\n✅ DONE"
echo ""
echo "✅ Installation completed"
echo "🎉 Restart your shell to use dev"