#!/bin/sh

# SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
# SPDX-License-Identifier: LGPL-3.0-or-later

set -e

action=$1
input=$2
output=$3

case "$action" in
download)
    if ! command -v wget >/dev/null 2>&1; then
        echo "wget not found, please install wget first" >&2
        exit 1
    fi

    wget "$input" -O "$output"
    ;;
materialize)
    if ! command -v tar >/dev/null 2>&1; then
        echo "tar not found, please install tar first" >&2
        exit 1
    fi

    mkdir "$output"
    tar --no-same-owner -xf "$input" -C "$output"
    ;;
*)
    echo "unsupported archive source action: $action" >&2
    exit 1
    ;;
esac
