Skip to content

Commit

Permalink
Merge pull request #4637 from jan-cerny/create_file
Browse files Browse the repository at this point in the history
Fix problems with creating files in include_lineinfile.sh
  • Loading branch information
yuumasato authored Jul 22, 2019
2 parents 52ba3b6 + f85eaf0 commit f233baf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions shared/bash_remediation_functions/include_lineinfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@ function lineinfile() {
local insert_before="$7"
local insensitive="${8:-true}"

[ ! -e "$path" ] && [ "$create" != "true" ] && die "Path '$path' wasn't found on this system and not creating. Refusing to continue."
[ ! -e "$path" ] && [ "$create" == "true" ] && touch "$path"

if [ "$state" == "absent" ]; then
lineinfile_absent "$path" "$regex" "$insensitive"
if [ "$state" == "absent" ] ; then
if [ -e "$path" ] ; then
lineinfile_absent "$path" "$regex" "$insensitive"
fi
elif [ "$state" == "present" ]; then
if [ ! -e "$path" ] ; then
if [ "$create" == "true" ] ; then
touch "$path"
else
die "Path '$path' wasn't found on this system and option 'create' is set to '$create'. Refusing to continue."
fi
fi
lineinfile_present "$path" "$regex" "$line" "$insert_after" "$insert_before" "$insensitive"
fi
}
Expand Down Expand Up @@ -141,5 +147,5 @@ function sshd_config_set() {
local parameter="$1"
local value="$2"

set_config_file "/etc/ssh/sshd_config" "$parameter" "$value" "yes" '' '^Match' 'true'
set_config_file "/etc/ssh/sshd_config" "$parameter" "$value" "true" '' '^Match' 'true'
}

0 comments on commit f233baf

Please sign in to comment.