@dotpi/tools 1.3.3 → 1.4.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/.editorbackup/NOTES.md~ +974 -0
- package/.editorbackup/PIPEWIRE.md~ +42 -0
- package/.editorbackup/README.md~ +335 -0
- package/BACKUP-SANDO.command +61 -0
- package/BACKUP-SISIDO.command +61 -0
- package/PIPEWIRE.md +280 -0
- package/dotpi_root/bin/.editorbackup/dotpi_firstrun.bash~ +149 -0
- package/dotpi_root/bin/.editorbackup/dotpi_firstrun~ +177 -0
- package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card.bash~ +425 -0
- package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card~ +620 -0
- package/dotpi_root/bin/.editorbackup/dotpi_prepare_system.bash~ +82 -0
- package/dotpi_root/bin/.editorbackup/dotpi_prepare_system~ +100 -0
- package/dotpi_root/bin/.editorbackup/dotpi~ +61 -0
- package/dotpi_root/bin/.editorbackup/prepare_sd_card.bash~ +252 -0
- package/dotpi_root/bin/dotpi_prepare_system +5 -0
- package/dotpi_root/etc/.editorbackup/dotpi_environment_default.bash~ +49 -0
- package/dotpi_root/etc/.editorbackup/dotpi_environment_instance.bash~ +1 -0
- package/dotpi_root/etc/.editorbackup/dotpi_environment_project.bash~ +33 -0
- package/dotpi_root/etc/.editorbackup/dotpi_tarignore~ +4 -0
- package/dotpi_root/share/.editorbackup/coucou~ +1 -0
- package/dotpi_root/share/.editorbackup/dotpi_environment.bash~ +9 -0
- package/dotpi_root/share/.editorbackup/dotpi_functions.bash~ +11 -0
- package/dotpi_root/share/.editorbackup/dotpi_functions_configuration.bash~ +420 -0
- package/dotpi_root/share/.editorbackup/dotpi_functions_connection.bash~ +358 -0
- package/dotpi_root/share/.editorbackup/dotpi_init.bash~ +18 -0
- package/dotpi_root/share/dotpi_audio_alsa/dotpi_audio_alsa.service +15 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth.service~ +24 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_command~ +80 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_start_command~ +26 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_stop_command~ +30 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_bluetooth_audio.service~ +21 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_bluetooth.bash~ +256 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_device.bash~ +287 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_bluetooth_audio.bash~ +7 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_configuration.bash~ +428 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_connection.bash~ +194 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_daemon.bash~ +26 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcard.bash~ +287 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcards.bash~ +12 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_system.bash~ +158 -0
- package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_utils.bash~ +152 -0
- package/dotpi_root/share/dotpi_init.bash +3 -0
- package/dotpi_root/share/dotpi_pipewire/bin/dotpi_pipewire_relink +85 -0
- package/dotpi_root/share/dotpi_pipewire/dotpi_install +24 -0
- package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire.service +22 -0
- package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire_command +29 -0
- package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_bluetooth.bash~ +20 -0
- package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_command~ +17 -0
- package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_headphones.bash~ +20 -0
- package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_hifiberry.bash~ +16 -0
- package/dotpi_root/share/jackd/.editorbackup/jackd.conf~ +5 -0
- package/dotpi_root/share/jackd/.editorbackup/jackd.service~ +15 -0
- package/dotpi_root/share/jackd/.editorbackup/jackd_headphones.conf~ +5 -0
- package/dotpi_root/share/jackd/dotpi_jack_simple_client.service +23 -0
- package/dotpi_root/share/wireplumber/.editorbackup/8zzz-dotpi-wireplumber-config.lua~ +1 -0
- package/package.json +1 -1
- package/projects/asterismes.tgz +0 -0
- package/projects/example-bluetooth/configuration/.editorbackup/dotpi_instance_001.bash~ +4 -0
- package/projects/example-bluetooth/configuration/.editorbackup/dotpi_instance_002.bash~ +3 -0
- package/projects/example-bluetooth/configuration/.editorbackup/dotpi_project.bash~ +46 -0
- package/projects/example-bluetooth/configuration/dotpi_instance_001.bash +3 -0
- package/projects/example-bluetooth/configuration/dotpi_instance_002.bash +3 -0
- package/projects/example-bluetooth/configuration/dotpi_project.bash +48 -0
- package/projects/example-development/configuration/.editorbackup/dotpi_project.bash~ +59 -0
- package/projects/example-development/configuration/dotpi_instance_114.bash +4 -0
- package/projects/example-headphones/configuration/.editorbackup/dotpi_project.bash~ +18 -0
- package/projects/example-hifiberry/configuration/.editorbackup/dotpi_instance_012.bash~ +4 -0
- package/projects/example-hifiberry/configuration/.editorbackup/dotpi_project.bash~ +18 -0
- package/projects/example-network/configuration/.editorbackup/dotpi_project.bash~ +21 -0
- package/projects/old/bad/.editorbackup/dotpi_environment_instance.bash~ +1 -0
- package/projects/old/bad/.editorbackup/dotpi_environment_project.bash~ +26 -0
- package/projects/old/bad/.editorbackup/dotpi_project.bash~ +33 -0
- package/projects/old/bad/.editorbackup/dotpi_tmp.bash~ +3 -0
- package/projects/old/bad/.editorbackup/wpa_supplicant.conf~ +37 -0
- package/projects/old/bad/dotpi_project.bash +20 -0
- package/projects/old/bluetooth/.editorbackup/dotpi_environment_instance.bash~ +1 -0
- package/projects/old/bluetooth/.editorbackup/dotpi_environment_project.bash~ +26 -0
- package/projects/old/bluetooth/.editorbackup/dotpi_project.bash~ +21 -0
- package/projects/old/bluetooth/.editorbackup/dotpi_tmp.bash~ +3 -0
- package/projects/old/bluetooth/.editorbackup/wpa_supplicant.conf~ +37 -0
- package/projects/old/bluetooth/dotpi_project.bash +29 -0
- package/projects/old/dev.bak/.editorbackup/dotpi_environment_instance.bash~ +1 -0
- package/projects/old/dev.bak/.editorbackup/dotpi_environment_project.bash~ +33 -0
- package/projects/old/dev.bak/.editorbackup/wpa_supplicant.conf~ +37 -0
- package/projects/old/dev.bak/dotpi_environment_instance.bash +1 -0
- package/projects/old/dev.bak/dotpi_environment_project.bash +46 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI-A114.nmconnection~ +24 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI.nmconnection~ +24 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +24 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/onze.nmconnection~ +22 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/welcome.nmconnection~ +23 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI-A114.nmconnection +23 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI.nmconnection +23 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/Livebox-97C6_wifi_invite.nmconnection +24 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/onze.nmconnection +24 -0
- package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/welcome.nmconnection +23 -0
- package/projects/old/dev.bak/network/.editorbackup/DOTPI-A114.nmconnection~ +24 -0
- package/projects/old/dev.bak/network/.editorbackup/DOTPI.nmconnection~ +24 -0
- package/projects/old/dev.bak/network/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +24 -0
- package/projects/old/dev.bak/network/.editorbackup/onze.nmconnection~ +22 -0
- package/projects/old/dev.bak/network/.editorbackup/welcome.nmconnection~ +23 -0
- package/projects/old/dev.bak/network/AccueilCie.nmconnection +24 -0
- package/projects/old/dev.bak/network/DOTPI-A114.nmconnection +23 -0
- package/projects/old/dev.bak/network/DOTPI.nmconnection +23 -0
- package/projects/old/dev.bak/network/Livebox-97C6_wifi_invite.nmconnection +25 -0
- package/projects/old/dev.bak/network/onze.nmconnection +24 -0
- package/projects/old/dev.bak/network/welcome.nmconnection +23 -0
- package/projects/old/dev.bak/network/wifi-access-point.nmconnection +23 -0
- package/projects/old/dev.bak/network/wifi-internet.nmconnection +24 -0
- package/projects/old/dev.bak/network/wifi-ircam-public.nmconnection +24 -0
- package/projects/old/dev.bak/network/wifi-local.nmconnection +22 -0
- package/projects/old/dev.bak/network/wifi-welcome.nmconnection +24 -0
- package/projects/old/dev.bak/wpa_supplicant.conf +43 -0
- package/projects/old/dev.zip +0 -0
- package/projects/old/example/.editorbackup/dotpi_environment_instance.bash~ +1 -0
- package/projects/old/example/.editorbackup/dotpi_environment_project.bash~ +26 -0
- package/projects/old/example/.editorbackup/dotpi_project.bash~ +21 -0
- package/projects/old/example/.editorbackup/dotpi_tmp.bash~ +3 -0
- package/projects/old/example/.editorbackup/wpa_supplicant.conf~ +37 -0
- package/projects/old/example/configuration/.editorbackup/dotpi_project.bash~ +21 -0
- package/projects/old/example/configuration/dotpi_project.bash +21 -0
- package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_instance.bash~ +1 -0
- package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_project.bash~ +26 -0
- package/projects/old/example-complete.bak/.editorbackup/dotpi_project.bash~ +21 -0
- package/projects/old/example-complete.bak/.editorbackup/dotpi_tmp.bash~ +3 -0
- package/projects/old/example-complete.bak/.editorbackup/wpa_supplicant.conf~ +37 -0
- package/projects/old/example-complete.bak/configuration/.editorbackup/dotpi_project.bash~ +21 -0
- package/projects/old/example-complete.bak/configuration/dotpi_project.bash +21 -0
- package/projects/old/example-complete.bak/configuration/jackd/.editorbackup/dotpi_jackd.bash~ +14 -0
- package/projects/old/example-complete.bak/configuration/jackd/dotpi_jackd.bash +14 -0
|
@@ -0,0 +1,420 @@
|
|
|
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
|
+
}
|