-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·178 lines (145 loc) · 4.82 KB
/
install.sh
File metadata and controls
executable file
·178 lines (145 loc) · 4.82 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
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
REPO="wsoule/dotfiles-cli"
BINARY_NAME="dotfiles"
INSTALL_DIR="/usr/local/bin"
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
i386|i686) ARCH="386" ;;
*) echo -e "${RED}❌ Unsupported architecture: $ARCH${NC}" && exit 1 ;;
esac
case $OS in
darwin) OS="darwin" ;;
linux) OS="linux" ;;
*) echo -e "${RED}❌ Unsupported OS: $OS${NC}" && exit 1 ;;
esac
echo -e "${BLUE}🛠 Dotfiles Manager Installer${NC}"
echo "=================================="
echo ""
echo "Installing for: $OS/$ARCH"
echo ""
# Check if running as root (not recommended)
if [[ $EUID -eq 0 ]]; then
echo -e "${YELLOW}⚠️ Warning: Running as root. Consider running as regular user.${NC}"
fi
# Function to install from GitHub releases
install_from_releases() {
echo -e "${BLUE}📦 Installing from GitHub releases...${NC}"
# Get latest release info
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_RELEASE" ]; then
echo -e "${RED}❌ Could not fetch latest release info${NC}"
return 1
fi
echo "Latest release: $LATEST_RELEASE"
# Construct download URL
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_RELEASE/${BINARY_NAME}_${OS}_${ARCH}.tar.gz"
echo "Downloading: $DOWNLOAD_URL"
# Create temporary directory
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
# Download and extract
if ! curl -L -o "${BINARY_NAME}.tar.gz" "$DOWNLOAD_URL"; then
echo -e "${RED}❌ Download failed${NC}"
rm -rf "$TEMP_DIR"
return 1
fi
tar -xzf "${BINARY_NAME}.tar.gz"
# Install binary
if [[ ! -w "$INSTALL_DIR" ]]; then
echo -e "${YELLOW}🔐 Installing to $INSTALL_DIR (requires sudo)${NC}"
sudo mv "$BINARY_NAME" "$INSTALL_DIR/"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
mv "$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
# Cleanup
cd - > /dev/null
rm -rf "$TEMP_DIR"
echo -e "${GREEN}✅ Installed successfully!${NC}"
return 0
}
# Function to build from source
install_from_source() {
echo -e "${BLUE}🔨 Building from source...${NC}"
# Check if Go is installed
if ! command -v go &> /dev/null; then
echo -e "${RED}❌ Go is not installed. Please install Go first:${NC}"
echo " macOS: brew install go"
echo " Linux: Follow instructions at https://golang.org/doc/install"
exit 1
fi
# Create temporary directory
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
# Clone repository
echo "Cloning repository..."
if ! git clone "https://github.com/$REPO.git" .; then
echo -e "${RED}❌ Failed to clone repository${NC}"
rm -rf "$TEMP_DIR"
exit 1
fi
# Build
echo "Building..."
if ! go build -o "$BINARY_NAME" .; then
echo -e "${RED}❌ Build failed${NC}"
rm -rf "$TEMP_DIR"
exit 1
fi
# Install binary
if [[ ! -w "$INSTALL_DIR" ]]; then
echo -e "${YELLOW}🔐 Installing to $INSTALL_DIR (requires sudo)${NC}"
sudo mv "$BINARY_NAME" "$INSTALL_DIR/"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
mv "$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
# Cleanup
cd - > /dev/null
rm -rf "$TEMP_DIR"
echo -e "${GREEN}✅ Built and installed successfully!${NC}"
}
# Try installation methods
echo -e "${BLUE}Attempting installation...${NC}"
# Try GitHub releases first, fall back to source
if ! install_from_releases; then
echo -e "${YELLOW}⚠️ Release installation failed, trying source build...${NC}"
install_from_source
fi
# Verify installation
echo ""
echo -e "${BLUE}🧪 Verifying installation...${NC}"
if command -v "$BINARY_NAME" &> /dev/null; then
echo -e "${GREEN}✅ Installation successful!${NC}"
echo ""
echo -e "${GREEN}🎉 Dotfiles Manager is ready!${NC}"
echo ""
echo "Get started with:"
echo -e " ${BLUE}dotfiles onboard${NC} # Complete developer setup"
echo -e " ${BLUE}dotfiles init${NC} # Initialize configuration"
echo -e " ${BLUE}dotfiles github setup${NC} # Set up GitHub SSH"
echo ""
echo "For help:"
echo -e " ${BLUE}dotfiles --help${NC}"
echo ""
# Show version
"$BINARY_NAME" --version 2>/dev/null || echo "Version: Latest"
else
echo -e "${RED}❌ Installation verification failed${NC}"
echo "The binary may not be in your PATH. Try:"
echo " $INSTALL_DIR/$BINARY_NAME --help"
exit 1
fi