summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@vps-18a7a2b7.vps.ovh.ca>2024-02-09 16:46:34 -0500
committerroot <root@vps-18a7a2b7.vps.ovh.ca>2024-02-09 16:46:34 -0500
commitd22e4dc2ef153334bf3c0d3b57f609e14f26a07f (patch)
tree7ce165d3ff6671289df3113c5dd3172d07aa3a5c
parentdeba08d9f7e29f0f988b5ebd03cfcb3305f842b4 (diff)
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)
-rwxr-xr-xwordpress/wordpress-config-info134
1 files 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 @@
2set -e 2set -e
3set -o pipefail 3set -o pipefail
4 4
5wp_config_get() 5env_to_json()
6{
7 while read kv
8 do
9 set -- "${kv%%=*}" "${kv#*=}"
10 jq -cn '{ ($k): $v }' --arg k "$1" --arg v "$2"
11 done
12}
13
14wp_config_export_assigns()
15{
16 set -- "$wp_config"
17 wp_config_get_assigns |
18 env_to_json |
19 jq -s '{filename: $fn, assigns: .}' --arg fn "$1"
20}
21
22wp_config_export_source()
23{
24 set -- "$wp_config"
25 jq -n -s '{filename: $fn, data: $fdata}' --arg fn "$1" --rawfile fdata "$1"
26}
27
28wp_config_export_defines()
29{
30 set -- "$wp_config"
31 wp_config_get_defines |
32 while read kv
33 do
34 set -- "${kv%%=*}" "${kv#*=}"
35 jq -cn '{ ($k): $v }' --arg k "$1" --arg v "$2"
36 done | jq -s '{filename: $fn, defines: .}' --arg fn "$1"
37}
38
39wp_config_export_defines()
40{
41 set -- "$wp_config"
42 wp_config_get_defines |
43 env_to_json |
44 jq -s '{filename: $fn, defines: .}' --arg fn "$1"
45}
46
47wp_config_export_all()
48{
49 (
50 wp_config_export_defines "$@" &&
51 wp_config_export_assigns "$@" &&
52 wp_config_export_source "$@"
53 ) | jq -s add
54}
55
56wp_config_get_defines()
57{
58 sed -e 's/\r//g' -ne \
59 "s/^define *( *'\([^']*\)' *, *'\([^']*\)' *) *;.*$/\1=\2/p" \
60 < "$wp_config"
61}
62
63wp_config_get_define()
6{ 64{
7 sed -e 's/\r//g' -ne \ 65 sed -e 's/\r//g' -ne \
8 "s/^define *( *'$1' *, *'\([^']*\)' *) *; *$/\1/p" \ 66 "s/^define *( *'$1' *, *'\([^']*\)' *) *; *$/\1/p" \
9 < "$wp_config" 67 < "$wp_config"
10} 68}
11 69
12wp_config_table_prefix_get() 70wp_config_get_assign()
13{ 71{
14 sed -e 's/\r//g' -ne \ 72 sed -e 's/\r//g' -ne \
15 "s/^\$table_prefix *= *'\\([^']*\\)' *; *$/\\1/p" \ 73 "s/^\$${1} *= *'\\([^']*\\)' *; *$/\\1/p" \
74 < "$wp_config"
75}
76
77wp_config_get_assigns()
78{
79 sed -E -e 's/\r//g' -ne \
80 "s/^[$]([a-zA-Z_][a-zA-Z_0-9]*) *= *'([^']*)' *; *$/\\1=\\2/p" \
16 < "$wp_config" 81 < "$wp_config"
17} 82}
18 83
@@ -45,12 +110,13 @@ then
45 prefix=/srv/ 110 prefix=/srv/
46 suffix=/public_html 111 suffix=/public_html
47 json='[ { site: $SITE, wordpress_config: . } ]' 112 json='[ { site: $SITE, wordpress_config: . } ]'
48 for SITE in $prefix*$suffix 113 declare -a sites=( $prefix*$suffix )
114 for SITE in "${sites[@]}"
49 do 115 do
50 SITE=${SITE%$suffix} 116 SITE=${SITE%$suffix}
51 SITE=${SITE#$prefix} 117 SITE=${SITE#$prefix}
52 "$0" "$SITE" | 118 "$0" "$SITE" | jq --arg SITE "$SITE" "$json" || exit 7
53 jq --arg SITE "$SITE" "$json" || continue 119 #"$0" "$SITE" || exit 7
54 done | 120 done |
55 jq -s add 121 jq -s add
56 exit 122 exit
@@ -59,18 +125,60 @@ then
59 exit -1 125 exit -1
60fi 126fi
61 127
62find_wp_config "$1" 128find_wp_config "$1" || exit 0
129
130new_interface_to_old_interface()
131{
132 jq '.[] | .wordpress_config | {defines, assigns} | .'
133}
63 134
64db_name=$(wp_config_get DB_NAME) 135new_interface_to_old_interface()
136{
137 jq '.[] | .wordpress_config |
138 { defines: .defines | add
139 , assigns: .assigns | add
140 } |
141 { db_host: .defines.DB_HOST
142 , db_user: .defines.DB_USER
143 , db_password: .defines.DB_PASSWORD
144 , db_name: .defines.DB_NAME
145 , table_prefix: .assigns.table_prefix
146 }'
147 }
148
149OLD_INTERFACE=y
150if [ "$NEW_INTERFACE" ]
151then
152 OLD_INTERFACE=
153fi
154if [ "$OLD_INTERFACE" ]
155then
156 OLD_INTERFACE= NEW_INTERFACE=y "$0" "$@" | new_interface_to_old_interface
157 exit
158fi
159
160wp_config_export_all |
161jq --arg SITE "$1" '[ { site: $SITE, wordpress_config: . } ]'
162exit
163
164
165
166
167
168
169
170
171
172exit
173db_name=$(wp_config_get_define DB_NAME)
65[ "$db_name" ] 174[ "$db_name" ]
66db_host=$(wp_config_get DB_HOST) 175db_host=$(wp_config_get_define DB_HOST)
67[ "$db_host" ] 176[ "$db_host" ]
68db_user=$(wp_config_get DB_USER) 177db_user=$(wp_config_get_define DB_USER)
69[ "$db_user" ] 178[ "$db_user" ]
70db_password=$(wp_config_get DB_PASSWORD) 179db_password=$(wp_config_get_define DB_PASSWORD)
71[ "$db_password" ] 180[ "$db_password" ]
72table_prefix=$(wp_config_table_prefix_get) 181table_prefix=$(wp_config_get_assign table_prefix)
73
74jq -n \ 182jq -n \
75 --arg h "$db_host" \ 183 --arg h "$db_host" \
76 --arg u "$db_user" \ 184 --arg u "$db_user" \