Initial project scaffold for Dimma

This commit is contained in:
2026-06-10 20:53:30 +02:00
commit 64f55c81b0
17 changed files with 702 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
# Build script for Go updater (PowerShell)
# Usage: .\build.ps1 [os] [arch]
# Default: builds for current OS/architecture
$MODULE = "gitea.sanplex.xyz/Sansan/dimma-updater"
$OUTPUT_DIR = "..\build"
$BIN_NAME = "go-updater"
$OS = if ($args.Count -gt 0) { $args[0] } else { $env:GOOS }
$ARCH = if ($args.Count -gt 1) { $args[1] } else { $env:GOARCH }
if ($OS -eq "windows") { $EXT = ".exe" } else { $EXT = "" }
$OUTPUT = "$OUTPUT_DIR\$BIN_NAME-$OS-$ARCH$EXT"
New-Item -ItemType Directory -Force -Path $OUTPUT_DIR | Out-Null
Write-Host "Building Go updater for $OS/$ARCH..."
Write-Host "Output: $OUTPUT"
go build -o $OUTPUT .\
if ($OS -eq "linux" -or $OS -eq "darwin") {
# On Unix-like systems, make executable
if ($IsLinux -or $IsMacOS) {
chmod +x $OUTPUT
}
}
Write-Host "Build complete: $OUTPUT"
Executable
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# Build script for Go updater
# Usage: ./build.sh [os] [arch]
# Default: builds for current OS/architecture
MODULE="gitea.sanplex.xyz/Sansan/dimma-updater"
OUTPUT_DIR="../build"
BIN_NAME="go-updater"
OS=${1:-$(go env GOOS)}
ARCH=${2:-$(go env GOARCH)}
case "$OS" in
windows) EXT=".exe" ;;
*) EXT="" ;;
esac
OUTPUT="${OUTPUT_DIR}/${BIN_NAME}-${OS}-${ARCH}${EXT}"
mkdir -p "$OUTPUT_DIR"
echo "Building Go updater for ${OS}/${ARCH}..."
echo "Output: ${OUTPUT}"
go build -o "$OUTPUT" ./
if [ "$OS" = "linux" ] || [ "$OS" = "darwin" ]; then
chmod +x "$OUTPUT"
fi
echo "Build complete: ${OUTPUT}"
+7
View File
@@ -0,0 +1,7 @@
module gitea.sanplex.xyz/Sansan/dimma-updater
go 1.21
require (
github.com/inconshreveable/go-update v0.0.0-20230525132907-6d786845c5a3
)
+100
View File
@@ -0,0 +1,100 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"net/http"
"os"
"strings"
)
const (
CurrentVersion = "v0.1.0"
ReleaseURL = "https://gitea.sanplex.xyz/Sansan/dimma/releases/latest"
)
type ReleaseInfo struct {
TagName string `json:"tag_name"`
}
func main() {
check := flag.Bool("check", false, "Check for updates")
flag.Parse()
if !*check {
flag.Usage()
return
}
fmt.Printf("Current version: %s\n", CurrentVersion)
latestVersion, err := fetchLatestVersion()
if err != nil {
fmt.Printf("Error fetching latest version: %v\n", err)
return
}
fmt.Printf("Latest version: %s\n", latestVersion)
if compareVersions(latestVersion, CurrentVersion) > 0 {
fmt.Printf("Update available: %s\n", latestVersion)
} else {
fmt.Println("Up to date")
}
}
func fetchLatestVersion() (string, error) {
resp, err := http.Get(ReleaseURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("HTTP %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
// Gitea releases API returns JSON with tag_name
var release ReleaseInfo
if err := json.Unmarshal(body, &release); err != nil {
// Try to extract from HTML if not JSON
release.TagName = extractVersionFromHTML(string(body))
if release.TagName == "" {
return "", fmt.Errorf("failed to parse release info")
}
}
return release.TagName, nil
}
func extractVersionFromHTML(html string) string {
// Simple extraction from HTML (fallback for non-API URLs)
// Looks for patterns like "v0.1.0" or "0.1.0"
parts := strings.Split(html, "v")
for _, part := range parts {
if len(part) > 0 && part[0] >= '0' && part[0] <= '9' {
version := "v" + strings.Split(part, "\"")[0]
version = strings.Split(version, " ")[0]
version = strings.Split(version, ">")[0]
version = strings.TrimSpace(version)
if version != "" {
return version
}
}
}
return ""
}
func compareVersions(a, b string) int {
// Simple version comparison (v0.1.0 format)
a = strings.TrimPrefix(a, "v")
b = strings.TrimPrefix(b, "v")
return strings.Compare(a, b)
}