-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·240 lines (202 loc) · 7.56 KB
/
install.sh
File metadata and controls
executable file
·240 lines (202 loc) · 7.56 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
set -e
# Television Installation Script
# Automatically detects your system and installs using the best available method
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print functions
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
# Detect OS and architecture
detect_system() {
OS=""
ARCH=""
# Detect OS
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
else
error "Unsupported OS: $OSTYPE"
fi
# Detect architecture
case $(uname -m) in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
armv7*) ARCH="armv7" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
info "Detected system: $OS ($ARCH)"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install on macOS
install_macos() {
if command_exists brew; then
info "Installing Television via Homebrew..."
brew install television
success "Television installed successfully via Homebrew!"
elif command_exists port; then
warning "MacPorts detected but Television may not be available. Falling back to binary download..."
install_binary
else
warning "No package manager found. Installing via binary download..."
install_binary
fi
}
# Install on Linux
install_linux() {
# Try package managers in order of preference
if command_exists nix; then
info "Installing Television via Nix..."
nix profile install nixpkgs#television
success "Television installed successfully via Nix!"
elif command_exists pacman && [[ -f /etc/arch-release ]]; then
info "Installing Television via pacman (Arch Linux)..."
sudo pacman -S --noconfirm television
success "Television installed successfully via pacman!"
elif command_exists apk && [[ -f /etc/chimera-release ]]; then
info "Installing Television via apk (Chimera Linux)..."
sudo apk add chimera-repo-user
sudo apk add television
success "Television installed successfully via apk!"
elif command_exists apt-get && [[ -f /etc/debian_version ]]; then
info "Installing Television via .deb package (Debian-based)..."
install_deb
elif command_exists dnf; then
warning "Fedora/RHEL detected but no native package available. Installing via binary..."
install_binary
elif command_exists zypper; then
warning "openSUSE detected but no native package available. Installing via binary..."
install_binary
elif command_exists cargo; then
warning "No native package available. Installing via Cargo..."
install_cargo
else
warning "No supported package manager found. Installing via binary download..."
install_binary
fi
}
# Install .deb package on Debian-based systems
install_deb() {
# Detect architecture-specific package
case "$ARCH" in
x86_64) DEB_ARCH="x86_64-unknown-linux-musl" ;;
aarch64) DEB_ARCH="aarch64-unknown-linux-gnu" ;;
*)
warning "No .deb package for $ARCH architecture. Falling back to binary..."
install_binary
return
;;
esac
info "Fetching latest release information..."
VER=$(curl -s "https://api.github.com/repos/alexpasmantier/television/releases/latest" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
if [[ -z "$VER" ]]; then
error "Failed to fetch latest version. Please check your internet connection."
fi
info "Downloading Television $VER for $DEB_ARCH..."
DEB_FILE="tv-$VER-$DEB_ARCH.deb"
if ! curl -LO "https://github.com/alexpasmantier/television/releases/download/$VER/$DEB_FILE"; then
error "Failed to download .deb package"
fi
info "Installing .deb package..."
sudo dpkg -i "$DEB_FILE"
# Clean up
rm -f "$DEB_FILE"
success "Television $VER installed successfully!"
}
# Install via Cargo
install_cargo() {
if ! command_exists rustc; then
info "Rust not found. Installing Rust first..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
fi
info "Installing Television via Cargo..."
cargo install --locked television
success "Television installed successfully via Cargo!"
}
# Install pre-compiled binary
install_binary() {
info "Installing Television via pre-compiled binary..."
# Map architecture to release naming
case "$OS-$ARCH" in
linux-x86_64) BINARY_TARGET="x86_64-unknown-linux-musl" ;;
linux-aarch64) BINARY_TARGET="aarch64-unknown-linux-gnu" ;;
macos-x86_64) BINARY_TARGET="x86_64-apple-darwin" ;;
macos-aarch64) BINARY_TARGET="aarch64-apple-darwin" ;;
*) error "No pre-compiled binary available for $OS-$ARCH" ;;
esac
info "Fetching latest release information..."
VER=$(curl -s "https://api.github.com/repos/alexpasmantier/television/releases/latest" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
if [[ -z "$VER" ]]; then
error "Failed to fetch latest version. Please check your internet connection."
fi
DIRNAME="tv-$VER-$BINARY_TARGET"
TARBALL="$DIRNAME.tar.gz"
URL="https://github.com/alexpasmantier/television/releases/download/$VER/$TARBALL"
info "Downloading Television $VER for $OS-$ARCH..."
if ! curl -LO "$URL"; then
error "Failed to download binary package"
fi
info "Extracting binary..."
tar -xzf "$TARBALL"
# Install to appropriate location
if [[ "$OS" == "macos" ]]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="/usr/local/bin"
fi
info "Installing to $INSTALL_DIR..."
sudo mkdir -p "$INSTALL_DIR"
sudo mv "$DIRNAME/tv" "$INSTALL_DIR/tv"
sudo chmod +x "$INSTALL_DIR/tv"
# Clean up
rm -rf $DIRNAME*
success "Television $VER installed successfully to $INSTALL_DIR/tv!"
}
# Install on Windows (Git Bash/MSYS2/WSL)
install_windows() {
if command_exists winget.exe; then
info "Installing Television via WinGet..."
winget.exe install --exact --id alexpasmantier.television
success "Television installed successfully via WinGet!"
elif command_exists scoop; then
info "Installing Television via Scoop..."
scoop bucket add extras
scoop install television
success "Television installed successfully via Scoop!"
else
error "No supported Windows package manager found. Please install WinGet or Scoop first."
fi
}
# Main installation logic
main() {
echo "🔍 Television Installation Script"
echo "================================"
detect_system
case "$OS" in
linux) install_linux ;;
macos) install_macos ;;
windows) install_windows ;;
*) error "Unsupported operating system: $OS" ;;
esac
echo ""
info "Installation complete! You can now use the 'tv' command."
info "Run 'tv --help' to get started."
info "Documentation: https://github.com/alexpasmantier/television"
}
# Handle Ctrl+C
trap 'echo ""; error "Installation cancelled by user"' INT
# Run main function
main "$@"