haste-it
This commit is contained in:
commit
1f72163401
|
@ -0,0 +1,59 @@
|
|||
To help you install the `haste-it` binaries efficiently on various architectures, I'll provide you with a README guide that includes bash one-liners for installation. Additionally, I'll include a simple bash script for automatic installation and setting up the environment variable for the Hastebin server URL.
|
||||
|
||||
### README.md Content
|
||||
|
||||
```markdown
|
||||
# Haste-It Installation Guide
|
||||
|
||||
This guide provides instructions for installing the `haste-it` binary on various systems based on the architecture.
|
||||
|
||||
## Installation
|
||||
|
||||
Before installing, ensure that the binary for your architecture has been built and is located in the `dist` directory.
|
||||
|
||||
Run the following command to install the `haste-it` binary:
|
||||
|
||||
```bash
|
||||
bash install.sh
|
||||
```
|
||||
|
||||
This script will automatically detect your system's architecture, choose the correct binary from the `dist` directory, and install it.
|
||||
|
||||
## Configuration
|
||||
|
||||
After installation, set the environment variable for your Hastebin server by adding the following to your `.bashrc`, `.zshrc`, or equivalent shell configuration file:
|
||||
|
||||
```bash
|
||||
export HASTEBIN_URL="https://your-hastebin-server.com"
|
||||
```
|
||||
|
||||
Replace `https://your-hastebin-server.com` with the URL of your Hastebin server.
|
||||
|
||||
## Usage
|
||||
|
||||
After installation and configuration, you can use `haste-it` by simply typing:
|
||||
|
||||
```bash
|
||||
haste-it [file]
|
||||
```
|
||||
|
||||
If no file is specified, `haste-it` will read from standard input.
|
||||
```
|
||||
|
||||
### Installation Script (`install.sh`)
|
||||
|
||||
Here's a simple bash script to automate the installation process. This script will detect the architecture, find the appropriate binary in the `dist` directory, and install it to `/usr/local/bin`.
|
||||
|
||||
## Instructions for Use
|
||||
|
||||
Ensure that install.sh has execute permissions:
|
||||
|
||||
```bash
|
||||
chmod +x install.sh
|
||||
```
|
||||
Run the script with sufficient privileges (as it installs to /usr/local/bin):
|
||||
|
||||
```bash
|
||||
sudo ./install.sh
|
||||
```
|
||||
Set the environment variable as described in the README.
|
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default architecture
|
||||
DEFAULT_ARCH="linux/amd64"
|
||||
|
||||
# Supported architectures (adjust as needed)
|
||||
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7" "darwin/amd64" "darwin/arm64")
|
||||
|
||||
# Ensure all necessary directories exist and go modules are ready
|
||||
prepare_build() {
|
||||
# Create necessary directories if they don't exist
|
||||
mkdir -p dist
|
||||
mkdir -p build_logs
|
||||
|
||||
# Initialize go modules if go.mod does not exist
|
||||
if [ ! -f go.mod ]; then
|
||||
echo "Initializing Go modules"
|
||||
go mod init yourmodule # Replace 'yourmodule' with your actual module name or path
|
||||
fi
|
||||
|
||||
# Fetch and ensure all dependencies are up to date
|
||||
echo "Checking dependencies..."
|
||||
go mod tidy
|
||||
}
|
||||
|
||||
# Build function
|
||||
build_binary() {
|
||||
os=$1
|
||||
arch=$2
|
||||
output_name="haste-it"
|
||||
|
||||
if [[ "$os/$arch" != "$DEFAULT_ARCH" ]]; then
|
||||
output_name="${output_name}_${os}_${arch}"
|
||||
fi
|
||||
|
||||
output_name="dist/${output_name}"
|
||||
|
||||
echo "Building for ${os}/${arch} -> ${output_name}"
|
||||
GOOS=${os} GOARCH=${arch} go build -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully built ${output_name}"
|
||||
else
|
||||
echo "Failed to build ${output_name}. Check build_logs/${os}_${arch}_build.log for errors."
|
||||
fi
|
||||
}
|
||||
|
||||
# Main Build Process
|
||||
prepare_build
|
||||
for arch in "${ARCHITECTURES[@]}"; do
|
||||
IFS='/' read -r -a parts <<< "$arch" # Split architecture string
|
||||
os=${parts[0]}
|
||||
arch=${parts[1]}
|
||||
build_binary $os $arch
|
||||
done
|
||||
|
||||
echo "Build process completed."
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default architecture
|
||||
DEFAULT_ARCH="linux/amd64"
|
||||
|
||||
# Supported architectures (adjust as needed)
|
||||
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7")
|
||||
|
||||
# Ensure all necessary directories exist and go modules are ready
|
||||
prepare_build() {
|
||||
# Create necessary directories if they don't exist
|
||||
mkdir -p dist
|
||||
mkdir -p build_logs
|
||||
|
||||
# Initialize go modules if go.mod does not exist
|
||||
if [ ! -f go.mod ]; then
|
||||
echo "Initializing Go modules"
|
||||
go mod init yourmodule # Replace 'yourmodule' with your actual module name or path
|
||||
fi
|
||||
|
||||
# Fetch and ensure all dependencies are up to date
|
||||
echo "Checking dependencies..."
|
||||
go mod tidy
|
||||
}
|
||||
|
||||
# Build function
|
||||
build_binary() {
|
||||
os=$1
|
||||
arch=$2
|
||||
output_name="haste-it"
|
||||
|
||||
if [[ "$os/$arch" != "$DEFAULT_ARCH" ]]; then
|
||||
output_name="${output_name}_${os}_${arch}"
|
||||
fi
|
||||
|
||||
output_name="build_output/${output_name}"
|
||||
|
||||
echo "Building for ${os}/${arch} -> ${output_name}"
|
||||
GOOS=${os} GOARCH=${arch} go build -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully built ${output_name}"
|
||||
else
|
||||
echo "Failed to build ${output_name}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main Build Process
|
||||
prepare_build
|
||||
for arch in "${ARCHITECTURES[@]}"; do
|
||||
IFS='/' read -r -a parts <<< "$arch" # Split architecture string
|
||||
os=${parts[0]}
|
||||
arch=${parts[1]}
|
||||
build_binary $os $arch
|
||||
done
|
||||
|
||||
echo "Build process completed."
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,59 @@
|
|||
|
||||
### Installation Script (`install.sh`)
|
||||
|
||||
Here's a simple bash script to automate the installation process. This script will detect the architecture, find the appropriate binary in the `dist` directory, and install it to `/usr/local/bin`.
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Define the installation directory and binary name
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
BINARY_NAME="haste-it"
|
||||
|
||||
# Define supported architectures and corresponding binaries
|
||||
declare -A binaries
|
||||
binaries["linux/amd64"]="haste-it_linux_amd64"
|
||||
binaries["linux/arm64"]="haste-it_linux_arm64"
|
||||
binaries["linux/arm/v7"]="haste-it_linux_arm"
|
||||
binaries["darwin/amd64"]="haste-it_darwin_amd64"
|
||||
binaries["darwin/arm64"]="haste-it_darwin_arm64"
|
||||
|
||||
# Detect the OS and architecture
|
||||
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||
ARCH="$(uname -m)"
|
||||
|
||||
case $ARCH in
|
||||
x86_64)
|
||||
ARCH="amd64"
|
||||
;;
|
||||
arm64)
|
||||
ARCH="arm64"
|
||||
;;
|
||||
aarch64)
|
||||
ARCH="arm64"
|
||||
;;
|
||||
arm*)
|
||||
ARCH="arm/v7"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Construct the key for finding the binary
|
||||
KEY="${OS}/${ARCH}"
|
||||
|
||||
# Check if the binary exists for this architecture
|
||||
if [[ -z "${binaries[$KEY]}" ]]; then
|
||||
echo "No pre-built binary for your system architecture ($KEY)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install the binary
|
||||
BINARY_PATH="dist/${binaries[$KEY]}"
|
||||
if [[ -f "$BINARY_PATH" ]]; then
|
||||
sudo cp "$BINARY_PATH" "$INSTALL_DIR/$BINARY_NAME"
|
||||
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
|
||||
echo "Installed $BINARY_NAME to $INSTALL_DIR"
|
||||
else
|
||||
echo "Binary file not found: $BINARY_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Fetch Hastebin URL from environment variable
|
||||
hastebinURL := os.Getenv("HASTEBIN_URL")
|
||||
if hastebinURL == "" {
|
||||
fmt.Println("Error: HASTEBIN_URL environment variable is not set")
|
||||
return
|
||||
}
|
||||
|
||||
// Determine the input source
|
||||
var input io.Reader
|
||||
if len(os.Args) > 1 {
|
||||
file, err := os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Printf("Error opening file: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
input = file
|
||||
} else {
|
||||
input = os.Stdin
|
||||
}
|
||||
|
||||
// Read the entire input
|
||||
buffer := new(bytes.Buffer)
|
||||
_, err := buffer.ReadFrom(input)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading input: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Send data to Hastebin
|
||||
resp, err := http.Post(hastebinURL+"/documents", "text/plain", buffer)
|
||||
if err != nil {
|
||||
fmt.Printf("Error posting data to Hastebin: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Decode response to get the key
|
||||
type HastebinResponse struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
var res HastebinResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
||||
fmt.Printf("Error decoding Hastebin response: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Output the full URL
|
||||
fmt.Println(hastebinURL + "/" + res.Key)
|
||||
}
|
||||
|
Loading…
Reference in New Issue