Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
atools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leo
atools
Commits
0af1494b
Commit
0af1494b
authored
Oct 10, 2019
by
Kevin Daudt
💻
Committed by
Leo
Oct 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initd-lint: add linting tool for openrc initd files
parent
58fa234c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
0 deletions
+108
-0
check.do
check.do
+4
-0
initd-lint
initd-lint
+38
-0
tests/initd-lint.bats
tests/initd-lint.bats
+66
-0
No files found.
check.do
View file @
0af1494b
exec >&2
echo ">>> Testing apkbuild-lint"
bats --tap tests/apkbuild-lint.bats
echo ">>> Testing initd-lint"
bats --tap tests/initd-lint.bats
initd-lint
0 → 100755
View file @
0af1494b
#!/bin/sh
lint_msg
()
{
local
msg
=
"
$1
"
tag
=
"
$2
"
severity
=
"
$3
"
printf
'%s:[%s]:%s:%s\n'
"
$severity
"
"
$tag
"
"
$service
"
"
$msg
"
}
scan
()
{
local
rx
=
"
$1
"
msg
=
"
$2
"
tag
=
"
$3
"
severity
=
"
$4
"
grep
-P
-Hn
-e
"
$rx
"
"
$service
"
|
sed
"s/^
\(
[^:]*:[^:]*:
\)\(
.*
\)
/
$severity
:[
$tag
]:
\1
$msg
/"
}
unexpected_shebang_line
()
{
shebang
=
$(
awk
'NR == 1'
"
$service
"
)
if
[
"
$shebang
"
!=
"#!/sbin/openrc-run"
]
;
then
lint_msg
"openrc init files should use '#!/sbin/openrc-run' as shebang line"
"AL33"
"IC"
fi
}
custom_start_stop_function
()
{
scan
'(start|stop)\s*\(\)\s*\{'
"Don't define a custom start
\/
stop function"
'AL34'
'IC'
}
_ret
=
0
for
service
;
do
if
[
!
-f
"
$service
"
]
;
then
echo
"error: no such file: '
$service
'"
exit
1
fi
unexpected_shebang_line
custom_start_stop_function
done
|
sort
-t
:
-V
|
grep
.
&&
_ret
=
1
exit
$_ret
tests/initd-lint.bats
0 → 100644
View file @
0af1494b
#!/usr/bin/env bats
cmd=./initd-lint
service=$BATS_TMPDIR/service.initd
assert_match() {
output=$1
expected=$2
echo "$output" | grep -qE "$expected"
}
@test 'warn about non-standard shebang' {
cat <<-"EOF" >$service
#!/bin/sh
cmd_run="my_service"
EOF
run $cmd $service
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "should use '#!/sbin/openrc-run'"
}
@test "don't warn about standard shebang" {
cat <<-"EOF" >$service
#!/sbin/openrc-run
cmd_run="my_service"
EOF
run $cmd $service
[[ $status -eq 0 ]]
}
@test "warn about custom start function" {
cat <<-"EOF" >$service
#!/sbin/openrc-run
start() {
start_command
}
EOF
run $cmd $service
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "custom start/stop function"
}
@test "warn about custom stop function" {
cat <<-"EOF" >$service
#!/sbin/openrc-run
stop () {
stop_command
}
EOF
run $cmd $service
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "custom start/stop function"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment