Skip to content

Commit 0ad2828

Browse files
authored
Merge pull request #1 from yplog/feature/installer
Feature/installer
2 parents 1e3b3e8 + da5a0db commit 0ad2828

File tree

2 files changed

+167
-11
lines changed

2 files changed

+167
-11
lines changed

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,45 @@ Memotty is a modern, interactive terminal quiz application built with Go and Bub
1111

1212
## Quick Start
1313

14-
### Installation
14+
#### Option 1: One-line Install (Recommended)
15+
```bash
16+
# Latest release
17+
curl -fsSL https://raw.githubusercontent.com/yplog/memotty/main/scripts/install.sh | bash
18+
19+
# Or download and run manually
20+
curl -fsSL -o install.sh https://raw.githubusercontent.com/yplog/memotty/main/scripts/install.sh
21+
chmod +x install.sh
22+
./install.sh
23+
```
24+
25+
#### Option 2: Build from Source
1526
```bash
1627
git clone https://github.com/yplog/memotty
1728
cd memotty
1829
go mod tidy
30+
go build -o memotty cmd/memotty/main.go
31+
32+
chmod +x memotty
33+
mv memotty ~/.local/bin/
34+
35+
# Add to PATH if not already added
36+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
37+
# or for zsh users
38+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
1939
```
2040

2141
### Run the Application
2242
```bash
23-
go run cmd/memotty/main.go
43+
memotty
44+
```
45+
46+
### Uninstall
47+
```bash
48+
# Remove binary only
49+
rm -f ~/.local/bin/memotty
50+
51+
# Complete removal (including CSV files)
52+
rm -f ~/.local/bin/memotty && rm -rf ~/.memotty
2453
```
2554

2655
## CSV File Format
@@ -72,15 +101,6 @@ Who was the first US President?,George Washington
72101
What year did the Berlin Wall fall?,1989
73102
```
74103

75-
## 📈 Future Enhancements
76-
77-
- [ ] Timer-based quizzes
78-
- [ ] Score tracking and statistics
79-
- [ ] Multiple difficulty levels
80-
- [ ] Multiple correct answers support (accept any of several valid answers)
81-
- [ ] Export results to file
82-
- [ ] Custom styling themes
83-
84104
## 🤝 Contributing
85105

86106
1. Fork the repository

scripts/install.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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

Comments
 (0)