2018-08-10 00:22:41 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-08-18 18:42:42 +00:00
|
|
|
# Copyright (C) 2018 Luke Shumaker
|
2024-02-13 07:05:48 +00:00
|
|
|
# Copyright (C) 2023-2024 Umorpha Systems
|
2018-08-18 18:42:42 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-10-23 22:22:04 +00:00
|
|
|
declare -r NAME=osi-extract
|
|
|
|
declare -r VERSION=20231023
|
2018-08-11 18:57:24 +00:00
|
|
|
|
2023-10-23 22:22:04 +00:00
|
|
|
set -euE
|
2024-01-04 22:16:23 +00:00
|
|
|
|
|
|
|
install_prefix="$(realpath --logical --canonicalize-missing -- "${BASH_SOURCE[0]}/../..")"
|
|
|
|
readonly install_prefix
|
|
|
|
|
|
|
|
source "${install_prefix}/lib/osi.sh"
|
2024-02-14 03:00:05 +00:00
|
|
|
source "${install_prefix}/lib/argparse.sh"
|
2018-08-10 00:22:41 +00:00
|
|
|
|
2023-10-23 22:22:04 +00:00
|
|
|
main() {
|
|
|
|
local arg_image=
|
|
|
|
local arg_src=
|
|
|
|
local arg_dst=
|
2024-02-14 03:00:05 +00:00
|
|
|
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
|
2023-10-25 10:59:35 +00:00
|
|
|
error)
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print "Try '%q --help' for more information" "${0##*/}" >&2
|
2023-10-25 10:59:35 +00:00
|
|
|
return $EXIT_INVALIDARGUMENT
|
|
|
|
;;
|
2023-10-23 22:22:04 +00:00
|
|
|
version)
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print "%s (osi-tools) %s" "$NAME" "$VERSION"
|
2023-10-25 10:59:35 +00:00
|
|
|
return $EXIT_SUCCESS
|
2023-10-23 22:22:04 +00:00
|
|
|
;;
|
2024-02-14 03:00:05 +00:00
|
|
|
help)
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print 'Usage: sudo %s [OPTIONS] FILENAME.img IMAGE_SRC_DIR HOST_DST_DIR' "${0##*/}"
|
|
|
|
osi.sh:print 'Operating System Image: Extract Files'
|
2023-10-23 22:22:04 +00:00
|
|
|
echo
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print 'OPTIONS:'
|
2024-02-14 03:00:05 +00:00
|
|
|
echo "${opt_flaghelp}"
|
2023-10-25 10:59:35 +00:00
|
|
|
return $EXIT_SUCCESS
|
2023-10-23 22:22:04 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
# main code starts here
|
|
|
|
copy)
|
|
|
|
local mountpoint
|
|
|
|
mountpoint=$(mktemp -dt -- "${0##*/}.XXXXXXXXXX")
|
|
|
|
trap "rmdir -- ${mountpoint@Q}" EXIT
|
|
|
|
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:sudo -- "${install_prefix}/bin/osi-mount" --user -- "$arg_image" "$mountpoint" cp -aT -- "$mountpoint/$arg_src" "$arg_dst"
|
2023-10-23 22:22:04 +00:00
|
|
|
;;
|
2024-02-14 03:00:05 +00:00
|
|
|
|
2024-02-13 07:02:50 +00:00
|
|
|
*) osi.sh:bug 'unknown opt_mode: %s' "$opt_mode";;
|
2023-10-23 22:22:04 +00:00
|
|
|
esac
|
2018-08-10 00:22:41 +00:00
|
|
|
}
|
2023-10-23 22:22:04 +00:00
|
|
|
|
|
|
|
main "$@"
|