aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-07 16:30:52 +0200
committerDanilo M. <danix@danix.xyz>2026-05-07 16:30:52 +0200
commit03b2f896062ce689df655160328381004b3ad26d (patch)
tree31f43b3767e7fe882c82a5c304e25f58f9d1b926
downloadmkhintfile-03b2f896062ce689df655160328381004b3ad26d.tar.gz
mkhintfile-03b2f896062ce689df655160328381004b3ad26d.zip
Initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--CLAUDE.md57
-rw-r--r--README.md91
-rw-r--r--mkhintfile.bash-completion33
-rwxr-xr-xmkhintfile.sh335
4 files changed, 516 insertions, 0 deletions
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000..2ee689b
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,57 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## What This Is
+
+`mkhintfile.sh` — bash utility for managing [slackrepo](https://idlemoor.github.io/slackrepo/) hint files. Hint files override build variables (version, download URL, checksum) for SlackBuilds.
+
+## Configuration
+
+Two paths hardcoded near top of `mkhintfile.sh` (lines 16–17):
+
+```bash
+REPO_DIR="/var/lib/sbopkg/SBo-danix/" # SBo repository with .info files
+HINT_DIR="/etc/slackrepo/SBo-danix/hintfiles/" # where .hint files live
+```
+
+Bash completion script has its own hardcoded copies (lines 8–9) — keep in sync when changing defaults.
+
+## Running / Testing
+
+No build step. Direct execution:
+
+```bash
+bash mkhintfile.sh --help
+bash mkhintfile.sh --list
+bash mkhintfile.sh --version 2.0.1 --hintfile mypackage
+bash mkhintfile.sh --version 1.2.3 --new mypackage
+bash mkhintfile.sh --new mypackage # empty hint, no version
+bash mkhintfile.sh --clean
+```
+
+No test suite exists. Test manually against real `REPO_DIR`/`HINT_DIR` or with mock directories.
+
+## Key Behaviors
+
+- `--hintfile` update: backs up to `.bak`, replaces old version string globally via `sed`, re-downloads both URLs to recalculate MD5 checksums. Skips download if value is `UNSUPPORTED` or `UNTESTED`.
+- `--new` with existing `.info`: copies `.info` as template, strips `PRGNAM`, `HOMEPAGE`, `MAINTAINER`, `EMAIL`, comments out `REQUIRES`, sets `ARCH="x86_64"`.
+- `--new` when hint already exists: backs up old, creates empty skeleton.
+- Downloads go to `/tmp/mkhint/download` (single shared temp file, deleted after md5 calculation).
+
+## Exit Codes
+
+| Code | Meaning |
+|------|---------|
+| 0 | Success |
+| 1 | Invalid arguments |
+| 2 | File not found |
+| 3 | File already exists (unused — backup logic replaces this) |
+| 4 | wget not available |
+
+## Installation
+
+```bash
+sudo cp mkhintfile.sh /usr/local/bin/mkhintfile
+sudo cp mkhintfile.bash-completion /etc/bash-completion.d/mkhintfile
+```
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5d04899
--- /dev/null
+++ b/README.md
@@ -0,0 +1,91 @@
+# mkhintfile.sh
+
+Manage hint files for slackrepo scripts. Updates version strings and download checksums, or creates new hint files from repository .info files.
+
+## Installation
+
+### Script
+
+```bash
+sudo cp mkhintfile.sh /usr/local/bin/mkhintfile
+```
+
+### Bash Completion
+
+```bash
+sudo cp mkhintfile.bash-completion /etc/bash-completion.d/mkhintfile
+```
+
+### Configuration
+
+Edit the paths at the top of mkhintfile.sh to match your setup:
+
+```bash
+REPO_DIR="/var/lib/sbopkg/SBo-danix" # Repository containing .info files
+HINT_DIR="/tmp/hintdir" # Directory where .hint files are stored
+```
+
+## Usage
+
+### Update an existing hint file
+
+Updates the package version, downloads the archive, and recalculates the MD5 checksums:
+
+```bash
+mkhintfile --version 2.0.1 --hintfile mypackage
+```
+
+This replaces the old version with 2.0.1 in mypackage.hint and re-downloads the URLs from DOWNLOAD and DOWNLOAD_x86_64 to update MD5SUM and MD5SUM_x86_64.
+
+### Create a new hint file from .info
+
+Generates a new hint file from the corresponding repository .info file:
+
+```bash
+mkhintfile --version 1.2.3 --new mypackage
+```
+
+The .info file is copied as a template, unwanted variables (PRGNAM, HOMEPAGE, MAINTAINER, EMAIL) are removed, and ARCH is set to x86_64.
+
+### Create an empty hint file
+
+Creates a fresh hint file with empty variables:
+
+```bash
+mkhintfile --new mypackage
+```
+
+### List hint files
+
+```bash
+mkhintfile --list
+```
+
+### Help
+
+```bash
+mkhintfile --help
+```
+
+## Exit Codes
+
+- 0 - Success
+- 1 - Invalid arguments
+- 2 - File not found
+- 3 - File already exists
+- 4 - wget not available
+
+## Hint File Variables
+
+- VERSION - Package version
+- ARCH - Architecture
+- DOWNLOAD - Download URL (generic/32-bit)
+- MD5SUM - MD5 checksum of the generic archive
+- DOWNLOAD_x86_64 - Download URL (x86_64 specific)
+- MD5SUM_x86_64 - MD5 checksum of the x86_64 archive
+
+## Notes
+
+- Old versions of hint files are backed up with a .bak extension before being modified.
+- If a download URL is set to UNSUPPORTED or UNTESTED, the link is skipped during update.
+- Bash completion for -f/--hintfile and -n/--new autocompletes package names from their respective directories.
diff --git a/mkhintfile.bash-completion b/mkhintfile.bash-completion
new file mode 100644
index 0000000..e217edf
--- /dev/null
+++ b/mkhintfile.bash-completion
@@ -0,0 +1,33 @@
+# bash completion for mkhintfile.sh
+# Install: sudo cp mkhintfile.bash-completion /etc/bash-completion.d/mkhintfile
+
+_mkhintfile_completions() {
+ local cur prev repo_dir hint_dir
+ _init_completion || return
+
+ repo_dir="/var/lib/sbopkg/SBo-danix"
+ hint_dir="/tmp/hintdir"
+
+ case "$prev" in
+ --new|-n)
+ local -a words=()
+ for f in "$repo_dir"/*.info; do
+ [[ -f "$f" ]] && words+=("$(basename "${f%.info}")")
+ done
+ COMPREPLY=($(compgen -W "${words[*]}" -- "$cur"))
+ ;;
+ --hintfile|-f)
+ local -a words=()
+ for f in "$hint_dir"/*.hint; do
+ [[ -f "$f" ]] && words+=("$(basename "${f%.hint}")")
+ done
+ COMPREPLY=($(compgen -W "${words[*]}" -- "$cur"))
+ ;;
+ # --version (no completion, raw text)
+ # --list, --help (no value completion, flags only)
+ *)
+ ;;
+ esac
+}
+
+complete -F _mkhintfile_completions mkhintfile.sh
diff --git a/mkhintfile.sh b/mkhintfile.sh
new file mode 100755
index 0000000..3b433b3
--- /dev/null
+++ b/mkhintfile.sh
@@ -0,0 +1,335 @@
+#!/bin/bash
+
+# mkhintfile.sh - Manage hint files for slackrepo scripts
+#
+# Usage:
+# ./mkhintfile.sh --version VERSION --hintfile FILE Update existing hint file
+# ./mkhintfile.sh --version VERSION --new FILE Create new hint file
+# ./mkhintfile.sh --new FILE Create new hint file (no version)
+# ./mkhintfile.sh --list List hint files
+# ./mkhintfile.sh --clean Remove .bak files from HINT_DIR
+# ./mkhintfile.sh --help Show this help
+
+set -e
+
+# Default configuration
+REPO_DIR="/var/lib/sbopkg/SBo-danix/"
+HINT_DIR="/etc/slackrepo/SBo-danix/hintfiles/"
+TMP_DIR="/tmp/mkhint"
+
+# create the temp dir if not existing
+if [[ ! -d $TMP_DIR ]]; then
+ mkdir $TMP_DIR
+fi
+
+# Variables
+VERSION=""
+HINT_FILE=""
+NEW_HINT_FILE=""
+COMMAND=""
+
+# Show help message
+show_help() {
+ cat <<EOF
+mkhintfile.sh - Manage hint files for slackrepo scripts
+
+Usage:
+ ./mkhintfile.sh --version VERSION --hintfile FILE Update existing hint file
+ ./mkhintfile.sh --version VERSION --new FILE Create new hint file
+ ./mkhintfile.sh --new FILE Create new hint file (no version)
+ ./mkhintfile.sh --list List hint files
+ ./mkhintfile.sh --clean Remove .bak files from HINT_DIR
+ ./mkhintfile.sh --help Show this help
+
+Options:
+ --version, -v VERSION New version string (required for --hintfile)
+ --hintfile, -f FILE Path to existing hint file (required with --version)
+ --new, -n FILE Create new hint file (required with --version or standalone)
+ --list, -l List all hint files in the default directory
+ --clean, -c Remove all .bak files from HINT_DIR
+ --help, -h Show this help message
+
+Hint files are stored in: $HINT_DIR
+Temporary files are stored in: $TMP_DIR
+
+Variables order in hint files:
+ VERSION, ARCH, DOWNLOAD, MD5SUM, DOWNLOAD_x86_64, MD5SUM_x86_64
+
+Exit codes:
+ 0 - Success
+ 1 - Invalid arguments or missing required options
+ 2 - File not found
+ 3 - File already exists
+ 4 - wget not available
+EOF
+}
+
+# List hint files
+list_hint_files() {
+ if [[ ! -d "$HINT_DIR" ]]; then
+ echo "Error: Hint directory does not exist: $HINT_DIR" >&2
+ exit 2
+ fi
+
+ echo "Hint files in: $HINT_DIR"
+ echo "======================================================="
+ printf "%-40s %10s %10s %-20s %s\n" "File" "HintVer" "SBOVer" "Category" "Created"
+ echo "-------------------------------------------------------"
+
+ local count=0
+ for file in "$HINT_DIR"/*.hint; do
+ if [[ -f "$file" ]]; then
+ local VER=$(grep "^VERSION" "$file" |cut -d '"' -f2)
+ local name=$(basename "$file")
+ local pkg="${name%.hint}"
+ local info_file
+ info_file=$(find "$REPO_DIR" -mindepth 2 -name "${pkg}.info" 2>/dev/null | head -1)
+ local SBO_VER=""
+ local category=""
+ if [[ -f "$info_file" ]]; then
+ SBO_VER=$(grep "^VERSION" "$info_file" | cut -d '"' -f2)
+ category=$(basename "$(dirname "$(dirname "$info_file")")")
+ fi
+ local date=$(stat -c "%y" "$file" | cut -d'.' -f1)
+ printf "%-40s %10s %10s %-20s %s\n" "$name" "$VER" "$SBO_VER" "$category" "$date"
+ count=$((count + 1))
+ fi
+ done
+
+ if [[ $count -eq 0 ]]; then
+ echo " (no hint files found)"
+ fi
+
+ echo "======================================================="
+ echo "Total: $count file(s)"
+}
+
+# Validate wget availability
+check_wget() {
+ if ! command -v wget &> /dev/null; then
+ echo "Error: wget is not installed. Please install wget first." >&2
+ exit 4
+ fi
+}
+
+# download files
+download_file() {
+ local url="$1"
+ local dlfile="${TMP_DIR}/download"
+
+ if [[ -f $dlfile ]]; then
+ rm $dlfile
+ fi
+
+ # Download the file
+ if [[ ! -z $1 ]]; then
+ wget -O "$dlfile" "$url" || return 1
+ fi
+
+ # calculate md5
+ local md5=$(md5sum "$dlfile" | awk '{print $1}')
+ rm $dlfile
+ echo $md5
+}
+
+# Create new hint file
+create_new_hint_file() {
+ cd $HINT_DIR
+ local file="$1"
+ local normalized_file="${file}"
+
+ if [[ "$file" != *.hint ]]; then
+ normalized_file="${file}.hint"
+ fi
+
+ # search repository for .info file
+ info=$(find $REPO_DIR -mindepth 2 -name ${normalized_file%.hint}.info)
+
+ # Check if file exists
+ if [[ ! -f "$normalized_file" ]]; then
+ # the hint file we want to create doesn't exists, so we can check
+ # the sbo repository for a .info file and use that as hint
+ if [[ -n $info ]]; then
+ cp $info $normalized_file
+ # remove unwanted lines from hint file
+ sed -i -e "/^PRGNAM=/d" \
+ -e "/^HOMEPAGE=/d" \
+ -e "/^MAINTAINER=/d" \
+ -e "/^EMAIL=/d" \
+ -e "s/^REQUIRES=/#REQUIRES=/" \
+ "${normalized_file}"
+
+ if grep -q '^ARCH=' $normalized_file; then
+ sed -i 's/^ARCH=.*/ARCH="x86_64"/' $normalized_file
+ else
+ echo 'ARCH="x86_64"' >> $normalized_file
+ fi
+
+ echo "generated $normalized_file from $(basename $info)."
+ echo "Check variables before using."
+ fi
+ else
+ echo "Hint file exists: $normalized_file" >&2
+ mv "$normalized_file" "${normalized_file}.bak"
+ echo "Backed up to: ${normalized_file}.bak" >&2
+ # Create new hint file with empty variables
+ cat > "$normalized_file" <<EOF
+VERSION=""
+ARCH="x86_64"
+DOWNLOAD=""
+MD5SUM=""
+DOWNLOAD_x86_64=""
+MD5SUM_x86_64=""
+EOF
+
+ echo "Created new hint file [EMPTY]: $normalized_file"
+
+ fi
+}
+
+# Update existing hint file
+update_hint_file() {
+ cd "$HINT_DIR"
+ local file="$1"
+ local new_version="$2"
+ local old_version=""
+
+ local normalized_file="${file}"
+
+ if [[ "$file" != *.hint ]]; then
+ normalized_file="${file}.hint"
+ fi
+
+ # Check if file exists
+ if [[ ! -f "$normalized_file" ]]; then
+ echo "Error: Hint file does not exist: $normalized_file" >&2
+ exit 2
+ fi
+
+ # Force backup as precaution before modifying
+ echo "Hint file exists: $normalized_file" >&2
+ cp "$normalized_file" "${normalized_file}.bak"
+ echo "Backed up to: ${normalized_file}.bak" >&2
+
+ # Extract current version from hint file
+ old_version=$(grep '^VERSION=' "$normalized_file" | sed 's/VERSION="//;s/"$//')
+
+ # Use sed for global replacement of OLD_VERSION in all variables
+ sed -i "s/${old_version}/${new_version}/g" "$normalized_file"
+
+ download=$(grep '^DOWNLOAD=' "$normalized_file" | sed 's/DOWNLOAD="//;s/"$//')
+ if [[ -n "$download" ]]; then
+ if [[ $download != "UNSUPPORTED" && $download != "UNTESTED" ]]; then
+ # we skip for unsupported or untested arch
+ sum=$(download_file ${download})
+ sed -i "/^MD5SUM=/s/MD5SUM=\"[^\"]*\"/MD5SUM=\"$sum\"/" "$normalized_file"
+ fi
+ fi
+
+ # we should repeat the check for x86_64 DOWNLOAD
+ download_x64=$(grep '^DOWNLOAD_x86_64=' "$normalized_file" | sed 's/DOWNLOAD_x86_64="//;s/"$//')
+ if [[ -n "$download_x64" ]]; then
+ if [[ $download_x64 != "UNSUPPORTED" && $download_x64 != "UNTESTED" ]]; then
+ # we skip for unsupported or untested arch
+ sum64=$(download_file ${download_x64})
+ sed -i "/^MD5SUM_x86_64=/s/MD5SUM_x86_64=\"[^\"]*\"/MD5SUM_x86_64=\"$sum64\"/" "$normalized_file"
+ fi
+ fi
+
+ hf=$(cat $normalized_file)
+ echo "Updated hint file: $normalized_file"
+ echo "=========================================="
+ echo -n "$hf"
+ echo; echo "=========================================="
+}
+
+# Clean .bak files from HINT_DIR
+clean_bak_files() {
+ if [[ ! -d "$HINT_DIR" ]]; then
+ echo "Error: Hint directory does not exist: $HINT_DIR" >&2
+ exit 2
+ fi
+
+ local count=0
+ for bakfile in "$HINT_DIR"/*.bak; do
+ if [[ -f "$bakfile" ]]; then
+ rm "$bakfile"
+ count=$((count + 1))
+ fi
+ done
+
+ echo "Removed $count .bak file(s) from $HINT_DIR"
+}
+
+# Main function
+main() {
+ # Parse command line arguments directly
+ while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --version|-v)
+ VERSION="$2"
+ shift 2
+ ;;
+ --hintfile|-f)
+ HINT_FILE="$2"
+ shift 2
+ ;;
+ --new|-n)
+ NEW_HINT_FILE="$2"
+ shift 2
+ ;;
+ --list|-l)
+ COMMAND="list"
+ shift
+ ;;
+ --clean|-c)
+ COMMAND="clean"
+ shift
+ ;;
+ --help|-h)
+ COMMAND="help"
+ shift
+ ;;
+ *)
+ echo "Unknown option: $1" >&2
+ show_help
+ exit 1
+ ;;
+ esac
+ done
+
+ if [[ -z "$COMMAND" ]]; then
+ # Default to update hint file if VERSION and HINT_FILE are provided
+ if [[ -n "$VERSION" && -n "$HINT_FILE" ]]; then
+ COMMAND="update"
+ elif [[ -n "$NEW_HINT_FILE" ]]; then
+ COMMAND="new"
+ fi
+ fi
+
+ case "$COMMAND" in
+ help)
+ show_help
+ ;;
+ list)
+ list_hint_files
+ ;;
+ clean)
+ clean_bak_files
+ ;;
+ update)
+ check_wget
+ update_hint_file "$HINT_FILE" "$VERSION"
+ ;;
+ new)
+ create_new_hint_file "$NEW_HINT_FILE"
+ ;;
+ *)
+ echo "Error: Unknown command: $COMMAND" >&2
+ show_help
+ exit 1
+ ;;
+ esac
+}
+
+main "$@"