-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·117 lines (98 loc) · 3.82 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
# !/bin/bash
# Configuration
INSTALL_DIR="/usr/local/bin"
RELEASE_URL="https://github.com/tasnimzotder/tchat/releases/latest/download"
ASSET_DARWIN_ARM64="tchat.darwin.arm64"
ASSET_LINUX_AMD64="tchat.linux.amd64"
ASSET_LINUX_ARM64="tchat.linux.arm64"
# Output with colors
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
# Functions
print_message() {
echo -e "${BLUE}tChat >> ${GREEN}$1${NC}"
}
error_exit() {
echo -e "${BLUE}tChat >> ${RED}$1${NC}" >&2
exit 1
}
determine_asset() {
OS="$(uname -s)"
ARCH="$(uname -m)"
if [ "$OS" = "Darwin" ]; then
# echo "$ASSET_DARWIN_ARM64"
case $ARCH in
arm64) echo "$ASSET_DARWIN_ARM64" ;;
*) error_exit "Unsupported architecture. Only arm64 is supported." ;;
esac
elif [ "$OS" = "Linux" ]; then
case $ARCH in
x86_64) echo "$ASSET_LINUX_AMD64" ;;
arm64) echo "$ASSET_LINUX_ARM64" ;;
aarch64) echo "$ASSET_LINUX_ARM64" ;;
*) error_exit "Unsupported architecture. Only amd64 and arm64 are supported." ;;
esac
else
error_exit "Unsupported OS. Only macOS and Linux are supported."
fi
}
dependency_check() {
# check if sudo user
if [ "$EUID" -ne 0 ]; then
error_exit "Please run as root."
fi
if ! command -v curl &>/dev/null; then
error_exit "curl is required to download tchat. Please install curl."
fi
}
download_and_install() {
asset=$(determine_asset)
print_message "Detected OS: $(uname -s), Arch: $(uname -m)"
print_message "Downloading and installing tchat..."
curl -L "$RELEASE_URL/$asset" -o "$INSTALL_DIR/tchat" || error_exit "Download failed."
chmod +x "$INSTALL_DIR/tchat" || error_exit "Could not make tchat executable."
}
sucess_installation() {
# tchat logo
echo -e "${GREEN}"
echo ""
echo ""
echo " ▄▄▄█████▓ ▄████▄ ██░ ██ ▄▄▄ ▄▄▄█████▓"
echo " ▓ ██▒ ▓▒▒██▀ ▀█ ▓██░ ██▒▒████▄ ▓ ██▒ ▓▒"
echo " ▒ ▓██░ ▒░▒▓█ ▄ ▒██▀▀██░▒██ ▀█▄ ▒ ▓██░ ▒░"
echo " ░ ▓██▓ ░ ▒▓▓▄ ▄██▒░▓█ ░██ ░██▄▄▄▄██░ ▓██▓ ░ "
echo " ▒██▒ ░ ▒ ▓███▀ ░░▓█▒░██▓ ▓█ ▓██▒ ▒██▒ ░ "
echo " ▒ ░░ ░ ░▒ ▒ ░ ▒ ░░▒░▒ ▒▒ ▓▒█░ ▒ ░░ "
echo " ░ ░ ▒ ▒ ░▒░ ░ ▒ ▒▒ ░ ░ "
echo " ░ ░ ░ ░░ ░ ░ ▒ ░ "
echo " ░ ░ ░ ░ ░ ░ ░ "
echo " ░ "
echo ""
echo ""
echo -e "${NC}"
print_message "tchat was installed successfully to $INSTALL_DIR/tchat with version $(tchat --version)."
print_message "Run 'tchat --help' to get started."
# shell check (bashrc, zshrc, etc.)
shell_type="$(basename $SHELL)"
if [ "$shell_type" = "bash" ]; then
shell_file=".bashrc"
elif [ "$shell_type" = "zsh" ]; then
shell_file=".zshrc"
else
shell_file=".bashrc"
fi
# alias check "tc"
if ! command -v tc &>/dev/null; then
print_message "To create an alias tc for tchat, run 'echo \"alias tc='tchat'\" >> ~/$shell_file'."
fi
if ! command -v tchat &>/dev/null; then
print_message "You may need to add $INSTALL_DIR to your PATH. Run 'echo \"export PATH=\$PATH:$INSTALL_DIR\" >> ~/$shell_file' to do so."
fi
print_message "Thanks for using tchat!"
}
# Main Script Logic
dependency_check &&
download_and_install &&
sucess_installation