From d22e4dc2ef153334bf3c0d3b57f609e14f26a07f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Feb 2024 16:46:34 -0500 Subject: switch to new, more general wordpress-config-info implementation this makes it very easy to read from the JSON and write out a new config and even includes the entire upstream config so that (1) you can check that you aren't overwriting changes from elsewhere; and (2) you preserve changes made manually. the whole thing is like editing a dns zone right. except it's your wordpress zone of authority. zone of user authority. it's the zone of presence authority. each machine represents a place for a human to be present!!! as such each machine represents a zone of authority for the human's machine resources including the symbolic designation resource which is the basis of currency transfer this zone of authority needs to transfer itself from seat to seat as a basic test of itself otherwise it lacks redundancy and cannot be trusted and cannot be a seat of authority at all so it must be vacatable to be stable like any position in a constitutional design which it is domain = bailiwick we need to extend the user agency into the full extent of the user bailiwick the user's domain of authority is their public key is the left-hand side of their hostname is the right-hand side of their ipv6 address thank you shiva the destroyer remembers eternally pretty nice framework for this stuff everything is in json if only everything json was in dns oh if only everything json was in dns (to the tune or tone of that jedspoemsongband song about being stranded in space) --- wordpress/wordpress-config-info | 134 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 121 insertions(+), 13 deletions(-) diff --git a/wordpress/wordpress-config-info b/wordpress/wordpress-config-info index 869fac9..5fedd74 100755 --- a/wordpress/wordpress-config-info +++ b/wordpress/wordpress-config-info @@ -2,17 +2,82 @@ set -e set -o pipefail -wp_config_get() +env_to_json() +{ + while read kv + do + set -- "${kv%%=*}" "${kv#*=}" + jq -cn '{ ($k): $v }' --arg k "$1" --arg v "$2" + done +} + +wp_config_export_assigns() +{ + set -- "$wp_config" + wp_config_get_assigns | + env_to_json | + jq -s '{filename: $fn, assigns: .}' --arg fn "$1" +} + +wp_config_export_source() +{ + set -- "$wp_config" + jq -n -s '{filename: $fn, data: $fdata}' --arg fn "$1" --rawfile fdata "$1" +} + +wp_config_export_defines() +{ + set -- "$wp_config" + wp_config_get_defines | + while read kv + do + set -- "${kv%%=*}" "${kv#*=}" + jq -cn '{ ($k): $v }' --arg k "$1" --arg v "$2" + done | jq -s '{filename: $fn, defines: .}' --arg fn "$1" +} + +wp_config_export_defines() +{ + set -- "$wp_config" + wp_config_get_defines | + env_to_json | + jq -s '{filename: $fn, defines: .}' --arg fn "$1" +} + +wp_config_export_all() +{ + ( + wp_config_export_defines "$@" && + wp_config_export_assigns "$@" && + wp_config_export_source "$@" + ) | jq -s add +} + +wp_config_get_defines() +{ + sed -e 's/\r//g' -ne \ + "s/^define *( *'\([^']*\)' *, *'\([^']*\)' *) *;.*$/\1=\2/p" \ + < "$wp_config" +} + +wp_config_get_define() { sed -e 's/\r//g' -ne \ "s/^define *( *'$1' *, *'\([^']*\)' *) *; *$/\1/p" \ < "$wp_config" } -wp_config_table_prefix_get() +wp_config_get_assign() { sed -e 's/\r//g' -ne \ - "s/^\$table_prefix *= *'\\([^']*\\)' *; *$/\\1/p" \ + "s/^\$${1} *= *'\\([^']*\\)' *; *$/\\1/p" \ + < "$wp_config" +} + +wp_config_get_assigns() +{ + sed -E -e 's/\r//g' -ne \ + "s/^[$]([a-zA-Z_][a-zA-Z_0-9]*) *= *'([^']*)' *; *$/\\1=\\2/p" \ < "$wp_config" } @@ -45,12 +110,13 @@ then prefix=/srv/ suffix=/public_html json='[ { site: $SITE, wordpress_config: . } ]' - for SITE in $prefix*$suffix + declare -a sites=( $prefix*$suffix ) + for SITE in "${sites[@]}" do SITE=${SITE%$suffix} SITE=${SITE#$prefix} - "$0" "$SITE" | - jq --arg SITE "$SITE" "$json" || continue + "$0" "$SITE" | jq --arg SITE "$SITE" "$json" || exit 7 + #"$0" "$SITE" || exit 7 done | jq -s add exit @@ -59,18 +125,60 @@ then exit -1 fi -find_wp_config "$1" +find_wp_config "$1" || exit 0 + +new_interface_to_old_interface() +{ + jq '.[] | .wordpress_config | {defines, assigns} | .' +} -db_name=$(wp_config_get DB_NAME) +new_interface_to_old_interface() +{ + jq '.[] | .wordpress_config | + { defines: .defines | add + , assigns: .assigns | add + } | + { db_host: .defines.DB_HOST + , db_user: .defines.DB_USER + , db_password: .defines.DB_PASSWORD + , db_name: .defines.DB_NAME + , table_prefix: .assigns.table_prefix + }' + } + +OLD_INTERFACE=y +if [ "$NEW_INTERFACE" ] +then + OLD_INTERFACE= +fi +if [ "$OLD_INTERFACE" ] +then + OLD_INTERFACE= NEW_INTERFACE=y "$0" "$@" | new_interface_to_old_interface + exit +fi + +wp_config_export_all | +jq --arg SITE "$1" '[ { site: $SITE, wordpress_config: . } ]' +exit + + + + + + + + + +exit +db_name=$(wp_config_get_define DB_NAME) [ "$db_name" ] -db_host=$(wp_config_get DB_HOST) +db_host=$(wp_config_get_define DB_HOST) [ "$db_host" ] -db_user=$(wp_config_get DB_USER) +db_user=$(wp_config_get_define DB_USER) [ "$db_user" ] -db_password=$(wp_config_get DB_PASSWORD) +db_password=$(wp_config_get_define DB_PASSWORD) [ "$db_password" ] -table_prefix=$(wp_config_table_prefix_get) - +table_prefix=$(wp_config_get_assign table_prefix) jq -n \ --arg h "$db_host" \ --arg u "$db_user" \ -- cgit v1.2.3