-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-gum.sh
More file actions
executable file
·256 lines (229 loc) · 7.52 KB
/
install-gum.sh
File metadata and controls
executable file
·256 lines (229 loc) · 7.52 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
# =============================================================================
# Gum Installation Helper for pgctl
# =============================================================================
# This script detects your OS and helps install Charm's gum CLI tool
# https://github.com/charmbracelet/gum
# =============================================================================
set -e
# Colors for output (basic, works without gum)
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if gum is already installed
check_gum_installed() {
if command -v gum &> /dev/null; then
GUM_VERSION=$(gum --version 2>/dev/null || echo "unknown")
log_success "gum is already installed (version: $GUM_VERSION)"
return 0
fi
return 1
}
# Detect operating system
detect_os() {
case "$(uname -s)" in
Darwin*)
OS="macos"
;;
Linux*)
OS="linux"
# Detect Linux distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
elif [ -f /etc/debian_version ]; then
DISTRO="debian"
elif [ -f /etc/redhat-release ]; then
DISTRO="rhel"
else
DISTRO="unknown"
fi
;;
*)
OS="unknown"
;;
esac
log_info "Detected OS: $OS"
if [ "$OS" = "linux" ]; then
log_info "Detected distribution: $DISTRO"
fi
}
# Install gum on macOS
install_macos() {
log_info "Installing gum via Homebrew..."
# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
log_warning "Homebrew is not installed."
echo ""
echo "To install Homebrew, run:"
echo ' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
echo ""
echo "Then run this script again."
exit 1
fi
brew install gum
}
# Install gum on Linux
install_linux() {
case "$DISTRO" in
ubuntu|debian|pop|linuxmint)
log_info "Installing gum via apt (Debian/Ubuntu)..."
echo ""
echo "Run the following commands:"
echo ""
echo " sudo mkdir -p /etc/apt/keyrings"
echo " curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg"
echo ' echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list'
echo " sudo apt update && sudo apt install gum"
echo ""
read -p "Would you like to run these commands now? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum
fi
;;
fedora|rhel|centos|rocky|almalinux)
log_info "Installing gum via yum/dnf (Fedora/RHEL)..."
echo ""
echo "Run the following commands:"
echo ""
echo ' echo "[charm]'
echo ' name=Charm'
echo ' baseurl=https://repo.charm.sh/yum/'
echo ' enabled=1'
echo ' gpgcheck=1'
echo ' gpgkey=https://repo.charm.sh/yum/gpg.key" | sudo tee /etc/yum.repos.d/charm.repo'
echo " sudo yum install gum"
echo ""
read -p "Would you like to run these commands now? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo '[charm]
name=Charm
baseurl=https://repo.charm.sh/yum/
enabled=1
gpgcheck=1
gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
sudo yum install gum -y
fi
;;
arch|manjaro)
log_info "Installing gum via pacman (Arch Linux)..."
echo ""
echo "Run the following command:"
echo " sudo pacman -S gum"
echo ""
read -p "Would you like to run this command now? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo pacman -S gum
fi
;;
alpine)
log_info "Installing gum via apk (Alpine Linux)..."
echo ""
echo "Run the following command:"
echo " sudo apk add gum"
echo ""
read -p "Would you like to run this command now? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo apk add gum
fi
;;
*)
log_warning "Unknown Linux distribution: $DISTRO"
install_from_binary
;;
esac
}
# Install from binary (fallback)
install_from_binary() {
log_info "Installing gum from binary..."
echo ""
echo "You can download gum binaries from:"
echo " https://github.com/charmbracelet/gum/releases"
echo ""
echo "Or install via Go:"
echo " go install github.com/charmbracelet/gum@latest"
echo ""
echo "Or use Nix:"
echo " nix-env -iA nixpkgs.gum"
echo ""
}
# Verify installation
verify_installation() {
if command -v gum &> /dev/null; then
GUM_VERSION=$(gum --version 2>/dev/null || echo "unknown")
log_success "gum installed successfully (version: $GUM_VERSION)"
echo ""
echo "You can now use pgctl with full interactive features!"
echo "Try running: ./postgres/pgctl"
return 0
else
log_error "gum installation could not be verified"
log_info "Please try installing manually or check your PATH"
return 1
fi
}
# Main function
main() {
echo ""
echo "╔════════════════════════════════════════╗"
echo "║ Gum Installation Helper for pgctl ║"
echo "╚════════════════════════════════════════╝"
echo ""
# Check if already installed
if check_gum_installed; then
echo ""
echo "No installation needed. gum is ready to use!"
exit 0
fi
log_info "gum is not installed. Starting installation..."
echo ""
# Detect OS
detect_os
# Install based on OS
case "$OS" in
macos)
read -p "Would you like to install gum via Homebrew? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
install_macos
else
log_info "Skipping installation."
install_from_binary
fi
;;
linux)
install_linux
;;
*)
log_warning "Unknown operating system"
install_from_binary
;;
esac
echo ""
# Verify installation
verify_installation
}
# Run main function
main "$@"