diff options
Diffstat (limited to 'wordpress/export-json.bash')
-rw-r--r-- | wordpress/export-json.bash | 131 |
1 files changed, 45 insertions, 86 deletions
diff --git a/wordpress/export-json.bash b/wordpress/export-json.bash index d2ab8f3..7f5c5d3 100644 --- a/wordpress/export-json.bash +++ b/wordpress/export-json.bash | |||
@@ -1,59 +1,51 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | |||
3 | # This script allows bash to export environment | ||
4 | # variables as JSON. A list of environment | ||
5 | # variables and their values is exported as a | ||
6 | # single JSON object containing key-value mappings | ||
7 | # of JSON strings. It uses the external tool "jq" | ||
8 | # to parse string values # placed in jq's argument | ||
9 | # list by bash and then encode them as JSON string | ||
10 | # values. This is no accidental dependency. The jq | ||
11 | # program is the foundation of the trustworthiness | ||
12 | # of this code. If we were encoding JSON strings | ||
13 | # in bash (and not just encoding the JSON objects | ||
14 | # containing the strings) we would have to be a | ||
15 | # lot more careful. | ||
16 | |||
17 | # This is the simple code I wanted to replace: | ||
18 | # | 2 | # |
19 | # jq --arg SITE "$SITE" "$json" | 3 | # export_JSON <variables> |
20 | # jq -n \ | 4 | # |
21 | # --arg h "$db_host" \ | 5 | # Synopsis: |
22 | # --arg u "$db_user" \ | 6 | # |
23 | # --arg p "$db_password" \ | 7 | # $ ( |
24 | # --arg n "$db_name" \ | 8 | # source export-json.bash |
25 | # --arg t "$table_prefix" \ | 9 | # export_JSON SSH_TTY \ |
26 | # '{ db_host: $h | 10 | # SSH_CONNECTION \ |
27 | # , db_user: $u | 11 | # SSH_CLIENT \ |
28 | # , db_password: $p | 12 | # SSH_AUTH_SOCK |
29 | # , db_name: $n | 13 | # ) |
30 | # , table_prefix: $t | 14 | # { |
31 | # }' | 15 | # "SSH_TTY": "/dev/pts/0", |
16 | # "SSH_CONNECTION": "192.0.2.140 41564 198.51.100.25 22", | ||
17 | # "SSH_CLIENT": "192.0.2.140 41564 22", | ||
18 | # "SSH_AUTH_SOCK": "/tmp/ssh-XXXXcePKJl/agent.36326" | ||
19 | # } | ||
20 | # | ||
21 | # This bash function exports shell variables as | ||
22 | # JSON ("javascript object notation") strings. | ||
23 | # | ||
24 | # The string is printed to stdout. | ||
25 | # | ||
26 | # JSON is a format that represents data as | ||
27 | # Javascript source code so modern programmers | ||
28 | # can read it unlike bash source code. | ||
29 | # | ||
30 | # Variable names are given to the function as its | ||
31 | # argument list: | ||
32 | # | ||
33 | # $ (source export-json.bash; export_JSON PATH) | ||
32 | # | 34 | # |
33 | # The problem with the above is that the names are | 35 | # The output is a single JSON object containing |
34 | # repeated. | 36 | # key-value mappings between JSON strings: |
35 | # This creates the possibility that the names not | 37 | # |
36 | # match, creating a bug. | 38 | # { |
37 | # This code allows the names to be specified only | 39 | # "PATH": "/usr/local/sbin:[...]" |
38 | # one time. | 40 | # } |
39 | # It allows the bug where the names do not match | 41 | # |
40 | # to be fixed only one time by one person. | 42 | # It uses the external tool "jq" to parse string |
41 | # IF ... the fix can be distributed back to the | 43 | # values placed in jq's argument list by bash and |
42 | # extant copies. | 44 | # then encode them as JSON string values. This |
43 | # How to get the beneficial mutations | 45 | # is no accidental dependency. The jq program is |
44 | # back into the living organisms? | 46 | # the foundation of the trustworthiness of this |
45 | # Life tries not to answer this question | 47 | # code. If we were encoding JSON strings in bash |
46 | # until very late in its development | 48 | # we would have to be a lot more careful. |
47 | # since after all | ||
48 | # the extant copies are the past | ||
49 | # and life looks into the future | ||
50 | # But because consciousness | ||
51 | # is the mirror of time | ||
52 | # the question is asked | ||
53 | # eventually | ||
54 | # when that level | ||
55 | # of life | ||
56 | # consciousness is reached. | ||
57 | 49 | ||
58 | arg1_to_env0() | 50 | arg1_to_env0() |
59 | { | 51 | { |
@@ -136,36 +128,3 @@ runtest() | |||
136 | try export_JSON '' | 128 | try export_JSON '' |
137 | try export_JSON '' SSH_TTY | 129 | try export_JSON '' SSH_TTY |
138 | } | 130 | } |
139 | |||
140 | # Cryptography and routing needs to and does work like the benefits | ||
141 | # office where there is a fixed supply to hand out so there is a line | ||
142 | # of recipients waiting and in order to save resources there is a | ||
143 | # limit to its size and a residue of turnaways. So it is with tcp | ||
144 | # connections and in order for a service to minimize disruption to other | ||
145 | # tcp connections it need only limit the number of open connections it | ||
146 | # allows; understanding that the residue of turnaways will increase but | ||
147 | # the fixed supply will be delivered and the turnaways will re-enter the | ||
148 | # queue to receive belatedly. | ||
149 | # | ||
150 | # The connections in which we are interested are not TCP connections, | ||
151 | # they are VPN connections over UDP, but not really, they are social | ||
152 | # connections sustained through a software<->computer interface | ||
153 | # intermediary. | ||
154 | # | ||
155 | # The social program of Samizdat involves tending to the computers by | ||
156 | # interfacing with their USB ports and network ports, not their screens! | ||
157 | # The screen is used to seek user confirmation WITH DEfAULT TIMEOUT | ||
158 | # that makes Samizdat human-interaction-optional. Furthermore, Samizdat | ||
159 | # attempts to use the network to make human-interaction require no | ||
160 | # physical presence, but rather the human can interact from any one of | ||
161 | # their nodes that is live at the time! These identity-holding nodes | ||
162 | # hold SSH servers open on the internet AND thereby hold the personal | ||
163 | # cryptographic identity that YOU can most easily export and use on YOUR | ||
164 | # OWN servers. | ||
165 | # | ||
166 | # Anyway, we allow connectivity onto these machines in various ways, | ||
167 | # for example, the local network can take over the display if the user | ||
168 | # has never logged in, allowing to authorize the first install to disk | ||
169 | # on the machine without needing the machine to have a working display | ||
170 | # or input device. | ||
171 | |||