@dotpi/tools 1.0.0
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.
- package/DOC.md +66 -0
- package/LICENSE +28 -0
- package/NOTES.md +81 -0
- package/README.md +341 -0
- package/dotpi-tools.js +35 -0
- package/dotpi_root/bin/dotpi +66 -0
- package/dotpi_root/bin/dotpi_firstrun +193 -0
- package/dotpi_root/bin/dotpi_prepare_sd_card +616 -0
- package/dotpi_root/bin/dotpi_prepare_system +244 -0
- package/dotpi_root/etc/dotpi_environment_default.bash +69 -0
- package/dotpi_root/etc/dotpi_tarignore +3 -0
- package/dotpi_root/share/dotpi-install/update_to_v1.0.0_manager +39 -0
- package/dotpi_root/share/dotpi-install/update_to_v1.0.0_pi +39 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth.service +23 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth_command +134 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +132 -0
- package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor.service +22 -0
- package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor_command +14 -0
- package/dotpi_root/share/dotpi_environment.bash +5 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_bluetooth.bash +346 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +504 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +435 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_connection.bash +199 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_dotpi.bash +36 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +111 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +175 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_utils.bash +154 -0
- package/dotpi_root/share/dotpi_functions.bash +14 -0
- package/dotpi_root/share/dotpi_init.bash +18 -0
- package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +18 -0
- package/dotpi_root/share/jackd/dotpi_jackd_command +26 -0
- package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +21 -0
- package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +17 -0
- package/dotpi_root/share/jackd/jackd.service +22 -0
- package/dotpi_root/share/limits/zzz_dotpi_audio.conf +11 -0
- package/dotpi_root/share/wireplumber/bluetooth.lua.d/8zzz-dotpi-wireplumber-config.lua +4 -0
- package/examples/example-development/configuration/dotpi_project.bash +40 -0
- package/examples/example-headphones/configuration/dotpi_project.bash +18 -0
- package/examples/example-hifiberry/configuration/dotpi_instance_012.bash +4 -0
- package/examples/example-hifiberry/configuration/dotpi_project.bash +18 -0
- package/examples/example-network/configuration/dotpi_project.bash +21 -0
- package/package.json +35 -0
- package/src/configure-host.js +187 -0
- package/src/constants.js +30 -0
- package/src/create-project.js +438 -0
- package/src/install-rpi.js +173 -0
- package/src/templates/README.md +16 -0
- package/src/templates/ap.nmconnection +25 -0
- package/src/templates/dotpi_project.bash +31 -0
- package/src/templates/dotpi_secrets.bash +4 -0
- package/src/templates/infrastructure.nmconnection +29 -0
- package/src/templates/ssh_config +6 -0
- package/src/utils.js +175 -0
- package/test/constants.spec.js +37 -0
- package/test/create-project.test.js +57 -0
- package/test/install-rpi.test.js +8 -0
- package/test/utils.spec.js +48 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
_dotpi_configuration_get_options() {
|
|
4
|
+
|
|
5
|
+
_echo_empty_option_error() {
|
|
6
|
+
dotpi_echo_error "$1 requires a non-empty option argument."
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
# From http://mywiki.wooledge.org/BashFAQ/035
|
|
10
|
+
|
|
11
|
+
while true ; do
|
|
12
|
+
case $1 in
|
|
13
|
+
|
|
14
|
+
-h|-\?|--help)
|
|
15
|
+
_dotpi_usage # Display a usage synopsis.
|
|
16
|
+
return 0
|
|
17
|
+
;;
|
|
18
|
+
|
|
19
|
+
-f|--file) # Takes an option argument; ensure it has been specified.
|
|
20
|
+
if [ -z "$2" ] ; then
|
|
21
|
+
_dotpi_usage
|
|
22
|
+
_echo_empty_option_error "$1"
|
|
23
|
+
return 1
|
|
24
|
+
else
|
|
25
|
+
file="$2"
|
|
26
|
+
shift
|
|
27
|
+
fi
|
|
28
|
+
;;
|
|
29
|
+
|
|
30
|
+
-k|--key)
|
|
31
|
+
if [ -z "$2" ] ; then
|
|
32
|
+
_dotpi_usage
|
|
33
|
+
_echo_empty_option_error "$1"
|
|
34
|
+
return 1
|
|
35
|
+
else
|
|
36
|
+
key="$2"
|
|
37
|
+
shift
|
|
38
|
+
fi
|
|
39
|
+
;;
|
|
40
|
+
|
|
41
|
+
-p|--prefix)
|
|
42
|
+
if [ -z "$2" ] ; then
|
|
43
|
+
_dotpi_usage
|
|
44
|
+
_echo_empty_option_error "$1"
|
|
45
|
+
return 1
|
|
46
|
+
else
|
|
47
|
+
prefix="$2"
|
|
48
|
+
shift
|
|
49
|
+
fi
|
|
50
|
+
;;
|
|
51
|
+
|
|
52
|
+
-N|--prepend-line-if-new)
|
|
53
|
+
if [ -z "$2" ] ; then
|
|
54
|
+
_dotpi_usage
|
|
55
|
+
_echo_empty_option_error "$1"
|
|
56
|
+
return 1
|
|
57
|
+
else
|
|
58
|
+
prepend_line_if_new="$2"
|
|
59
|
+
shift
|
|
60
|
+
fi
|
|
61
|
+
;;
|
|
62
|
+
|
|
63
|
+
-v|--value)
|
|
64
|
+
if [ -z "$2" ] ; then
|
|
65
|
+
_dotpi_usage
|
|
66
|
+
_echo_empty_option_error "$1"
|
|
67
|
+
return 1
|
|
68
|
+
else
|
|
69
|
+
value="$2"
|
|
70
|
+
shift
|
|
71
|
+
fi
|
|
72
|
+
;;
|
|
73
|
+
|
|
74
|
+
--) # End of all options.
|
|
75
|
+
shift
|
|
76
|
+
break
|
|
77
|
+
;;
|
|
78
|
+
|
|
79
|
+
-?*) # Unknown
|
|
80
|
+
_dotpi_usage
|
|
81
|
+
dotpi_echo_error "Unknown option: $1"
|
|
82
|
+
return 1
|
|
83
|
+
;;
|
|
84
|
+
|
|
85
|
+
*) # Default case: No more options, so break out of the loop.
|
|
86
|
+
break
|
|
87
|
+
|
|
88
|
+
esac
|
|
89
|
+
|
|
90
|
+
shift
|
|
91
|
+
done
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
dotpi_configuration_escape_string() (
|
|
96
|
+
# escape / \ $
|
|
97
|
+
echo "$(echo "$1" | perl -pe 's#([/\\\$])#\\${1}#g')"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
dotpi_configuration_get_pattern() (
|
|
101
|
+
# sub-shell to keep everything local (functions and variables)
|
|
102
|
+
|
|
103
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
104
|
+
_dotpi_usage() {
|
|
105
|
+
echo "Usage: ${_dotpi_command} --key <key>"
|
|
106
|
+
echo "Usage: ${_dotpi_command} --prefix <prefix>"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Initialize all the option variables.
|
|
110
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
111
|
+
key=
|
|
112
|
+
if ! _dotpi_configuration_get_options "${@}" ; then
|
|
113
|
+
return $?
|
|
114
|
+
fi
|
|
115
|
+
|
|
116
|
+
if [ -z "$key" ] && [ -z "$prefix" ] ; then
|
|
117
|
+
_dotpi_usage
|
|
118
|
+
dotpi_echo_error "key or prefix is required"
|
|
119
|
+
return 1
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
if [ -n "$key" ] ; then
|
|
124
|
+
# [<leading>] <key> <assignment> <value> [ <values>] [<trailing>]
|
|
125
|
+
|
|
126
|
+
# start of line, and spaces
|
|
127
|
+
# invert for no comment, no non-spaces
|
|
128
|
+
_dotpi_configuration_pattern_leading='(^[^#\S]*)'
|
|
129
|
+
|
|
130
|
+
# escape
|
|
131
|
+
key_escaped="$(dotpi_configuration_escape_string "$key")"
|
|
132
|
+
# group and disable pattern metacharacters
|
|
133
|
+
_dotpi_configuration_pattern_key="(${key_escaped})"
|
|
134
|
+
|
|
135
|
+
# = with surrounding spaces
|
|
136
|
+
_dotpi_configuration_pattern_assignment='(\s*=\s*)'
|
|
137
|
+
|
|
138
|
+
# value is a repetition of non-space characters
|
|
139
|
+
# invert for no comment, no space
|
|
140
|
+
_dotpi_configuration_pattern_value='([^#\s]+)'
|
|
141
|
+
|
|
142
|
+
# optional value containing spaces (terminated with a non-space)
|
|
143
|
+
_dotpi_configuration_pattern_value_with_spaces='((\s+[^#\s]+)*)'
|
|
144
|
+
|
|
145
|
+
# trailing spaces and trailing comments until the end of line
|
|
146
|
+
# (including the end of line)
|
|
147
|
+
_dotpi_configuration_pattern_trailing='(\s*#?.*$)'
|
|
148
|
+
|
|
149
|
+
echo "\
|
|
150
|
+
$_dotpi_configuration_pattern_leading\
|
|
151
|
+
$_dotpi_configuration_pattern_key\
|
|
152
|
+
$_dotpi_configuration_pattern_assignment\
|
|
153
|
+
$_dotpi_configuration_pattern_value\
|
|
154
|
+
$_dotpi_configuration_pattern_value_with_spaces\
|
|
155
|
+
$_dotpi_configuration_pattern_trailing\
|
|
156
|
+
"
|
|
157
|
+
elif [ -n "$prefix" ] ; then
|
|
158
|
+
# [<leading>] <prefix> [<trailing>]
|
|
159
|
+
|
|
160
|
+
# start of line, and spaces
|
|
161
|
+
# invert for no comment, no non-spaces
|
|
162
|
+
_dotpi_configuration_pattern_leading='(^[^#\S]*)'
|
|
163
|
+
|
|
164
|
+
# escape
|
|
165
|
+
prefix_escaped="$(dotpi_configuration_escape_string "$prefix")"
|
|
166
|
+
# group and disable pattern metacharacters
|
|
167
|
+
_dotpi_configuration_pattern_prefix="(${prefix_escaped})"
|
|
168
|
+
|
|
169
|
+
# anything until the end of line
|
|
170
|
+
# (including the end of line)
|
|
171
|
+
_dotpi_configuration_pattern_trailing='(.*$)'
|
|
172
|
+
|
|
173
|
+
echo "\
|
|
174
|
+
$_dotpi_configuration_pattern_leading\
|
|
175
|
+
$_dotpi_configuration_pattern_prefix\
|
|
176
|
+
$_dotpi_configuration_pattern_trailing\
|
|
177
|
+
"
|
|
178
|
+
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
return 0
|
|
182
|
+
)
|
|
183
|
+
# comment a key in a configuration file
|
|
184
|
+
dotpi_configuration_comment() (
|
|
185
|
+
# sub-shell to keep everything local (functions and variables)
|
|
186
|
+
|
|
187
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
188
|
+
_dotpi_usage() {
|
|
189
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
# Initialize all the option variables.
|
|
193
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
194
|
+
file=
|
|
195
|
+
key=
|
|
196
|
+
if ! _dotpi_configuration_get_options "${@}" ; then
|
|
197
|
+
return $?
|
|
198
|
+
fi
|
|
199
|
+
|
|
200
|
+
if [ -z "$key" ] ; then
|
|
201
|
+
_dotpi_usage
|
|
202
|
+
dotpi_echo_error "missing key option"
|
|
203
|
+
return 1
|
|
204
|
+
fi
|
|
205
|
+
|
|
206
|
+
perl_options=()
|
|
207
|
+
if [ -n "$file" ] ; then
|
|
208
|
+
perl_options+=( '-i' "$file" )
|
|
209
|
+
fi
|
|
210
|
+
|
|
211
|
+
pattern="$(dotpi_configuration_get_pattern --key "$key")"
|
|
212
|
+
# keep leading spaces, and trailing (including end of line)
|
|
213
|
+
perl -pe "s/${pattern}/"'${1}# ${2}${3}${4}${5}${7}/' "${perl_options[@]}"
|
|
214
|
+
return $?
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
# write a value corresponding to a key in a configuration file
|
|
218
|
+
dotpi_configuration_write() (
|
|
219
|
+
# sub-shell to keep everything local (functions and variables)
|
|
220
|
+
|
|
221
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
222
|
+
_dotpi_usage() {
|
|
223
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key> --value <value>"
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
# Initialize all the option variables.
|
|
227
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
228
|
+
file=
|
|
229
|
+
key=
|
|
230
|
+
value=
|
|
231
|
+
prepend_line_if_new=
|
|
232
|
+
if ! _dotpi_configuration_get_options "${@}" ; then
|
|
233
|
+
return $?
|
|
234
|
+
fi
|
|
235
|
+
|
|
236
|
+
if [ -z "$key" ] ; then
|
|
237
|
+
_dotpi_usage
|
|
238
|
+
dotpi_echo_error "missing key option"
|
|
239
|
+
return 1
|
|
240
|
+
fi
|
|
241
|
+
|
|
242
|
+
if [ -z "$value" ] ; then
|
|
243
|
+
_dotpi_usage
|
|
244
|
+
dotpi_echo_error "missing value option"
|
|
245
|
+
return 1
|
|
246
|
+
fi
|
|
247
|
+
|
|
248
|
+
if [ -n "$file" ] ; then
|
|
249
|
+
if ! [ -r "$file" ] ; then
|
|
250
|
+
touch "$file"
|
|
251
|
+
fi
|
|
252
|
+
else
|
|
253
|
+
input_file='/dev/stdin'
|
|
254
|
+
output_file='/dev/stdout'
|
|
255
|
+
fi
|
|
256
|
+
|
|
257
|
+
pattern="$(dotpi_configuration_get_pattern --key "$key")"
|
|
258
|
+
value_escaped="$(dotpi_configuration_escape_string "$value")"
|
|
259
|
+
# trailing includes the end of line
|
|
260
|
+
perl_command=('perl' '-pe' "s/${pattern}/"'${1}${2}${3}'"${value_escaped}"'${7}/')
|
|
261
|
+
|
|
262
|
+
find_command=('dotpi_configuration_find' '--key' "$key")
|
|
263
|
+
|
|
264
|
+
if [ -n "$file" ] ; then
|
|
265
|
+
"${perl_command[@]}" -i -- "$file"
|
|
266
|
+
found=$( "${find_command[@]}" --file "$file" )
|
|
267
|
+
output_file="$file"
|
|
268
|
+
else
|
|
269
|
+
# duplicate stdout
|
|
270
|
+
"${perl_command[@]}" 3>&1 ; found=$( "${find_command[@]}" <3 )
|
|
271
|
+
fi
|
|
272
|
+
|
|
273
|
+
if (( found == 0 )) ; then
|
|
274
|
+
# add a new line in case file does not already end with one
|
|
275
|
+
echo '' >> "$output_file"
|
|
276
|
+
if [ -n "$prepend_line_if_new" ] ; then
|
|
277
|
+
echo "$prepend_line_if_new" >> "$output_file"
|
|
278
|
+
fi
|
|
279
|
+
echo "${key}=${value_escaped}" >> "$output_file"
|
|
280
|
+
fi
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
return $?
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
# read a value corresponfing to a key in a configuration file
|
|
287
|
+
dotpi_configuration_read() (
|
|
288
|
+
# sub-shell to keep everything local (functions and variables)
|
|
289
|
+
|
|
290
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
291
|
+
_dotpi_usage() {
|
|
292
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
# Initialize all the option variables.
|
|
296
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
297
|
+
file=
|
|
298
|
+
key=
|
|
299
|
+
if ! _dotpi_configuration_get_options "${@}" ; then
|
|
300
|
+
return $?
|
|
301
|
+
fi
|
|
302
|
+
|
|
303
|
+
if [ -z "$key" ] ; then
|
|
304
|
+
_dotpi_usage
|
|
305
|
+
dotpi_echo_error "missing key option"
|
|
306
|
+
return 1
|
|
307
|
+
fi
|
|
308
|
+
|
|
309
|
+
perl_options=()
|
|
310
|
+
if [ -n "$file" ] ; then
|
|
311
|
+
if ! [ -r "$file" ] ; then
|
|
312
|
+
dotpi_echo_error "${file} is not readable"
|
|
313
|
+
return 1 # false
|
|
314
|
+
fi
|
|
315
|
+
|
|
316
|
+
perl_options+=( "$file" )
|
|
317
|
+
fi
|
|
318
|
+
|
|
319
|
+
pattern="$(dotpi_configuration_get_pattern --key "$key")"
|
|
320
|
+
|
|
321
|
+
values=()
|
|
322
|
+
# split values with new line, keep spaces
|
|
323
|
+
while IFS= read -r line ; do
|
|
324
|
+
values+=("$line")
|
|
325
|
+
done < <(perl -ne 'if (m/'"$pattern"'/) { print "${4}${5}\n" }' "${perl_options[@]}" )
|
|
326
|
+
|
|
327
|
+
if (( ${#values} == 0 )) ; then
|
|
328
|
+
return 1 # false
|
|
329
|
+
else
|
|
330
|
+
# last instance
|
|
331
|
+
echo "${values[@]: -1}"
|
|
332
|
+
return 0 # true
|
|
333
|
+
fi
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
# find a key in a configuration file
|
|
337
|
+
dotpi_configuration_find() (
|
|
338
|
+
# sub-shell to keep everything local (functions and variables)
|
|
339
|
+
|
|
340
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
341
|
+
_dotpi_usage() {
|
|
342
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
# Initialize all the option variables.
|
|
346
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
347
|
+
file=
|
|
348
|
+
key=
|
|
349
|
+
if ! _dotpi_configuration_get_options "${@}" ; then
|
|
350
|
+
return $?
|
|
351
|
+
fi
|
|
352
|
+
|
|
353
|
+
if [ -z "$key" ] ; then
|
|
354
|
+
_dotpi_usage
|
|
355
|
+
dotpi_echo_error "missing key option"
|
|
356
|
+
return 1
|
|
357
|
+
fi
|
|
358
|
+
|
|
359
|
+
read_options=()
|
|
360
|
+
if [ -n "$file" ] ; then
|
|
361
|
+
read_options+=( '--file' "$file" )
|
|
362
|
+
fi
|
|
363
|
+
|
|
364
|
+
dotpi_configuration_read --key "$key" "${read_options[@]}" > /dev/null
|
|
365
|
+
return_value=$?
|
|
366
|
+
# 0 is true
|
|
367
|
+
echo $(( !return_value ))
|
|
368
|
+
return $return_value
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
# delete a key in a configuration file
|
|
372
|
+
dotpi_configuration_delete() (
|
|
373
|
+
# sub-shell to keep everything local (functions and variables)
|
|
374
|
+
|
|
375
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
376
|
+
_dotpi_usage() {
|
|
377
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
# Initialize all the option variables.
|
|
381
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
382
|
+
file=
|
|
383
|
+
key=
|
|
384
|
+
if ! _dotpi_configuration_get_options "${@}" ; then
|
|
385
|
+
return $?
|
|
386
|
+
fi
|
|
387
|
+
|
|
388
|
+
if [ -z "$key" ] ; then
|
|
389
|
+
_dotpi_usage
|
|
390
|
+
dotpi_echo_error "missing key option"
|
|
391
|
+
return 1
|
|
392
|
+
fi
|
|
393
|
+
|
|
394
|
+
perl_options=()
|
|
395
|
+
|
|
396
|
+
if [ -n "$file" ] ; then
|
|
397
|
+
if ! [ -r "$file" ] ; then
|
|
398
|
+
dotpi_echo_error "${file} is not readable"
|
|
399
|
+
return 1 # false
|
|
400
|
+
fi
|
|
401
|
+
|
|
402
|
+
perl_options+=( '-i' "$file" )
|
|
403
|
+
fi
|
|
404
|
+
|
|
405
|
+
pattern="$(dotpi_configuration_get_pattern --key "$key")"
|
|
406
|
+
|
|
407
|
+
perl -ne 'if (! m/'"${pattern}"'/) { print "$_" }' "${perl_options[@]}"
|
|
408
|
+
|
|
409
|
+
return $?
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
# replace a region in a configuration file
|
|
413
|
+
dotpi_configuration_replace_region() {
|
|
414
|
+
command_name="${FUNCNAME[0]}"
|
|
415
|
+
if (( ${#} < 3 )) ; then
|
|
416
|
+
echo "Usage: ${command_name} <start_string> <end_string> <substitution> [<file>]"
|
|
417
|
+
dotpi_echo_error "${command_name} needs at least 3 arguments"
|
|
418
|
+
return 1
|
|
419
|
+
fi
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
local start="$(dotpi_configuration_escape_string "$1")"
|
|
423
|
+
local end="$(dotpi_configuration_escape_string "$2")"
|
|
424
|
+
local substitution="$(dotpi_configuration_escape_string "$3")"
|
|
425
|
+
local file="$4"
|
|
426
|
+
|
|
427
|
+
local perl_options=()
|
|
428
|
+
if [ -n "$file" ] ; then
|
|
429
|
+
perl_options+=( '-i' "$file" )
|
|
430
|
+
fi
|
|
431
|
+
|
|
432
|
+
perl -p0e 's/'"$start"'.*?'"$end"'/'"$substitution"'/smg' "${perl_options[@]}"
|
|
433
|
+
|
|
434
|
+
return $?
|
|
435
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
_dotpi_connection_get_options() {
|
|
4
|
+
|
|
5
|
+
_echo_empty_option_error() {
|
|
6
|
+
dotpi_echo_error "$1 requires a non-empty option argument."
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
# From http://mywiki.wooledge.org/BashFAQ/035
|
|
10
|
+
|
|
11
|
+
while true ; do
|
|
12
|
+
case $1 in
|
|
13
|
+
|
|
14
|
+
-h|-\?|--help)
|
|
15
|
+
_dotpi_usage # Display a usage synopsis.
|
|
16
|
+
return 0
|
|
17
|
+
;;
|
|
18
|
+
|
|
19
|
+
-f|--file) # Takes an option argument; ensure it has been specified.
|
|
20
|
+
if [ -z "$2" ] ; then
|
|
21
|
+
_dotpi_usage
|
|
22
|
+
_echo_empty_option_error "$1"
|
|
23
|
+
return 1
|
|
24
|
+
else
|
|
25
|
+
file="$2"
|
|
26
|
+
shift
|
|
27
|
+
fi
|
|
28
|
+
;;
|
|
29
|
+
|
|
30
|
+
-k|--key)
|
|
31
|
+
if [ -z "$2" ] ; then
|
|
32
|
+
_dotpi_usage
|
|
33
|
+
_echo_empty_option_error "$1"
|
|
34
|
+
return 1
|
|
35
|
+
else
|
|
36
|
+
key="$2"
|
|
37
|
+
shift
|
|
38
|
+
fi
|
|
39
|
+
;;
|
|
40
|
+
|
|
41
|
+
-v|--value)
|
|
42
|
+
if [ -z "$2" ] ; then
|
|
43
|
+
_dotpi_usage
|
|
44
|
+
_echo_empty_option_error "$1"
|
|
45
|
+
return 1
|
|
46
|
+
else
|
|
47
|
+
value="$2"
|
|
48
|
+
shift
|
|
49
|
+
fi
|
|
50
|
+
;;
|
|
51
|
+
|
|
52
|
+
--) # End of all options.
|
|
53
|
+
shift
|
|
54
|
+
break
|
|
55
|
+
;;
|
|
56
|
+
|
|
57
|
+
-?*) # Unknown
|
|
58
|
+
_dotpi_usage
|
|
59
|
+
dotpi_echo_error "Unknown option: $1"
|
|
60
|
+
return 1
|
|
61
|
+
;;
|
|
62
|
+
|
|
63
|
+
*) # Default case: No more options, so break out of the loop.
|
|
64
|
+
break
|
|
65
|
+
|
|
66
|
+
esac
|
|
67
|
+
|
|
68
|
+
shift
|
|
69
|
+
done
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# write key value pair to an .nmconnection file
|
|
74
|
+
dotpi_connection_write() (
|
|
75
|
+
# sub-shell to keep everything local (functions and variables)
|
|
76
|
+
|
|
77
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
78
|
+
_dotpi_usage() {
|
|
79
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key> --value <value>"
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# Initialize all the option variables.
|
|
83
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
84
|
+
file=
|
|
85
|
+
key=
|
|
86
|
+
value=
|
|
87
|
+
prepend_line_if_new=
|
|
88
|
+
if ! _dotpi_connection_get_options "${@}" ; then
|
|
89
|
+
return $?
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
if [ -z "$key" ] ; then
|
|
93
|
+
_dotpi_usage
|
|
94
|
+
dotpi_echo_error "missing key option"
|
|
95
|
+
return 1
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
if [ -z "$value" ] ; then
|
|
99
|
+
_dotpi_usage
|
|
100
|
+
dotpi_echo_error "missing value option"
|
|
101
|
+
return 1
|
|
102
|
+
fi
|
|
103
|
+
|
|
104
|
+
if [ -z "$file" ] ; then
|
|
105
|
+
dotpi_echo_error "missing file option"
|
|
106
|
+
return 1
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
git config --file "$file" "$key" "$value"
|
|
110
|
+
|
|
111
|
+
return $?
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# read a value corresponding to a key in an .nmconnection file
|
|
115
|
+
dotpi_connection_read() (
|
|
116
|
+
# sub-shell to keep everything local (functions and variables)
|
|
117
|
+
|
|
118
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
119
|
+
_dotpi_usage() {
|
|
120
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Initialize all the option variables.
|
|
124
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
125
|
+
file=
|
|
126
|
+
key=
|
|
127
|
+
value=
|
|
128
|
+
prepend_line_if_new=
|
|
129
|
+
if ! _dotpi_connection_get_options "${@}" ; then
|
|
130
|
+
return $?
|
|
131
|
+
fi
|
|
132
|
+
|
|
133
|
+
if [ -z "$key" ] ; then
|
|
134
|
+
_dotpi_usage
|
|
135
|
+
dotpi_echo_error "missing key option"
|
|
136
|
+
return 1
|
|
137
|
+
fi
|
|
138
|
+
|
|
139
|
+
if [ -z "$file" ] ; then
|
|
140
|
+
_dotpi_usage
|
|
141
|
+
dotpi_echo_error "missing file option"
|
|
142
|
+
return 1
|
|
143
|
+
fi
|
|
144
|
+
|
|
145
|
+
if ! [ -r "$file" ] ; then
|
|
146
|
+
_dotpi_usage
|
|
147
|
+
dotpi_echo_error "file ${file} is not readable"
|
|
148
|
+
return 1
|
|
149
|
+
fi
|
|
150
|
+
|
|
151
|
+
# use printf to unquote strings
|
|
152
|
+
value="$(git config --file "$file" "$key")"
|
|
153
|
+
printf "$value\n"
|
|
154
|
+
|
|
155
|
+
return $?
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# delete a key in an .nmconnection file
|
|
159
|
+
dotpi_connection_delete() (
|
|
160
|
+
# sub-shell to keep everything local (functions and variables)
|
|
161
|
+
|
|
162
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
163
|
+
_dotpi_usage() {
|
|
164
|
+
echo "Usage: ${_dotpi_command} [--file <file>] --key <key>"
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Initialize all the option variables.
|
|
168
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
169
|
+
file=
|
|
170
|
+
key=
|
|
171
|
+
value=
|
|
172
|
+
prepend_line_if_new=
|
|
173
|
+
if ! _dotpi_connection_get_options "${@}" ; then
|
|
174
|
+
return $?
|
|
175
|
+
fi
|
|
176
|
+
|
|
177
|
+
if [ -z "$key" ] ; then
|
|
178
|
+
_dotpi_usage
|
|
179
|
+
dotpi_echo_error "missing key option"
|
|
180
|
+
return 1
|
|
181
|
+
fi
|
|
182
|
+
|
|
183
|
+
if [ -z "$file" ] ; then
|
|
184
|
+
_dotpi_usage
|
|
185
|
+
dotpi_echo_error "missing value option"
|
|
186
|
+
return 1
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if ! [ -r "$file" ] ; then
|
|
190
|
+
_dotpi_usage
|
|
191
|
+
dotpi_echo_error "file ${file} is not readable"
|
|
192
|
+
return 1
|
|
193
|
+
fi
|
|
194
|
+
|
|
195
|
+
git config --file "$file" --unset "$key"
|
|
196
|
+
|
|
197
|
+
return $?
|
|
198
|
+
)
|
|
199
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
dotpi_dotpi_update() (
|
|
4
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
5
|
+
log_file="${DOTPI_ROOT}/var/log/${_dotpi_command}_$(date +"%Y%m%d-%H%M%S").log"
|
|
6
|
+
exec &> >(dotpi log "$log_file")
|
|
7
|
+
|
|
8
|
+
dotpi echo_info "Log of dotpi update: ${log_file}"
|
|
9
|
+
|
|
10
|
+
src_path="${DOTPI_ROOT}/tmp"
|
|
11
|
+
|
|
12
|
+
cd -- "${src_path}" || {
|
|
13
|
+
dotpi_echo_error "${_dotpi_command}: could not change directory to runtime: ${src_path}"
|
|
14
|
+
return 1
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# clone without history, without any file
|
|
18
|
+
src_name="dotpi-install"
|
|
19
|
+
src_path="${src_path}/${src_name}"
|
|
20
|
+
rm -rf "${src_path}"
|
|
21
|
+
git clone -n --depth=1 --filter=tree:0 -b main "https://github.com/ircam-ismm/${src_name}.git"
|
|
22
|
+
|
|
23
|
+
cd "${src_path}" || {
|
|
24
|
+
dotpi_echo_error "${_dotpi_command}: could not change directory to runtime: ${src_path}"
|
|
25
|
+
return 1
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
src_root_name="dotpi_root"
|
|
29
|
+
# checkout only dotpi-root
|
|
30
|
+
git sparse-checkout set --no-cone "${src_root_name}"
|
|
31
|
+
# actual checkout
|
|
32
|
+
git checkout
|
|
33
|
+
|
|
34
|
+
dotpi echo_info "Update dotpi from sources"
|
|
35
|
+
tar c -C "${src_root_name}" '.' | tar xv -m --no-same-owner --no-same-permissions --no-overwrite-dir -C "${DOTPI_ROOT}"
|
|
36
|
+
)
|