sed wrapper (#2158)

* sed wrapper 'sedfile' added

* formatting

* sed --> sedfile

* typo

* fix lint

* debug

* fixme

* mkcert fix

* style adjusted

* Update Dockerfile
This commit is contained in:
Casper 2021-09-06 00:07:02 +02:00 committed by GitHub
parent ed6421c9ab
commit e89ea3110f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 39 deletions

29
target/bin/sedfile Executable file
View file

@ -0,0 +1,29 @@
#!/bin/bash
# wrapper for 'sed -i': fail if file was not modified by sed
set -ueo pipefail
HASHTOOL="sha1sum"
if [[ $# -lt 1 ]]
then
echo "Error: No file given."
echo
exit 1
fi >&2
# get last argument
FILE=${*: -1}
OLD=$(${HASHTOOL} "${FILE}")
sed "$@"
NEW=$(${HASHTOOL} "${FILE}")
# fail if file was not modified
if [[ ${OLD} == "${NEW}" ]]
then
echo "Error: sed $*"
exit 1
fi >&2
exit 0