• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyberShadow / aconfmgr / 662

22 Dec 2025 03:28PM UTC coverage: 91.427% (-2.3%) from 93.708%
662

Pull #232

github

CyberShadow-Renovate
Update dependency aura to v20251216074710
Pull Request #232: Update dependency aura to v20251216074710

0 of 1 new or added line in 1 file covered. (0.0%)

124 existing lines in 16 files now uncovered.

4586 of 5016 relevant lines covered (91.43%)

407.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/helpers.bash
1
# helpers.bash
2

3
# This file contains helper functions for the generated configuration scripts.
4

5
#
6
# AddPackage [--foreign] PACKAGE...
7
#
8
# Adds a package to the list of packages to be installed.
9
#
10

11
# shellcheck disable=SC2329  # User-facing API function called from config files
12
function AddPackage() {
13
        local fn='packages.txt'
535✔
14
        if [[ "$1" == "--foreign" ]]
535✔
15
        then
16
                shift
37✔
17
                fn='foreign-packages.txt'
37✔
18
        fi
19

20
        printf '%q\n' "$@" >> "$output_dir"/"$fn"
535✔
21
}
22

23
#
24
# AddPackageGroup GROUP
25
#
26
# Adds all packages belonging to a group to the list of packages to be installed.
27
#
28

29
# shellcheck disable=SC2329  # User-facing API function called from config files
30
function AddPackageGroup() {
31
        local group=$1
1✔
32

33
        pacman --sync --quiet --groups "$group" >> "$output_dir"/packages.txt
1✔
34
}
35

36
#
37
# RemovePackage [--foreign] PACKAGE...
38
#
39
# Removes an earlier-added package to the list of packages to be installed.
40
#
41
# Emitted by `aconfmgr save` when a package is present in the configuration,
42
# but absent on the system.
43
#
44
# You should refactor out any occurrences of this function from your configuration.
45
#
46

47
# shellcheck disable=SC2329  # User-facing API function called from config files
48
function RemovePackage() {
49
        local fn='packages.txt'
15✔
50
        if [[ "$1" == "--foreign" ]]
15✔
51
        then
52
                shift
5✔
53
                fn='foreign-packages.txt'
5✔
54
        fi
55

56
        local package
15✔
57
        for package in "$@"
15✔
58
        do
59
                sed -i "$output_dir"/"$fn" -e "/^${package}\$/d"
15✔
60
        done
61
}
62

63
#
64
# IgnorePackage [--foreign] PACKAGE...
65
#
66
# Adds a package to the list of packages to be ignored.
67
#
68

69
# shellcheck disable=SC2329  # User-facing API function called from config files
70
function IgnorePackage() {
71
        if [[ "$1" == "--foreign" ]]
187✔
72
        then
73
                shift
108✔
74
                ignore_foreign_packages+=("$@")
109✔
75
        else
76
                ignore_packages+=("$@")
78✔
77
        fi
78
}
79

80
#
81
# CopyFile PATH [MODE [OWNER [GROUP]]]
82
#
83
# Copies a file from the "files" subdirectory to the output.
84
#
85
# The specified path should be relative to the root of the "files" subdirectory.
86
#
87
# If MODE, OWNER and GROUP are blank or unspecified, they default to
88
# "644", "root" and "root" respectively for new files.
89
# Values corresponding to the above defaults must be specified
90
# as an empty string ('').
91
#
92

93
# shellcheck disable=SC2329  # User-facing API function called from config files
94
function CopyFile() {
95
        local file="$1"
3✔
96
        local mode="${2:-}"
3✔
97
        local owner="${3:-}"
3✔
98
        local group="${4:-}"
3✔
99

100
        CopyFileTo "$file" "$file" "$mode" "$owner" "$group"
3✔
101
}
102

103
#
104
# CopyFileTo SRC-PATH DST-PATH [MODE [OWNER [GROUP]]]
105
#
106
# Copies a file from the "files" subdirectory to the output,
107
# under a different name or path.
108
#
109
# The source path should be relative to the root of the "files" subdirectory.
110
# The destination path is relative to the root of the output directory.
111
#
112

