diff --git a/.pct-helpers b/.pct-helpers index 108aa1a..4c79715 100644 --- a/.pct-helpers +++ b/.pct-helpers @@ -302,33 +302,81 @@ xreadpass(){ } +# Like cat but a prettier... +# +# listFile PATH +# +listFile(){ + if [ -e "$1" ] ; then + echo "--- $1 ---" + cat "$1" + echo '---' + else + echo "$FUNCNAME: $1: No such file or directory." + return 1 + fi +} + + # Review changes in PATH.new, then edit/apply changes to PATH # -# reviewApplyChanges PATH +# reviewApplyChanges PATH [apply|edit|skip] +# # # NOTE: if changes are not applied this will return non-zero making this # usable in conditionals... reviewApplyChanges(){ local file=$1 + if ! [ -e "$file".new ] ; then + echo "$FUNCNAME: $1: No such file or directory." + return 1 + fi + + # default option... + local dfl= + local a=a + local e=e + local s=s + case "${2,,}" in + a|apply) + a=A + dfl=a + ;; + e|edit) + e=E + dfl=e + ;; + s|skip) + s=S + dfl=s + ;; + esac + echo "# Review updated: ${file}.new:" - @ cat ${file}.new - echo '---' + listFile ${file}.new local res while true ; do - read -ep "# [a]pply, [e]dit, [s]kip? " res + read -ep "# [$a]pply, [$e]dit, [$s]kip? " res + if [ -z $res ] ; then + if [ -z $dfl ] ; then + continue + fi + res=$dfl + fi case "${res,,}" in a|apply) break ;; e|edit) ${EDITOR} "${file}.new" + listFile ${file}.new ;; s|skip) - echo "# file saved as: ${file}.new" + echo "# Changes kept as: ${file}.new" return 1 ;; *) - echo "ERROR: unknown command: \"$res\"" >&2 + echo "ERROR: Unknown command: \"$res\"" >&2 continue ;; esac diff --git a/Makefile b/Makefile index 8c8e313..e14e455 100644 --- a/Makefile +++ b/Makefile @@ -95,26 +95,12 @@ bootstrap-clean: host-bootstrap-clean # Finalize: reconect admin port/bridge correctly... .PHONY: finalize finalize: gate-bootstrap-clean + # cleanup: stage 1... make host-bootstrap-clean + # cleanup: stage 2... make host-bootstrap-clean -#.PHONY: finalize -#finalize: -# ### -# ### This will break the connection to the server, to continue: -# ### - Detach the ADMIN port, -# ### - Connect the WAN port, -# ### - $ ssh @ -# ### from there: -# ### $ ssh root@pve -# ### then: -# ### # tmux a -# ### - When done this will reboot the system. -# ### -# tmux new-session 'make _finalize' - - #---------------------------------------------------------------------- # Shorthands... diff --git a/host/make.sh b/host/make.sh index 69634ac..fb77960 100755 --- a/host/make.sh +++ b/host/make.sh @@ -54,7 +54,7 @@ if ! [ -z $BOOTSTRAP_CLEAN ] ; then @ cp "$INTERFACES"{,.bak} __finalize(){ - if reviewApplyChanges "$INTERFACES" ; then + if reviewApplyChanges "$INTERFACES" apply ; then # XXX this must be done in nohup to avoid breaking on connection lost... if ! @ ifreload -a ; then # reset settings back if ifreload fails... @@ -213,7 +213,7 @@ if xreadYes "# Create bridges?" BRIDGES ; then fi # interfaces - if reviewApplyChanges "$INTERFACES" ; then + if reviewApplyChanges "$INTERFACES" apply ; then # XXX this must be done in nohup to avoid breaking on connection lost... if ! @ ifreload -a ; then # reset settings back if ifreload fails... @@ -231,7 +231,7 @@ if xreadYes "# Update /etc/hosts?" HOSTS ; then @ sed -i \ -e 's/^[^#].* \(pve.local.*\)$/'${HOST_ADMIN_IP/\/*}' \1/' \ /etc/hosts.new - reviewApplyChanges /etc/hosts + reviewApplyChanges /etc/hosts apply fi @@ -250,7 +250,7 @@ if xreadYes "# Update DNS?" DNS ; then build file=/etc/resolv.conf @ cp "staging/${file}" "${file}".new - reviewApplyChanges "${file}" + reviewApplyChanges "${file}" apply fi @@ -259,7 +259,7 @@ if xreadYes "# Update firewall rules?" FIREWALL ; then build file=/etc/pve/firewall/cluster.fw @ cp "staging/${file}" "${file}".new - reviewApplyChanges "${file}" + reviewApplyChanges "${file}" apply fi