#!/bin/bash
### This file is covered by the GNU General Public License
### version 3 or later.
###
### Copyright (C) 2021-2025, ALT Linux Team

#########################################
### Deployment System Profile Manager ###
#########################################

# Safety first
set -o errexit
set -o noglob
set -o nounset
set -o errtrace

# Temporary directory
export TMPDIR="${TMPDIR:-/tmp}"

# Full path to this script
readonly scriptname="$(realpath -- "$0")"

# Short name of this program
readonly progname="${scriptname##*/}"

# Supplemental sources: we need the ability to launch on site
if [ "$scriptname" = "/usr/bin/$progname" ]; then
	readonly libdir=/usr/libexec/system-restore
else
	readonly libdir="${scriptname%/*}"/sysrest
fi

# Internal variables
#
action=
baremetal=
catalog=
classid=
comment=
cpuarch=
datetime=
newname=
parent=
pci_bus=1
instance=
profile=
search=

# Backup directory on local file system
# (default is current working directory)
#
backup="$(realpath .)"

# Remote backup storage account information
backup_proto=file

# Default comment in shared profiles
shared_comment="This is a shared profile"

# Bootstrap
[ ! -s /etc/system-restore/profile.conf ] ||
	. /etc/system-restore/profile.conf
. "$libdir"/profile/hardware.sh
. "$libdir"/profile/common.sh
. "$libdir"/profile/parser.sh
. "$libdir"/profile/output.sh
. "$libdir"/profile/create.sh
. "$libdir"/profile/update.sh
. "$libdir"/profile/remove.sh
. "$libdir"/profile/search.sh

# Catch all unexpected errors
trap 'unexpected_error "${BASH_SOURCE[0]##*/}" "$LINENO"' ERR

# Entry point
parse_cmdline "$@"
detect_profile
umask 0022
"$action"

