refactor: remove vendored binaries and raw assets from repo

This commit is contained in:
2026-06-08 09:03:04 +07:00
parent 1b19d5443d
commit 2ba402e9f9
3 changed files with 138 additions and 8 deletions

View File

@@ -43,6 +43,13 @@ scripts/setup-dcmtk.sh --source-dir /path/to/dcmtk/bin
scripts/setup-microdicom.sh --source-dir /path/to/microdicom scripts/setup-microdicom.sh --source-dir /path/to/microdicom
``` ```
Or download your hosted release assets directly:
```bash
scripts/setup-dcmtk.sh --archive-url https://github.com/<owner>/<repo>/releases/download/<tag>/dcmtk-bin.tar.gz
scripts/setup-microdicom.sh --archive-url https://github.com/<owner>/<repo>/releases/download/<tag>/microdicom.zip
```
Create a local config file from the template: Create a local config file from the template:
```bash ```bash

View File

@@ -4,29 +4,69 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
INSTALL_DIR="${INSTALL_DIR:-$ROOT_DIR/.local/dcmtk-bin}" INSTALL_DIR="${INSTALL_DIR:-$ROOT_DIR/.local/dcmtk-bin}"
REQUIRED_BINS=(storescp movescu storescu findscu dcmdump dcmodify getscu echoscu dcmj2pnm) REQUIRED_BINS=(storescp movescu storescu findscu dcmdump dcmodify getscu echoscu dcmj2pnm)
SOURCE_DIR=""
ARCHIVE_URL=""
TMP_DIR=""
usage() { usage() {
cat <<'EOF' cat <<'EOF'
Usage: Usage:
scripts/setup-dcmtk.sh [--source-dir DIR] [--install-dir DIR] scripts/setup-dcmtk.sh [--source-dir DIR | --archive-url URL] [--install-dir DIR]
Behavior: Behavior:
- Copies required DCMTK binaries into a local ignored directory. - Copies required DCMTK binaries into a local ignored directory.
- If --source-dir is omitted, binaries are resolved from PATH. - If --source-dir is omitted, binaries are resolved from PATH.
- If --archive-url is given, the script downloads and extracts an archive,
then searches for the required binaries inside it.
Examples: Examples:
scripts/setup-dcmtk.sh --source-dir /opt/dcmtk/bin scripts/setup-dcmtk.sh --source-dir /opt/dcmtk/bin
scripts/setup-dcmtk.sh --archive-url https://github.com/<owner>/<repo>/releases/download/<tag>/dcmtk-bin.tar.gz
scripts/setup-dcmtk.sh --install-dir /data/dcmtk-bin scripts/setup-dcmtk.sh --install-dir /data/dcmtk-bin
EOF EOF
} }
SOURCE_DIR="" download() {
local url="$1"
local out="$2"
if command -v curl >/dev/null 2>&1; then
curl -fL "$url" -o "$out"
elif command -v wget >/dev/null 2>&1; then
wget -O "$out" "$url"
else
echo "need curl or wget to download $url" >&2
exit 1
fi
}
extract_archive() {
local archive="$1"
local dest="$2"
case "$archive" in
*.tar.gz|*.tgz) tar -xzf "$archive" -C "$dest" ;;
*.tar.xz) tar -xJf "$archive" -C "$dest" ;;
*.tar) tar -xf "$archive" -C "$dest" ;;
*.zip)
command -v unzip >/dev/null 2>&1 || { echo "unzip is required for $archive" >&2; exit 1; }
unzip -q "$archive" -d "$dest"
;;
*)
echo "unsupported archive format: $archive" >&2
exit 1
;;
esac
}
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--source-dir) --source-dir)
SOURCE_DIR="${2:?missing value for --source-dir}" SOURCE_DIR="${2:?missing value for --source-dir}"
shift 2 shift 2
;; ;;
--archive-url)
ARCHIVE_URL="${2:?missing value for --archive-url}"
shift 2
;;
--install-dir) --install-dir)
INSTALL_DIR="${2:?missing value for --install-dir}" INSTALL_DIR="${2:?missing value for --install-dir}"
shift 2 shift 2
@@ -43,13 +83,36 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
if [[ -n "$SOURCE_DIR" && -n "$ARCHIVE_URL" ]]; then
echo "use only one of --source-dir or --archive-url" >&2
exit 1
fi
cleanup() {
[[ -n "$TMP_DIR" && -d "$TMP_DIR" ]] && rm -rf "$TMP_DIR"
}
trap cleanup EXIT
if [[ -n "$ARCHIVE_URL" ]]; then
TMP_DIR="$(mktemp -d)"
archive="$TMP_DIR/archive"
download "$ARCHIVE_URL" "$archive"
mkdir -p "$TMP_DIR/extracted"
mv "$archive" "$TMP_DIR/archive$(basename "$ARCHIVE_URL" | sed 's/.*\(\.[^.][^.]*\)$/\1/')" 2>/dev/null || true
archive_path="$(find "$TMP_DIR" -maxdepth 1 -type f | head -n 1)"
extract_archive "$archive_path" "$TMP_DIR/extracted"
SOURCE_DIR="$TMP_DIR/extracted"
fi
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
resolve_bin() { resolve_bin() {
local name="$1" local name="$1"
if [[ -n "$SOURCE_DIR" ]]; then if [[ -n "$SOURCE_DIR" ]]; then
local candidate="$SOURCE_DIR/$name" local candidate
[[ -x "$candidate" ]] || { echo "missing executable: $candidate" >&2; return 1; } candidate="$(find "$SOURCE_DIR" -type f -name "$name" -perm -u+x | head -n 1 || true)"
[[ -n "$candidate" ]] || candidate="$(find "$SOURCE_DIR" -type f -name "$name" | head -n 1 || true)"
[[ -n "$candidate" ]] || { echo "missing binary in source: $name" >&2; return 1; }
printf '%s\n' "$candidate" printf '%s\n' "$candidate"
return 0 return 0
fi fi

View File

@@ -3,25 +3,66 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
INSTALL_DIR="${INSTALL_DIR:-$ROOT_DIR/.local/microdicom}" INSTALL_DIR="${INSTALL_DIR:-$ROOT_DIR/.local/microdicom}"
SOURCE_DIR=""
ARCHIVE_URL=""
TMP_DIR=""
usage() { usage() {
cat <<'EOF' cat <<'EOF'
Usage: Usage:
scripts/setup-microdicom.sh --source-dir DIR [--install-dir DIR] scripts/setup-microdicom.sh [--source-dir DIR | --archive-url URL] [--install-dir DIR]
Behavior: Behavior:
- Copies a prepared MicroDicom directory into a local ignored directory. - Copies a prepared MicroDicom directory into a local ignored directory.
- Expected source contents include files like AUTORUN.INF, RUN.BAT, and MICROD/. - With --archive-url, downloads and extracts an archive, then searches for
a directory containing AUTORUN.INF and MICROD/.
Example:
scripts/setup-microdicom.sh --archive-url https://github.com/<owner>/<repo>/releases/download/<tag>/microdicom.zip
EOF EOF
} }
SOURCE_DIR="" download() {
local url="$1"
local out="$2"
if command -v curl >/dev/null 2>&1; then
curl -fL "$url" -o "$out"
elif command -v wget >/dev/null 2>&1; then
wget -O "$out" "$url"
else
echo "need curl or wget to download $url" >&2
exit 1
fi
}
extract_archive() {
local archive="$1"
local dest="$2"
case "$archive" in
*.tar.gz|*.tgz) tar -xzf "$archive" -C "$dest" ;;
*.tar.xz) tar -xJf "$archive" -C "$dest" ;;
*.tar) tar -xf "$archive" -C "$dest" ;;
*.zip)
command -v unzip >/dev/null 2>&1 || { echo "unzip is required for $archive" >&2; exit 1; }
unzip -q "$archive" -d "$dest"
;;
*)
echo "unsupported archive format: $archive" >&2
exit 1
;;
esac
}
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--source-dir) --source-dir)
SOURCE_DIR="${2:?missing value for --source-dir}" SOURCE_DIR="${2:?missing value for --source-dir}"
shift 2 shift 2
;; ;;
--archive-url)
ARCHIVE_URL="${2:?missing value for --archive-url}"
shift 2
;;
--install-dir) --install-dir)
INSTALL_DIR="${2:?missing value for --install-dir}" INSTALL_DIR="${2:?missing value for --install-dir}"
shift 2 shift 2
@@ -38,7 +79,26 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
[[ -n "$SOURCE_DIR" ]] || { echo "--source-dir is required" >&2; exit 1; } if [[ -n "$SOURCE_DIR" && -n "$ARCHIVE_URL" ]]; then
echo "use only one of --source-dir or --archive-url" >&2
exit 1
fi
cleanup() {
[[ -n "$TMP_DIR" && -d "$TMP_DIR" ]] && rm -rf "$TMP_DIR"
}
trap cleanup EXIT
if [[ -n "$ARCHIVE_URL" ]]; then
TMP_DIR="$(mktemp -d)"
archive="$TMP_DIR/$(basename "$ARCHIVE_URL")"
download "$ARCHIVE_URL" "$archive"
mkdir -p "$TMP_DIR/extracted"
extract_archive "$archive" "$TMP_DIR/extracted"
SOURCE_DIR="$(find "$TMP_DIR/extracted" -type f -name AUTORUN.INF -printf '%h\n' | head -n 1 || true)"
fi
[[ -n "$SOURCE_DIR" ]] || { echo "one of --source-dir or --archive-url is required" >&2; exit 1; }
[[ -d "$SOURCE_DIR" ]] || { echo "source directory does not exist: $SOURCE_DIR" >&2; exit 1; } [[ -d "$SOURCE_DIR" ]] || { echo "source directory does not exist: $SOURCE_DIR" >&2; exit 1; }
[[ -f "$SOURCE_DIR/AUTORUN.INF" ]] || { echo "missing AUTORUN.INF in source directory" >&2; exit 1; } [[ -f "$SOURCE_DIR/AUTORUN.INF" ]] || { echo "missing AUTORUN.INF in source directory" >&2; exit 1; }
[[ -d "$SOURCE_DIR/MICROD" ]] || { echo "missing MICROD/ in source directory" >&2; exit 1; } [[ -d "$SOURCE_DIR/MICROD" ]] || { echo "missing MICROD/ in source directory" >&2; exit 1; }