bfrg/restore

63 lines
1.7 KiB
Bash
Executable file

#!/usr/bin/env bash
# shellcheck shell=bash
# Copyright (C) 2022 Thorsten Schubert <tschubert@bafh.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -o nounset
set -o pipefail
set -o errexit
shopt -s lastpipe
[[ ${TRACE:-} ]] && set -o xtrace
# shellcheck disable=SC1091
source "$(dirname "${BASH_SOURCE[0]}")/bfrg"
# shellcheck disable=SC2034
LOG_FILE=${LOG_FILE:-${CACHE_BASE}/restore-${SCRIPT_EPOCH}.log}
verify_repair() {
local -r infile=${1}
require_command par2 || return 0
log 'attempting file verification'
command par2 repair -- "$infile"
}
decrypt_stdout() {
local -r infile=${1}
local -r ts=${infile%%.*}
mkdir -p "${ts}"
trap 'rmdir --ignore-fail-on-non-empty ${ts}' ERR SIGINT
log 'attempting file decryption and unpacking'
command gpg --decrypt -- "${infile}" | command "${COMPRESSOR_CMD[0]}" -d -- | command tar -C "${ts}" -xv --
}
(($# < 1)) && die "no input file specified"
readonly INFILE=${1}
init_logger
if ! verify_file_exists "${INFILE}"; then
die "cannot read file ${INFILE}"
fi
ensure_commands gpg tar "${COMPRESSOR_CMD[0]}"
verify_repair "${INFILE}"
decrypt_stdout "${INFILE}"
# vi: set ft=sh ts=4 sw=0 sts=-1 sr noet nosi tw=0 fdm=manual: