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
|
2023-10-23 22:22:04 +00:00
|
|
|
# Copyright (C) 2023 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
|
|
|
|
source ./lib/osi.sh
|
2018-08-10 00:22:41 +00:00
|
|
|
|
2023-10-23 22:22:04 +00:00
|
|
|
main() {
|
|
|
|
local arg_mode=copy
|
|
|
|
local arg_image=
|
|
|
|
local arg_src=
|
|
|
|
local arg_dst=
|
2018-08-10 00:22:41 +00:00
|
|
|
|
2023-10-23 22:22:04 +00:00
|
|
|
local args
|
|
|
|
if ! args="$(getopt -n "${0##*/}" -o 'hV' -l 'help,version' -- "$@")"; then
|
|
|
|
arg_mode=error
|
|
|
|
else
|
|
|
|
eval "set -- $args"
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-V|--version) shift; arg_mode=version;;
|
|
|
|
-h|--help) shift; arg_mode=usage;;
|
|
|
|
--) shift; break;;
|
2023-10-25 10:59:35 +00:00
|
|
|
*) error $EXIT_FAILURE 'Internal error. The programmer writing this tool screwed up.';;
|
2023-10-23 22:22:04 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
case "$arg_mode" in
|
|
|
|
copy)
|
|
|
|
if (( $# != 3 )); then
|
|
|
|
if (( $# == 0 )); then
|
|
|
|
error 0 "Expected 1 positional argument, got none"
|
|
|
|
else
|
|
|
|
error 0 "Expected 1 positional argument, got %d: %s" "$#" "${*@Q}"
|
|
|
|
fi
|
|
|
|
arg_mode=error
|
|
|
|
fi
|
|
|
|
|
|
|
|
arg_image=$1
|
2023-10-23 22:29:14 +00:00
|
|
|
arg_src=$2
|
|
|
|
arg_dst=$(realpath -ms -- "$3")
|
2023-10-23 22:22:04 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
case "$arg_mode" in
|
2023-10-25 10:59:35 +00:00
|
|
|
error)
|
|
|
|
print "Try '%q --help' for more information" "${0##*/}" >&2
|
|
|
|
return $EXIT_INVALIDARGUMENT
|
|
|
|
;;
|
2023-10-23 22:22:04 +00:00
|
|
|
version)
|
|
|
|
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
|
|
|
;;
|
|
|
|
usage)
|
|
|
|
print 'Usage: sudo %s [OPTIONS] FILENAME.img IMAGE_SRC_DIR HOST_DST_DIR' "${0##*/}"
|
|
|
|
print 'Operating System Image: Extract Files'
|
|
|
|
echo
|
|
|
|
print 'OPTIONS:'
|
|
|
|
print ' -h, --help display this help'
|
|
|
|
print ' -V, --version output version information'
|
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
|
|
|
|
|
|
|
|
sudo -- ./osi-mount --user -- "$arg_image" "$mountpoint" cp -aT -- "$mountpoint/$arg_src" "$arg_dst"
|
|
|
|
;;
|
|
|
|
esac
|
2018-08-10 00:22:41 +00:00
|
|
|
}
|
2023-10-23 22:22:04 +00:00
|
|
|
|
|
|
|
main "$@"
|