@dotpi/tools 1.4.0 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/NOTES.md +41 -1
  2. package/README.md +3 -13
  3. package/dotpi_root/bin/dotpi +1 -0
  4. package/dotpi_root/bin/dotpi_prepare_sd_card +34 -22
  5. package/dotpi_root/bin/dotpi_prepare_system +108 -68
  6. package/dotpi_root/bin/package.json +6 -0
  7. package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor.service +1 -5
  8. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_install +21 -0
  9. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_uninstall +17 -0
  10. package/dotpi_root/dist/@dotpi/avahi_monitor/package.json +10 -0
  11. package/dotpi_root/dist/@dotpi/javascript/bash.js +103 -0
  12. package/dotpi_root/dist/@dotpi/javascript/echo.js +13 -0
  13. package/dotpi_root/dist/@dotpi/javascript/filesystem.js +25 -0
  14. package/dotpi_root/dist/@dotpi/javascript/package.json +12 -0
  15. package/dotpi_root/dist/@dotpi/javascript/service.js +49 -0
  16. package/dotpi_root/dist/@dotpi/javascript/system.js +36 -0
  17. package/dotpi_root/dist/@dotpi/javascript/template.js +13 -0
  18. package/dotpi_root/dist/@dotpi/javascript/user.js +32 -0
  19. package/dotpi_root/dist/@dotpi/module/bin/dotpi_module +13 -0
  20. package/dotpi_root/dist/@dotpi/module/dotpi_install +52 -0
  21. package/dotpi_root/dist/@dotpi/module/dotpi_uninstall +50 -0
  22. package/dotpi_root/dist/@dotpi/module/package.json +21 -0
  23. package/dotpi_root/dist/@dotpi/module/src/configuration.js +43 -0
  24. package/dotpi_root/dist/@dotpi/module/src/createConfig.js +108 -0
  25. package/dotpi_root/dist/@dotpi/module/src/definition.js +7 -0
  26. package/dotpi_root/dist/@dotpi/module/src/index.js +0 -0
  27. package/dotpi_root/dist/@dotpi/module/src/install.js +145 -0
  28. package/dotpi_root/dist/@dotpi/module/src/uninstall.js +180 -0
  29. package/dotpi_root/etc/dotpi_environment_default.bash +16 -0
  30. package/dotpi_root/etc/dotpi_init.d/.gitkeep +0 -0
  31. package/dotpi_root/etc/dotpi_modules.json +8 -0
  32. package/dotpi_root/lib/package.json +6 -0
  33. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +7 -6
  34. package/dotpi_root/share/dotpi_audio_bluetooth/package.json +6 -0
  35. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +12 -26
  36. package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +2 -2
  37. package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +6 -2
  38. package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +11 -0
  39. package/dotpi_root/share/dotpi_functions/dotpi_functions_user.bash +28 -0
  40. package/dotpi_root/share/dotpi_functions.bash +4 -4
  41. package/dotpi_root/share/dotpi_init.bash +7 -1
  42. package/dotpi_root/share/dotpi_pipewire/bin/dotpi_pipewire_relink +7 -6
  43. package/dotpi_root/share/dotpi_pipewire/dotpi_install +1 -1
  44. package/dotpi_root/share/dotpi_pipewire/package.json +9 -0
  45. package/dotpi_root/share/limits/zzz_dotpi_audio.conf +2 -6
  46. package/dotpi_root/share/wireplumber/wireplumber.conf.d/dotpi-wireplumber-config.conf +8 -0
  47. package/lerna.json +4 -0
  48. package/package.json +12 -2
  49. package/projects/led-test/.dotpi +3 -0
  50. package/projects/led-test/README.md +16 -0
  51. package/projects/led-test/dotpi_project.bash +29 -0
  52. package/projects/qsddsqsd/.dotpi +3 -0
  53. package/projects/qsddsqsd/README.md +16 -0
  54. package/projects/qsddsqsd/dotpi_project.bash +29 -0
  55. package/src/constants.js +4 -4
  56. package/src/create-project.js +124 -56
  57. package/src/templates/dotpi_project.bash +5 -7
  58. package/src/utils.js +2 -2
  59. package/test/create-project.test.js +0 -1
  60. package/PIPEWIRE.md +0 -280
  61. package/dotpi_root/bin/.editorbackup/dotpi_firstrun.bash~ +0 -149
  62. package/dotpi_root/bin/.editorbackup/dotpi_firstrun~ +0 -177
  63. package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card.bash~ +0 -425
  64. package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card~ +0 -620
  65. package/dotpi_root/bin/.editorbackup/dotpi_prepare_system.bash~ +0 -82
  66. package/dotpi_root/bin/.editorbackup/dotpi_prepare_system~ +0 -100
  67. package/dotpi_root/bin/.editorbackup/dotpi~ +0 -61
  68. package/dotpi_root/bin/.editorbackup/prepare_sd_card.bash~ +0 -252
  69. package/dotpi_root/etc/.editorbackup/dotpi_environment_default.bash~ +0 -49
  70. package/dotpi_root/etc/.editorbackup/dotpi_environment_instance.bash~ +0 -1
  71. package/dotpi_root/etc/.editorbackup/dotpi_environment_project.bash~ +0 -33
  72. package/dotpi_root/etc/.editorbackup/dotpi_tarignore~ +0 -4
  73. package/dotpi_root/share/.editorbackup/coucou~ +0 -1
  74. package/dotpi_root/share/.editorbackup/dotpi_environment.bash~ +0 -9
  75. package/dotpi_root/share/.editorbackup/dotpi_functions.bash~ +0 -11
  76. package/dotpi_root/share/.editorbackup/dotpi_functions_configuration.bash~ +0 -420
  77. package/dotpi_root/share/.editorbackup/dotpi_functions_connection.bash~ +0 -358
  78. package/dotpi_root/share/.editorbackup/dotpi_init.bash~ +0 -18
  79. package/dotpi_root/share/dotpi_audio_alsa/dotpi_audio_alsa.service +0 -15
  80. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth.service~ +0 -24
  81. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_command~ +0 -80
  82. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_start_command~ +0 -26
  83. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_stop_command~ +0 -30
  84. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_bluetooth_audio.service~ +0 -21
  85. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_bluetooth.bash~ +0 -256
  86. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_device.bash~ +0 -287
  87. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_bluetooth_audio.bash~ +0 -7
  88. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_configuration.bash~ +0 -428
  89. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_connection.bash~ +0 -194
  90. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_daemon.bash~ +0 -26
  91. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcard.bash~ +0 -287
  92. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcards.bash~ +0 -12
  93. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_system.bash~ +0 -158
  94. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_utils.bash~ +0 -152
  95. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_bluetooth.bash~ +0 -20
  96. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_command~ +0 -17
  97. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_headphones.bash~ +0 -20
  98. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_hifiberry.bash~ +0 -16
  99. package/dotpi_root/share/jackd/.editorbackup/jackd.conf~ +0 -5
  100. package/dotpi_root/share/jackd/.editorbackup/jackd.service~ +0 -15
  101. package/dotpi_root/share/jackd/.editorbackup/jackd_headphones.conf~ +0 -5
  102. package/dotpi_root/share/jackd/dotpi_jack_simple_client.service +0 -23
  103. package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +0 -18
  104. package/dotpi_root/share/jackd/dotpi_jackd_command +0 -26
  105. package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +0 -21
  106. package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +0 -17
  107. package/dotpi_root/share/jackd/jackd.service +0 -22
  108. package/dotpi_root/share/wireplumber/.editorbackup/8zzz-dotpi-wireplumber-config.lua~ +0 -1
  109. package/projects/old/dev.bak/.editorbackup/dotpi_environment_instance.bash~ +0 -1
  110. package/projects/old/dev.bak/.editorbackup/dotpi_environment_project.bash~ +0 -33
  111. package/projects/old/dev.bak/.editorbackup/wpa_supplicant.conf~ +0 -37
  112. package/projects/old/dev.bak/dotpi_environment_instance.bash +0 -1
  113. package/projects/old/dev.bak/dotpi_environment_project.bash +0 -46
  114. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI-A114.nmconnection~ +0 -24
  115. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI.nmconnection~ +0 -24
  116. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +0 -24
  117. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/onze.nmconnection~ +0 -22
  118. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/welcome.nmconnection~ +0 -23
  119. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI-A114.nmconnection +0 -23
  120. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI.nmconnection +0 -23
  121. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/Livebox-97C6_wifi_invite.nmconnection +0 -24
  122. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/onze.nmconnection +0 -24
  123. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/welcome.nmconnection +0 -23
  124. package/projects/old/dev.bak/network/.editorbackup/DOTPI-A114.nmconnection~ +0 -24
  125. package/projects/old/dev.bak/network/.editorbackup/DOTPI.nmconnection~ +0 -24
  126. package/projects/old/dev.bak/network/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +0 -24
  127. package/projects/old/dev.bak/network/.editorbackup/onze.nmconnection~ +0 -22
  128. package/projects/old/dev.bak/network/.editorbackup/welcome.nmconnection~ +0 -23
  129. package/projects/old/dev.bak/network/AccueilCie.nmconnection +0 -24
  130. package/projects/old/dev.bak/network/DOTPI-A114.nmconnection +0 -23
  131. package/projects/old/dev.bak/network/DOTPI.nmconnection +0 -23
  132. package/projects/old/dev.bak/network/Livebox-97C6_wifi_invite.nmconnection +0 -25
  133. package/projects/old/dev.bak/network/onze.nmconnection +0 -24
  134. package/projects/old/dev.bak/network/welcome.nmconnection +0 -23
  135. package/projects/old/dev.bak/network/wifi-access-point.nmconnection +0 -23
  136. package/projects/old/dev.bak/network/wifi-internet.nmconnection +0 -24
  137. package/projects/old/dev.bak/network/wifi-ircam-public.nmconnection +0 -24
  138. package/projects/old/dev.bak/network/wifi-local.nmconnection +0 -22
  139. package/projects/old/dev.bak/network/wifi-welcome.nmconnection +0 -24
  140. package/projects/old/dev.bak/wpa_supplicant.conf +0 -43
  141. package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_instance.bash~ +0 -1
  142. package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_project.bash~ +0 -26
  143. package/projects/old/example-complete.bak/.editorbackup/dotpi_project.bash~ +0 -21
  144. package/projects/old/example-complete.bak/.editorbackup/dotpi_tmp.bash~ +0 -3
  145. package/projects/old/example-complete.bak/.editorbackup/wpa_supplicant.conf~ +0 -37
  146. package/projects/old/example-complete.bak/configuration/.editorbackup/dotpi_project.bash~ +0 -21
  147. package/projects/old/example-complete.bak/configuration/dotpi_project.bash +0 -21
  148. package/projects/old/example-complete.bak/configuration/jackd/.editorbackup/dotpi_jackd.bash~ +0 -14
  149. package/projects/old/example-complete.bak/configuration/jackd/dotpi_jackd.bash +0 -14
  150. /package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor_command +0 -0