113
# shellcheck disable=SC2329  # User-facing API function called from config files
114
function CopyFileTo() {
115
        local src_file="$1"
4✔
116
        local dst_file="$2"
4✔
117
        local mode="${3:-}"
4✔
118
        local owner="${4:-}"
4✔
119
        local group="${5:-}"
4✔
120

121
        if [[ "$src_file" != /* ]]
4✔
122
        then
123
                ConfigWarning 'Source file path %s is not absolute.\n' \
2✔
124
                                          "$(Color C "%q" "$src_file")"
2✔
125
        fi
126

127
        if [[ "$dst_file" != /* && "$dst_file" != "$src_file" ]]
5✔
128
        then
129
                ConfigWarning 'Target file path %s is not absolute.\n' \
2✔
130
                              "$(Color C "%q" "$dst_file")"
2✔
131
        fi
132

133
        mkdir --parents "$(dirname "$output_dir"/files/"$dst_file")"
8✔
134

UNCOV
135
        cp --no-dereference\
×
136
           "$config_dir"/files/"$src_file"\
4✔
137
           "$output_dir"/files/"$dst_file"
4✔
138

139
        SetFileProperty "$dst_file" mode  "$mode"
4✔
140
        SetFileProperty "$dst_file" owner "$owner"
4✔
141
        SetFileProperty "$dst_file" group "$group"
4✔
142

143
        used_files["$src_file"]=y
4✔
144
}
145

146
#
147
# CreateFile [--no-clobber] PATH [MODE [OWNER [GROUP]]]
148
#
149
# Creates an empty file, to be included in the output.
150
# Prints its absolute path to standard output.
151
#
152
# Avoids overwriting any pre-existing output file if
153
# --no-clobber is provided.
154
#
155

156
# shellcheck disable=SC2329  # User-facing API function called from config files
157
function CreateFile() {
158
        local keep=false
46✔
159
        if [[ "$1" == "--no-clobber" ]]
46✔
160
        then
161
                keep=true
×
162
                shift
×
163
        fi
164

165
        local file="$1"
46✔
166
        local mode="${2:-}"
46✔
167
        local owner="${3:-}"
46✔
168
        local group="${4:-}"
46✔
169

170
        local output_file="$output_dir"/files/"$file"
46✔
171

172
        mkdir --parents "$(dirname "$output_file")"
92✔
173

174
        if [[ -h "$output_file" || -e "$output_file" ]]
92✔
175
        then
176
                if $keep
×
177
                then
178
                        printf '%s' "$output_file"
×
179
                        return
×
180
                else
181
                        ConfigWarning 'Overwriting %s, which was created earlier in the configuration. Use %s to keep old contents, or silence this warning by calling %s first.\n' \
×
182
                                                  "$(Color C "%q" "$file")" \
×
183
                                                  "$(Color Y "CreateFile --no-clobber")" \
×
184
                                                  "$(Color Y "RemoveFile")"
×
185
                fi
186
        fi
187

188
        truncate --size 0 "$output_file"
46✔
189

190
        SetFileProperty "$file" mode  "$mode"
46✔
191
        SetFileProperty "$file" owner "$owner"
46✔
192
        SetFileProperty "$file" group "$group"
46✔
193

194
        printf '%s' "$output_file"
46✔
195
}
196

197
#
198
# GetPackageOriginalFile [--no-clobber] PACKAGE PATH
199
#
200
# Extracts the original file from a package's archive for inclusion in the output.
201
# Prints its absolute path to standard output.
202
#
203
# As in the case of CreateFile, the file can be further modified after extraction.
204
#
205
# Avoids overwriting any pre-existing output file if
206
# --no-clobber is provided.
207
#
208

209
# shellcheck disable=SC2329  # User-facing API function called from config files
210
function GetPackageOriginalFile() {
211
        local keep=false
11✔
212
        if [[ "$1" == "--no-clobber" ]]
11✔
213
        then
214
                keep=true
2✔
215
                shift
2✔
216
        fi
217

218
        local package="$1" # Package to extract the file from
11✔
219
        local file="$2" # Absolute path to file in package
11✔
220

221
        local output_file="$output_dir"/files/"$file"
11✔
222

223
        mkdir --parents "$(dirname "$output_file")"
22✔
224

225
        if [[ -h "$output_file" || -e "$output_file" ]]
22✔
226
        then
227
                if $keep
2✔
228
                then
229
                        printf '%s' "$output_file"
1✔
230
                        return
1✔
231
                else
232
                        ConfigWarning 'Overwriting %s, which was created earlier in the configuration. Use %s to keep old contents, or silence this warning by calling %s first.\n' \
4✔
233
                                                  "$(Color C "%q" "$file")" \
4✔
234
                                                  "$(Color Y "GetPackageOriginalFile --no-clobber")" \
4✔
235
                                                  "$(Color Y "RemoveFile")"
4✔
236
                fi
237
        fi
238

239
        AconfGetPackageOriginalFile        "$package" "$file" > "$output_file"
10✔
240

241
        printf '%s' "$output_file"
10✔
242
}
243

244
#
245
# CreateLink PATH TARGET [OWNER [GROUP]]
246
#
247
# Creates a symbolic link with the specified target.
248
#
249

250
# shellcheck disable=SC2329  # User-facing API function called from config files
251
function CreateLink() {
252
        local file="$1"
15✔
253
        local target="$2"
15✔
254
        local owner="${3:-}"
15✔
255
        local group="${4:-}"
15✔
256

257
        mkdir --parents "$(dirname "$output_dir"/files/"$file")"
30✔
258

259
        ln --symbolic -- "$target" "$output_dir"/files/"$file"
15✔
260

261
        SetFileProperty "$file" owner "$owner"
15✔
262
        SetFileProperty "$file" group "$group"
15✔
263
}
264

265
#
266
# CreateDir PATH [MODE [OWNER [GROUP]]]
267
#
268
# Creates an empty directory at the specified path.
269
#
270
# Normally calling this function is not necessary, as creating files
271
# will implicitly create all parent directories. Use this function
272
# only when you need to create an empty directory without any files in
273
# it.
274
#
275

276
# shellcheck disable=SC2329  # User-facing API function called from config files
277
function CreateDir() {
278
        local file="$1"
12✔
279
        local mode="${2:-}"
12✔
280
        local owner="${3:-}"
12✔
281
        local group="${4:-}"
12✔
282

283
        mkdir --parents "$output_dir"/files/"$file"
12✔
284

285
        SetFileProperty "$file" mode  "$mode"
12✔
286
        SetFileProperty "$file" owner "$owner"
12✔
287
        SetFileProperty "$file" group "$group"
12✔
288
}
289

290
#
291
# RemoveFile PATH
292
#
293
# Removes an earlier-added file.
294
#
295
# Emitted by `aconfmgr save` when a file is present in the configuration,
296
# but absent (or, in case of files owned by packages, unmodified) on the system.
297
#
298
# You should refactor out any occurrences of this function from your configuration.
299
#
300
# If you want to delete a file owned by a package, instead use:
301
# SetFileProperty /path/to/file deleted y
302
#
303

304
# shellcheck disable=SC2329  # User-facing API function called from config files
305
function RemoveFile() {
306
        local file="$1"
18✔
307

308
        rm --dir "$output_dir"/files/"$file"
18✔
309
}
310

311
#
312
# SetFileProperty PATH TYPE VALUE
313
#
314
# Sets a file property.
315
# TYPE can be "owner", "group" "mode", or "deleted".
316
#
317
# Set "deleted" to "y" to mark a file owned by some package for deletion.
318
#
319
# To reset a file property to its default value,
320
# specify an empty string ('') for the VALUE parameter.
321
#
322

323
# shellcheck disable=SC2329  # User-facing API function called from config files
324
function SetFileProperty() {
325
        local file="$1"
241✔
326
        local type="$2"
241✔
327
        local value="$3"
241✔
328

329
        printf '%s\t%s\t%q\n' "$type" "$value" "$file" >> "$output_dir"/file-props.txt
241✔
330
}
331

332
#
333
# IgnorePath PATH
334
#
335
# Adds the specified path to the list of ignored paths.
336
#
337
# The argument should be a shell pattern, e.g. '/etc/foo/*'.
338
#
339

340
# shellcheck disable=SC2329  # User-facing API function called from config files
341
function IgnorePath() {
342
        ignore_paths+=("$@")
574✔
343
}
344

345
#
346
# AddFileContentFilter PATTERN FUNCTION
347
#
348
# Adds a filter for paths matching the given PATTERN (bash syntax).
349
#
350
# The function is called with the file name as the only parameter, the
351
# file contents on its stdin, and is expected to provide the filtered
352
# contents on its stdout.
353
#
354
# Only one function can be configured per unique PATTERN.  The most
355
# recently added PATTERN takes precedence over any matching patterns
356
# preceding it.
357
#
358

359
# shellcheck disable=SC2329  # User-facing API function called from config files
360
function AddFileContentFilter() {
361
        local pattern=$1
6✔
362
        local function=$2
6✔
363

364
        file_content_filters[$pattern]=$function
6✔
365
}
366

367
: # include in coverage
134✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc