#!/bin/sh

scriptversion="4"

me=$0
version="$me v$scriptversion

Copyright (C) 2025-2026 vx-clutch.
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law."

usage="\
Usage: $me [OPTION]... <version> <dir>
Micro Releaser

Options:
   --help     print this help and exit
   --version  output version information
"

while [ $# -gt 0 ]; do
  case $1 in
    --help) echo "$usage"; exit 0 ;;
    --version) echo "$version"; exit 0 ;;
    --*) echo "$me: Unknown option '$1'." >&2; exit 1 ;;
    *) break ;;
  esac
done

[ $# -eq 2 ] || { echo "$me: missing <version> <dir>" >&2; exit 1; }

version_name=$1
src_dir=$2

[ -d "$src_dir" ] || { echo "$me: '$src_dir' is not a directory" >&2; exit 1; }

case $version_name in
  */*|"") echo "$me: invalid version name" >&2; exit 1 ;;
esac

tarball=$version_name.tar.gz

(
  cd "$src_dir" || exit
  git ls-files |
    tar -czf "$tarball" \
      --transform="s,^,$version_name/," \
      -T -
)

if [ "$src_dir" = "." ]; then
  src_dir=$(basename "$(realpath "$src_dir")")
fi

printf "'%s' -> '%s'\n" "$src_dir" "$tarball"

# ures
#
# MIT/X Consortium License
# 
# © 2025-2026 vx-clutch
# 
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Project repository: https://git.vxserver.dev/vx-clutch/ures