@@ -1,420 +0,0 @@
1
- _dotpi_configuration_get_options() {
2
-
3
- _echo_empty_option_error() {
4
- dotpi_echo_error "$1 requires a non-empty option argument."
5
- }
6
-
7
- # From http://mywiki.wooledge.org/BashFAQ/035
8
-
9
- while true ; do
10
- case $1 in
11
-
12
- -h|-\?|--help)
13
- _dotpi_usage # Display a usage synopsis.
14
- return 0
15
- ;;
16
-
17
- -f|--file) # Takes an option argument; ensure it has been specified.
18
- if [ -z "$2" ] ; then
19
- _dotpi_usage
20
- _echo_empty_option_error "$1"
21
- return 1
22
- else
23
- file="$2"
24
- shift
25
- fi
26
- ;;
27
-
28
- -k|--key)
29
- if [ -z "$2" ] ; then
30
- _dotpi_usage
31
- _echo_empty_option_error "$1"
32
- return 1
33
- else
34
- key="$2"
35
- shift
36
- fi
37
- ;;
38
-
39
- -p|--prefix)
40
- if [ -z "$2" ] ; then
41
- _dotpi_usage
42
- _echo_empty_option_error "$1"
43
- return 1
44
- else
45
- prefix="$2"
46
- shift
47
- fi
48
- ;;
49
-
50
- -N|--prepend-line-if-new)
51
- if [ -z "$2" ] ; then
52
- _dotpi_usage
53
- _echo_empty_option_error "$1"
54
- return 1
55
- else
56
- prepend_line_if_new="$2"
57
- shift
58
- fi
59
- ;;
60
-
61
- -v|--value)
62
- if [ -z "$2" ] ; then
63
- _dotpi_usage
64
- _echo_empty_option_error "$1"
65
- return 1
66
- else
67
- value="$2"
68
- shift
69
- fi
70
- ;;
71
-
72
- --) # End of all options.
73
- shift
74
- break
75
- ;;
76
-
77
- -?*) # Unknown
78
- _dotpi_usage
79
- dotpi_echo_error "Unknown option: $1"
80
- return 1
81
- ;;
82
-
83
- *) # Default case: No more options, so break out of the loop.
84
- break
85
-
86
- esac
87
-
88
- shift
89
- done
90
-
91
- }
92
-
93
- dotpi_configuration_escape_string() (
94
- # escape / and \
95
- echo "$(echo "$1" | perl -pe 's#([\/\\\$])#\\${1}#g')"
96
- )
97
-
98
- dotpi_configuration_get_pattern() (
99
- # sub-shell to keep everything local (functions and variables)
100
-
101
- _dotpi_command="$(basename "${FUNCNAME[0]:-"$0"}")"
102
- _dotpi_usage() {
103
- echo "Usage: ${_dotpi_command} --key <key>"
104
- echo "Usage: ${_dotpi_command} --prefix <prefix>"
105
- }
106
-
107
- # Initialize all the option variables.
108
- # This ensures we are not contaminated by variables from the environment.
109
- key=
110
- if ! _dotpi_configuration_get_options "${@}" ; then
111
- return $?
112
- fi
113
-
114
- if [ -z "$key" ] || [ -z "$prefix" ] ; then
115
- _dotpi_usage
116
- dotpi_echo_error "key or prefix option is required"
117
- return 1
118
- fi
119
-
120
- # [<leading>] <key> <assignment> <value> [ <values>] [<trailing>]
121
-
122
- if [ -n "$key" ] ; then
123
- # start of line, and spaces
124
- # invert for no comment, no non-spaces
125
- _dotpi_configuration_pattern_leading='(^[^#\S]*)'
126
-
127
- # escape
128
- key_escaped="$(dotpi_configuration_escape_string "$key")"
129
- # group and disable pattern metacharacters
130
- _dotpi_configuration_pattern_key="(${key_escaped})"
131
-
132
- # = with surrounding spaces
133
- _dotpi_configuration_pattern_assignment='(\s*=\s*)'
134
-
135
- # value is a repetition of non-space characters
136
- # invert for no comment, no space
137
- _dotpi_configuration_pattern_value='([^#\s]+)'
138
-
139
- # optional value containing spaces (terminated with a non-space)
140
- _dotpi_configuration_pattern_value_with_spaces='((\s+[^#\s]+)*)'
141
-
142
- # trailing spaces and trailing comments until the end of line
143
- _dotpi_configuration_pattern_trailing='(\s*#?.*$)'
144
-
145
- echo "\
146
- $_dotpi_configuration_pattern_leading\
147
- $_dotpi_configuration_pattern_key\
148
- $_dotpi_configuration_pattern_assignment\
149
- $_dotpi_configuration_pattern_value\
150
- $_dotpi_configuration_pattern_value_with_spaces\
151
- $_dotpi_configuration_pattern_trailing\
152
- "
153
- elif [ -n "prefix" ] ; then
154
- # start of line, and spaces
155
- # invert for no comment, no non-spaces
156
- _dotpi_configuration_pattern_leading='(^[^#\S]*)'
157
-
158
- # escape
159
- prefix_escaped="$(dotpi_configuration_escape_string "$prefix")"
160
- # group and disable pattern metacharacters
161
- _dotpi_configuration_pattern_prefix="(${prefix_escaped})"
162
-
163
- # trailing spaces and trailing comments until the end of line
164
- _dotpi_configuration_pattern_trailing='(\s*#?.*$)'
165
-
166
- echo "\
167
- $_dotpi_configuration_pattern_leading\
168
- $_dotpi_configuration_pattern_prefix\
169
- $_dotpi_configuration_pattern_trailing\
170
- "
171
-
172
- fi
173
-
174
- return 0
175
- )
176
-
177
- dotpi_configuration_comment() (
178
- # sub-shell to keep everything local (functions and variables)
179
-
180
- _dotpi_command="$(basename "${FUNCNAME[0]:-"$0"}")"
181
- _dotpi_usage() {
182
- echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
183
- }
184
-
185
- # Initialize all the option variables.
186
- # This ensures we are not contaminated by variables from the environment.
187
- file=
188
- key=
189
- if ! _dotpi_configuration_get_options "${@}" ; then
190
- return $?
191
- fi
192
-
193
- if [ -z "$key" ] ; then
194
- _dotpi_usage
195
- dotpi_echo_error "missing key option"
196
- return 1
197
- fi
198
-
199
- perl_options=()
200
- if [ -n "$file" ] ; then
201
- perl_options+=( '-i' "$file" )
202
- fi
203
-
204
- pattern="$(dotpi_configuration_get_pattern --key "$key")"
205
- # keep leading spaces
206
- perl -pe "s/${pattern}/"'${1}# ${2}${3}${4}${5}${6}\n/' "${perl_options[@]}"
207
- return $?
208
- )
209
-
210
- dotpi_configuration_write() (
211
- # sub-shell to keep everything local (functions and variables)
212
-
213
- _dotpi_command="$(basename "${FUNCNAME[0]:-"$0"}")"
214
- _dotpi_usage() {
215
- echo "Usage: ${_dotpi_command} [--file <file>] --key <key> --value <value>"
216
- }
217
-
218
- # Initialize all the option variables.
219
- # This ensures we are not contaminated by variables from the environment.
220
- file=
221
- key=
222
- value=
223
- prepend_line_if_new=
224
- if ! _dotpi_configuration_get_options "${@}" ; then
225
- return $?
226
- fi
227
-
228
- if [ -z "$key" ] ; then
229
- _dotpi_usage
230
- dotpi_echo_error "missing key option"
231
- return 1
232
- fi
233
-
234
- if [ -z "$value" ] ; then
235
- _dotpi_usage
236
- dotpi_echo_error "missing value option"
237
- return 1
238
- fi
239
-
240
- if [ -n "$file" ] ; then
241
- if ! [ -r "$file" ] ; then
242
- touch "$file"
243
- fi
244
- else
245
- input_file='/dev/stdin'
246
- output_file='/dev/stdout'
247
- fi
248
-
249
- pattern="$(dotpi_configuration_get_pattern --key "$key")"
250
- value_escaped="$(dotpi_configuration_escape_string "$value")"
251
- perl_command=('perl' '-pe' "s/${pattern}/"'${1}${2}${3}'"${value_escaped}"'${6}\n/')
252
-
253
- find_command=('dotpi_configuration_find' '--key' "$key")
254
-
255
- if [ -n "$file" ] ; then
256
- "${perl_command[@]}" -i "$file"
257
- found=$( "${find_command[@]}" --file "$file" )
258
- output_file="$file"
259
- else
260
- # duplicate stdout
261
- "${perl_command[@]}" 3>&1 ; found=$( "${find_command[@]}" <3 )
262
- fi
263
-
264
- if (( found == 0 )) ; then
265
- if [ -n "$prepend_line_if_new" ] ; then
266
- echo "$prepend_line_if_new" >> "$output_file"
267
- fi
268
- echo "${key}=${value_escaped}" >> "$output_file"
269
- fi
270
-
271
-
272
- return $?
273
- )
274
-
275
- dotpi_configuration_read() (
276
- # sub-shell to keep everything local (functions and variables)
277
-
278
- _dotpi_command="$(basename "${FUNCNAME[0]:-"$0"}")"
279
- _dotpi_usage() {
280
- echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
281
- }
282
-
283
- # Initialize all the option variables.
284
- # This ensures we are not contaminated by variables from the environment.
285
- file=
286
- key=
287
- if ! _dotpi_configuration_get_options "${@}" ; then
288
- return $?
289
- fi
290
-
291
- if [ -z "$key" ] ; then
292
- _dotpi_usage
293
- dotpi_echo_error "missing key option"
294
- return 1
295
- fi
296
-
297
- perl_options=()
298
- if [ -n "$file" ] ; then
299
- if ! [ -r "$file" ] ; then
300
- dotpi_echo_error "${file} is not readable"
301
- return 1 # false
302
- fi
303
-
304
- perl_options+=( "$file" )
305
- fi
306
-
307
- pattern="$(dotpi_configuration_get_pattern --key "$key")"
308
-
309
- values=()
310
- # split values with new line, keep spaces
311
- while IFS= read -r line ; do
312
- values+="$line"
313
- done < <(perl -ne 'if (m/'"$pattern"'/) { print "${4}${5}\n" }' "${perl_options[@]}" )
314
-
315
- if (( ${#values} == 0 )) ; then
316
- return 1 # false
317
- else
318
- # last instance
319
- echo "${values[@]: -1}"
320
- return 0 # true
321
- fi
322
- )
323
-
324
- dotpi_configuration_find() (
325
- # sub-shell to keep everything local (functions and variables)
326
-
327
- _dotpi_command="$(basename "${FUNCNAME[0]:-"$0"}")"
328
- _dotpi_usage() {
329
- echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
330
- }
331
-
332
- # Initialize all the option variables.
333
- # This ensures we are not contaminated by variables from the environment.
334
- file=
335
- key=
336
- if ! _dotpi_configuration_get_options "${@}" ; then
337
- return $?
338
- fi
339
-
340
- if [ -z "$key" ] ; then
341
- _dotpi_usage
342
- dotpi_echo_error "missing key option"
343
- return 1
344
- fi
345
-
346
- read_options=()
347
- if [ -n "$file" ] ; then
348
- read_options+=( '--file' "$file" )
349
- fi
350
-
351
- dotpi_configuration_read --key "$key" "${read_options[@]}" > /dev/null
352
- return_value=$?
353
- # 0 is true
354
- echo $(( !return_value ))
355
- return $return_value
356
- )
357
-
358
- dotpi_configuration_delete() (
359
- # sub-shell to keep everything local (functions and variables)
360
-
361
- _dotpi_command="$(basename "${FUNCNAME[0]:-"$0"}")"
362
- _dotpi_usage() {
363
- echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
364
- }
365
-
366
- # Initialize all the option variables.
367
- # This ensures we are not contaminated by variables from the environment.
368
- file=
369
- key=
370
- if ! _dotpi_configuration_get_options "${@}" ; then
371
- return $?
372
- fi
373
-
374
- if [ -z "$key" ] ; then
375
- _dotpi_usage
376
- dotpi_echo_error "missing key option"
377
- return 1
378
- fi
379
-
380
- perl_options=()
381
-
382
- if [ -n "$file" ] ; then
383
- if ! [ -r "$file" ] ; then
384
- dotpi_echo_error "${file} is not readable"
385
- return 1 # false
386
- fi
387
-
388
- perl_options+=( '-i' "$file" )
389
- fi
390
-
391
- pattern="$(dotpi_configuration_get_pattern --key "$key")"
392
-
393
- perl -ne 'if (! m/'"${pattern}"'/) { print "$_" }' "${perl_options[@]}"
394
-
395
- return $?
396
- )
397
-
398
- dotpi_configuration_replace_region() {
399
- command_name="${FUNCNAME[0]}"
400
- if (( ${#} < 3 )) ; then
401
- echo "Usage: ${command_name} <start_string> <end_string> <substitution> [<file>]"
402
- dotpi_echo_error "${command_name} needs at least 3 arguments"
403
- return 1
404
- fi
405
-
406
-
407
- local start="$(dotpi_configuration_escape_string "$1")"
408
- local end="$(dotpi_configuration_escape_string "$2")"
409
- local substitution="$(dotpi_configuration_escape_string "$3")"
410
- local file="$4"
411
-
412
- local perl_options=()
413
- if [ -n "$file" ] ; then
414
- perl_options+=( '-i' "$file" )
415
- fi
416
-
417
- perl -p0e 's/'"$start"'.*?'"$end"'/'"$substitution"'/smg' "${perl_options[@]}"
418
-
419
- return $?
420
- }