1+ #! /bin/bash
2+
3+ set -e
4+
5+ RED=' \033[0;31m'
6+ GREEN=' \033[0;32m'
7+ YELLOW=' \033[1;33m'
8+ BLUE=' \033[0;34m'
9+ NC=' \033[0m' # No Color
10+
11+ info () {
12+ echo -e " ${BLUE} [INFO]${NC} $1 " >&2
13+ }
14+
15+ success () {
16+ echo -e " ${GREEN} [SUCCESS]${NC} $1 " >&2
17+ }
18+
19+ warning () {
20+ echo -e " ${YELLOW} [WARNING]${NC} $1 " >&2
21+ }
22+
23+ error () {
24+ echo -e " ${RED} [ERROR]${NC} $1 " >&2
25+ exit 1
26+ }
27+
28+ detect_platform () {
29+ local os=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
30+ local arch=$( uname -m)
31+
32+ case $os in
33+ linux)
34+ OS=" linux"
35+ ;;
36+ darwin)
37+ OS=" darwin"
38+ ;;
39+ * )
40+ error " Unsupported operating system: $os "
41+ ;;
42+ esac
43+
44+ case $arch in
45+ x86_64|amd64)
46+ ARCH=" amd64"
47+ ;;
48+ arm64|aarch64)
49+ ARCH=" arm64"
50+ ;;
51+ * )
52+ error " Unsupported architecture: $arch "
53+ ;;
54+ esac
55+
56+ info " Detected platform: $OS -$ARCH "
57+ }
58+
59+ get_latest_release () {
60+ info " Getting latest release information..."
61+
62+ if command -v curl > /dev/null 2>&1 ; then
63+ LATEST_RELEASE=$( curl -s https://api.github.com/repos/yplog/memotty/releases/latest | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
64+ elif command -v wget > /dev/null 2>&1 ; then
65+ LATEST_RELEASE=$( wget -qO- https://api.github.com/repos/yplog/memotty/releases/latest | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
66+ else
67+ error " curl or wget is required"
68+ fi
69+
70+ if [ -z " $LATEST_RELEASE " ]; then
71+ error " Could not fetch latest release information"
72+ fi
73+
74+ info " Latest release: $LATEST_RELEASE "
75+ }
76+
77+ download_binary () {
78+ local binary_name=" memotty-${OS} -${ARCH} "
79+ local download_url=" https://github.com/yplog/memotty/releases/download/${LATEST_RELEASE} /${binary_name} "
80+ local temp_file=" /tmp/memotty"
81+
82+ info " Downloading from: $download_url "
83+
84+ if command -v curl > /dev/null 2>&1 ; then
85+ curl -L -o " $temp_file " " $download_url " > /dev/null 2>&1 || error " Download failed"
86+ elif command -v wget > /dev/null 2>&1 ; then
87+ wget -O " $temp_file " " $download_url " > /dev/null 2>&1 || error " Download failed"
88+ else
89+ error " curl or wget is required"
90+ fi
91+
92+ if [ ! -f " $temp_file " ]; then
93+ error " Downloaded file not found"
94+ fi
95+
96+ success " Download completed"
97+
98+ echo " $temp_file "
99+ }
100+
101+ install_binary () {
102+ local temp_file=" $1 "
103+ local install_dir=" $HOME /.local/bin"
104+ local install_path=" $install_dir /memotty"
105+
106+ mkdir -p " $install_dir "
107+
108+ cp " $temp_file " " $install_path "
109+ chmod +x " $install_path "
110+
111+ rm -f " $temp_file "
112+
113+ success " Binary installed to: $install_path "
114+
115+ if [[ " :$PATH :" != * " :$install_dir :" * ]]; then
116+ warning " ⚠️ $install_dir is not in your PATH"
117+ info " Add this line to your ~/.bashrc or ~/.zshrc:"
118+ echo " " >&2
119+ echo " export PATH=\"\$ HOME/.local/bin:\$ PATH\" " >&2
120+ echo " " >&2
121+ fi
122+ }
123+
124+ main () {
125+ detect_platform
126+ get_latest_release
127+
128+ local temp_file=$( download_binary)
129+ install_binary " $temp_file "
130+
131+ echo " " >&2
132+ success " 🎉 Installation completed successfully!"
133+ info " More info: https://github.com/yplog/memotty"
134+ }
135+
136+ main " $@ "
0 commit comments