etcupdate: add resolve mode

This commit is contained in:
tschettervictor
2025-01-09 11:37:04 -07:00
committed by GitHub
parent 0d09ac9607
commit 9c79f138e7

View File

@@ -31,11 +31,13 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_notify "Usage: bastille etcupdate [option(s)] [TARGET|bootstrap] RELEASE"
error_notify "Usage: bastille etcupdate [option(s)] [bootstrap|TARGET] [update RELEASE|resolve]"
cat << EOF
Options:
-d | --dry-run Show output, but do not apply.
-f | --force Force a re-bootstrap of a RELEASE.
-x | --debug Enable debug mode.
EOF
exit 1
@@ -47,11 +49,9 @@ bootstrap_etc_release() {
if ls -A "${bastille_releasesdir}/${_release}/usr/src" 2>/dev/null; then
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_bootstrap_archives=src
if ! bastille bootstrap "${_release}"; then
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_bootstrap_archives="${_current}"
error_exit "Failed to bootstrap etcupdate \"${_release}\""
else
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_bootstrap_archives="${_current}"
error_notify "Failed to bootstrap etcupdate: ${_release}"
fi
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_bootstrap_archives="${_current}"
fi
}
@@ -62,50 +62,88 @@ bootstrap_etc_tarball() {
if ! etcupdate build -d /tmp/etcupdate -s ${bastille_releasesdir}/${_release}/usr/src ${bastille_cachedir}/${_release}.tbz2; then
error_exit "Failed to build etcupdate tarball \"${_release}.tbz2\""
else
info "Etcupdate bootstrap complete: \"${_release}\""
info "Etcupdate bootstrap complete: ${_release}"
fi
elif [ -f ${bastille_cachedir}/${_release}.tbz2 ] && [ "${FORCE}" -eq 1 ]; then
rm -f "${bastille_cachedir}/${_release}.tbz2"
echo "Building tarball, please wait..."
if ! etcupdate build -d /tmp/etcupdate -s ${bastille_releasesdir}/${_release}/usr/src ${bastille_cachedir}/${_release}.tbz2; then
error_exit "Failed to build etcupdate tarball \"${_release}.tbz2\""
else
info "Etcupdate bootstrap complete: ${_release}"
fi
else
info "Etcupdate release has already been prepared for application: \"${_release}\""
exit 0
info "Etcupdate release has already been prepared for application: ${_release}"
fi
}
resolve_conflicts() {
local _jail="${1}"
if [ "${DRY_RUN}" -eq 1 ]; then
info "[_jail]: --dry-run"
etcupdate resolve -n -D "${bastille_jailsdir}/${_jail}/root"
else
info "[_jail]:"
etcupdate resolve -D "${bastille_jailsdir}/${_jail}/root"
fi
}
update_jail_etc() {
local _jail="${1}"
local _release="${2}"
if [ ! -f ${bastille_cachedir}/${_release}.tbz2 ]; then
error_exit "Error: Please run \"bastille etcupdate bootstrap RELEASE\" first."
fi
if [ "${DRY_RUN}" -eq 1 ]; then
info "[_jail]: --dry-run"
etcupdate -n -D "${bastille_jailsdir}"/"${_jail}"/root -t ${bastille_cachedir}/${_release}.tbz2
etcupdate -n -D "${bastille_jailsdir}/${_jail}/root" -t ${bastille_cachedir}/${_release}.tbz2
else
info "[_jail]:"
etcupdate -D "${bastille_jailsdir}"/"${_jail}"/root -t ${bastille_cachedir}/${_release}.tbz2
etcupdate -D "${bastille_jailsdir}/${_jail}/root" -t ${bastille_cachedir}/${_release}.tbz2
fi
}
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
usage
fi
# Handle options.
DRY_RUN=0
FORCE=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-d|--dry-run)
if [ -z "${2}" ] || [ -z "${3}" ]; then
usage
else
DRY_RUN=1
shift
fi
DRY_RUN=1
shift
;;
-*)
error_exit "Unknown option: \"${1}\""
-f|--force)
FORCE=1
shift
;;
-x|--debug)
enable_debug
shift
;;
-*)
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
case ${_opt} in
d) DRY_RUN=1 ;;
f) FORCE=1 ;;
x) enable_debug ;;
*) error_exit "Unknown Option: \"${1}\"" ;;
esac
done
shift
;;
*)
break
;;
esac
done
# Main commands
while [ "$#" -gt 0 ]; do
case "${1}" in
bootstrap)
if [ -z "${2}" ]; then
usage
@@ -121,14 +159,19 @@ while [ "$#" -gt 0 ]; do
usage
else
TARGET="${1}"
RELEASE="${2}"
ACTION="${2}"
RELEASE="${3}"
fi
if [ -z "${DRY_RUN}" ]; then
DRY_RUN=0
fi
set_target_single "${TARGET}"
update_jail_etc "${TARGET}" "${RELEASE}"
shift "$#"
case "${ACTION}" in
resolve)
resolve_conflicts "${TARGET}"
shift "$#"
;;
update)
update_jail_etc "${TARGET}" "${RELEASE}"
shift "$#"
;;
esac
;;
esac
done