#!/usr/bin/env bash # Copyright (C) 2018 Luke Shumaker # Copyright (C) 2023-2024 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later declare -r NAME=osi-extract declare -r VERSION=20231023 set -euE install_prefix="$(realpath --logical --canonicalize-missing -- "${BASH_SOURCE[0]}/../..")" readonly install_prefix source "${install_prefix}/lib/osi.sh" source "${install_prefix}/lib/argparse.sh" main() { local arg_image= local arg_src= local arg_dst= opt_positional() { if (( $# != 3 )); then argparse:error "Expected 3 positional arguments, got %d: %s" "$#" "${*@Q}" return fi arg_image=$1 arg_src=$2 arg_dst=$(realpath -ms -- "$3") } argparse copy "$@" case "$opt_mode" in error) osi.sh:print "Try '%q --help' for more information" "${0##*/}" >&2 return $EXIT_INVALIDARGUMENT ;; version) osi.sh:print "%s (osi-tools) %s" "$NAME" "$VERSION" return $EXIT_SUCCESS ;; help) osi.sh:print 'Usage: sudo %s [OPTIONS] FILENAME.img IMAGE_SRC_DIR HOST_DST_DIR' "${0##*/}" osi.sh:print 'Operating System Image: Extract Files' echo osi.sh:print 'OPTIONS:' echo "${opt_flaghelp}" return $EXIT_SUCCESS ;; # main code starts here copy) local mountpoint mountpoint=$(mktemp -dt -- "${0##*/}.XXXXXXXXXX") trap "rmdir -- ${mountpoint@Q}" EXIT osi.sh:sudo -- "${install_prefix}/bin/osi-mount" --user -- "$arg_image" "$mountpoint" cp -aT -- "$mountpoint/$arg_src" "$arg_dst" ;; *) osi.sh:bug 'unknown opt_mode: %s' "$opt_mode";; esac } main "$@"