Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcupdate: beta version #790

Merged
merged 17 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 72 additions & 29 deletions usr/local/share/bastille/etcupdate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
tschettervictor marked this conversation as resolved.
Show resolved Hide resolved
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
;;
-f|--force)
FORCE=1
shift
;;
-*)
error_exit "Unknown option: \"${1}\""
-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
Expand All @@ -121,14 +159,19 @@ while [ "$#" -gt 0 ]; do
usage
else
TARGET="${1}"
RELEASE="${2}"
fi
if [ -z "${DRY_RUN}" ]; then
DRY_RUN=0
ACTION="${2}"
RELEASE="${3}"
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