mirror of
https://github.com/yarlson/lnk.git
synced 2025-09-02 18:12:33 +02:00
feat(install): enhance installer script robustness and flexibility
This commit is contained in:
@@ -15,15 +15,21 @@ lnk push "setup"
|
|||||||
```bash
|
```bash
|
||||||
# Quick install (recommended)
|
# Quick install (recommended)
|
||||||
curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash
|
curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
# Homebrew (macOS/Linux)
|
# Homebrew (macOS/Linux)
|
||||||
brew tap yarlson/lnk
|
brew tap yarlson/lnk
|
||||||
brew install lnk
|
brew install lnk
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
# Manual download
|
# Manual download
|
||||||
wget https://github.com/yarlson/lnk/releases/latest/download/lnk-$(uname -s | tr '[:upper:]' '[:lower:]')-amd64
|
wget https://github.com/yarlson/lnk/releases/latest/download/lnk-$(uname -s | tr '[:upper:]' '[:lower:]')-amd64
|
||||||
chmod +x lnk-* && sudo mv lnk-* /usr/local/bin/lnk
|
chmod +x lnk-* && sudo mv lnk-* /usr/local/bin/lnk
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
# From source
|
# From source
|
||||||
git clone https://github.com/yarlson/lnk.git && cd lnk && go build . && sudo mv lnk /usr/local/bin/
|
git clone https://github.com/yarlson/lnk.git && cd lnk && go build . && sudo mv lnk /usr/local/bin/
|
||||||
```
|
```
|
||||||
|
@@ -64,11 +64,13 @@ git push origin v1.0.0
|
|||||||
## What GoReleaser Does
|
## What GoReleaser Does
|
||||||
|
|
||||||
1. **Builds binaries** for multiple platforms:
|
1. **Builds binaries** for multiple platforms:
|
||||||
|
|
||||||
- Linux (amd64, arm64)
|
- Linux (amd64, arm64)
|
||||||
- macOS (amd64, arm64)
|
- macOS (amd64, arm64)
|
||||||
- Windows (amd64)
|
- Windows (amd64)
|
||||||
|
|
||||||
2. **Creates archives** with consistent naming:
|
2. **Creates archives** with consistent naming:
|
||||||
|
|
||||||
- `lnk_Linux_x86_64.tar.gz`
|
- `lnk_Linux_x86_64.tar.gz`
|
||||||
- `lnk_Darwin_arm64.tar.gz`
|
- `lnk_Darwin_arm64.tar.gz`
|
||||||
- etc.
|
- etc.
|
||||||
@@ -76,6 +78,7 @@ git push origin v1.0.0
|
|||||||
3. **Generates checksums** for verification
|
3. **Generates checksums** for verification
|
||||||
|
|
||||||
4. **Creates GitHub release** with:
|
4. **Creates GitHub release** with:
|
||||||
|
|
||||||
- Automatic changelog from conventional commits
|
- Automatic changelog from conventional commits
|
||||||
- Installation instructions
|
- Installation instructions
|
||||||
- Download links for all platforms
|
- Download links for all platforms
|
||||||
@@ -112,17 +115,20 @@ ls -la dist/
|
|||||||
After a release is published, users can install lnk using multiple methods:
|
After a release is published, users can install lnk using multiple methods:
|
||||||
|
|
||||||
### 1. Shell Script (Recommended)
|
### 1. Shell Script (Recommended)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash
|
curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Homebrew (macOS/Linux)
|
### 2. Homebrew (macOS/Linux)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew tap yarlson/lnk
|
brew tap yarlson/lnk
|
||||||
brew install lnk
|
brew install lnk
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Manual Download
|
### 3. Manual Download
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Download from GitHub releases
|
# Download from GitHub releases
|
||||||
wget https://github.com/yarlson/lnk/releases/latest/download/lnk_Linux_x86_64.tar.gz
|
wget https://github.com/yarlson/lnk/releases/latest/download/lnk_Linux_x86_64.tar.gz
|
||||||
@@ -181,4 +187,4 @@ The Homebrew formula is automatically maintained in the [homebrew-lnk](https://g
|
|||||||
1. Check that the GITHUB_TOKEN has access to the homebrew-lnk repository
|
1. Check that the GITHUB_TOKEN has access to the homebrew-lnk repository
|
||||||
2. Verify the repository name and owner in `.goreleaser.yml`
|
2. Verify the repository name and owner in `.goreleaser.yml`
|
||||||
3. Check the release workflow logs for Homebrew-related errors
|
3. Check the release workflow logs for Homebrew-related errors
|
||||||
4. Ensure the homebrew-lnk repository exists and is accessible
|
4. Ensure the homebrew-lnk repository exists and is accessible
|
||||||
|
84
install.sh
84
install.sh
@@ -17,6 +17,9 @@ REPO="yarlson/lnk"
|
|||||||
INSTALL_DIR="/usr/local/bin"
|
INSTALL_DIR="/usr/local/bin"
|
||||||
BINARY_NAME="lnk"
|
BINARY_NAME="lnk"
|
||||||
|
|
||||||
|
# Fallback version if redirect fails
|
||||||
|
FALLBACK_VERSION="v0.0.2"
|
||||||
|
|
||||||
# Detect OS and architecture
|
# Detect OS and architecture
|
||||||
detect_platform() {
|
detect_platform() {
|
||||||
local os arch
|
local os arch
|
||||||
@@ -45,11 +48,44 @@ detect_platform() {
|
|||||||
echo "${os}_${arch}"
|
echo "${os}_${arch}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the latest release version
|
# Get latest version by following redirect
|
||||||
get_latest_version() {
|
get_latest_version() {
|
||||||
curl -s "https://api.github.com/repos/${REPO}/releases/latest" | \
|
echo -e "${BLUE}Getting latest release version...${NC}" >&2
|
||||||
grep '"tag_name":' | \
|
|
||||||
sed -E 's/.*"([^"]+)".*/\1/'
|
# Get redirect location from releases/latest
|
||||||
|
local redirect_url
|
||||||
|
redirect_url=$(curl -s -I "https://github.com/${REPO}/releases/latest" | grep -i "^location:" | sed 's/\r$//' | cut -d' ' -f2-)
|
||||||
|
|
||||||
|
if [ -z "$redirect_url" ]; then
|
||||||
|
echo -e "${YELLOW}⚠ Could not get redirect URL, using fallback version ${FALLBACK_VERSION}${NC}" >&2
|
||||||
|
echo "$FALLBACK_VERSION"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract version from redirect URL (format: https://github.com/user/repo/releases/tag/v1.2.3)
|
||||||
|
local version
|
||||||
|
version=$(echo "$redirect_url" | sed -E 's|.*/releases/tag/([^/]*)\s*$|\1|')
|
||||||
|
|
||||||
|
if [ -z "$version" ] || [ "$version" = "$redirect_url" ]; then
|
||||||
|
echo -e "${YELLOW}⚠ Could not parse version from redirect URL: $redirect_url${NC}" >&2
|
||||||
|
echo -e "${YELLOW}Using fallback version ${FALLBACK_VERSION}${NC}" >&2
|
||||||
|
echo "$FALLBACK_VERSION"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$version"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get version to install
|
||||||
|
get_version() {
|
||||||
|
# Allow override via environment variable
|
||||||
|
if [ -n "$LNK_VERSION" ]; then
|
||||||
|
echo "$LNK_VERSION"
|
||||||
|
elif [ -n "$1" ]; then
|
||||||
|
echo "$1"
|
||||||
|
else
|
||||||
|
get_latest_version
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download and install
|
# Download and install
|
||||||
@@ -59,14 +95,9 @@ install_lnk() {
|
|||||||
echo -e "${BLUE}🔗 Installing lnk...${NC}"
|
echo -e "${BLUE}🔗 Installing lnk...${NC}"
|
||||||
|
|
||||||
platform=$(detect_platform)
|
platform=$(detect_platform)
|
||||||
version=$(get_latest_version)
|
version=$(get_version "$1")
|
||||||
|
|
||||||
if [ -z "$version" ]; then
|
echo -e "${BLUE}Version: ${version}${NC}"
|
||||||
echo -e "${RED}Error: Failed to get latest version${NC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${BLUE}Latest version: ${version}${NC}"
|
|
||||||
echo -e "${BLUE}Platform: ${platform}${NC}"
|
echo -e "${BLUE}Platform: ${platform}${NC}"
|
||||||
|
|
||||||
# Download URL
|
# Download URL
|
||||||
@@ -82,6 +113,16 @@ install_lnk() {
|
|||||||
# Download the binary
|
# Download the binary
|
||||||
if ! curl -sL "$url" -o "$filename"; then
|
if ! curl -sL "$url" -o "$filename"; then
|
||||||
echo -e "${RED}Error: Failed to download ${url}${NC}"
|
echo -e "${RED}Error: Failed to download ${url}${NC}"
|
||||||
|
echo -e "${YELLOW}Please check if the release exists at: https://github.com/${REPO}/releases/tag/${version}${NC}"
|
||||||
|
echo -e "${YELLOW}Available releases: https://github.com/${REPO}/releases${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if we got an HTML error page instead of the binary
|
||||||
|
if file "$filename" 2>/dev/null | grep -q "HTML"; then
|
||||||
|
echo -e "${RED}Error: Downloaded file appears to be an HTML page (404 error)${NC}"
|
||||||
|
echo -e "${YELLOW}The release ${version} might not exist.${NC}"
|
||||||
|
echo -e "${YELLOW}Available releases: https://github.com/${REPO}/releases${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -107,20 +148,33 @@ install_lnk() {
|
|||||||
|
|
||||||
echo -e "${GREEN}✅ lnk installed successfully!${NC}"
|
echo -e "${GREEN}✅ lnk installed successfully!${NC}"
|
||||||
echo -e "${GREEN}Run 'lnk --help' to get started.${NC}"
|
echo -e "${GREEN}Run 'lnk --help' to get started.${NC}"
|
||||||
|
|
||||||
|
# Test the installation
|
||||||
|
if command -v lnk >/dev/null 2>&1; then
|
||||||
|
echo -e "${GREEN}Installed version: $(lnk --version)${NC}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if running with --help
|
# Check if running with --help
|
||||||
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
|
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
|
||||||
echo "Lnk installer script"
|
echo "Lnk installer script"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Usage: curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash"
|
echo "Usage:"
|
||||||
|
echo " curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash"
|
||||||
|
echo " curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash -s v0.0.1"
|
||||||
|
echo " LNK_VERSION=v0.0.1 curl -sSL https://raw.githubusercontent.com/yarlson/lnk/main/install.sh | bash"
|
||||||
echo ""
|
echo ""
|
||||||
echo "This script will:"
|
echo "This script will:"
|
||||||
echo " 1. Detect your OS and architecture"
|
echo " 1. Detect your OS and architecture"
|
||||||
echo " 2. Download the latest lnk release"
|
echo " 2. Auto-detect the latest release by following GitHub redirects"
|
||||||
echo " 3. Install it to /usr/local/bin (requires sudo)"
|
echo " 3. Download and install to /usr/local/bin (requires sudo)"
|
||||||
|
echo ""
|
||||||
|
echo "Environment variables:"
|
||||||
|
echo " LNK_VERSION - Specify version to install (e.g., v0.0.1)"
|
||||||
|
echo ""
|
||||||
|
echo "Manual installation: https://github.com/yarlson/lnk/releases"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the installer
|
# Run the installer
|
||||||
install_lnk
|
install_lnk "$1"
|
Reference in New Issue
Block a user