Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment Client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment Client
Commits
1ed0c774
Commit
1ed0c774
authored
4 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
Warn on missing replacements; handle Ruby vars with single and double quotes
parent
0d73c943
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/create_config.sh
+26
-15
26 additions, 15 deletions
bin/create_config.sh
with
26 additions
and
15 deletions
bin/create_config.sh
+
26
−
15
View file @
1ed0c774
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# 2020-12-15 v0.0 <axel.hahn@iml.unibe.ch>
# 2020-12-15 v0.0 <axel.hahn@iml.unibe.ch>
# 2021-05-07 v1.0 <axel.hahn@iml.unibe.ch> multiple replacement files
# 2021-05-07 v1.0 <axel.hahn@iml.unibe.ch> multiple replacement files
# 2021-05-27 v1.1 <axel.hahn@iml.unibe.ch> Warn on missing replacements; handle Ruby vars with single and double quotes
# ======================================================================
# ======================================================================
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
...
@@ -78,10 +79,11 @@ if [ $? -ne 0 ]; then
...
@@ -78,10 +79,11 @@ if [ $? -ne 0 ]; then
exit
2
exit
2
fi
fi
echo
---
Replacements to apply:
typeset
-i
iReplacements
=
$(
grep
"^[a-zA-Z]"
$replacefile
|
grep
"="
|
wc
-l
)
grep
"^[a-zA-Z]"
$replacefile
|
grep
"="
echo
---
Replacements to apply:
$iReplacements
if
[
$?
-ne
0
]
;
then
if
[
$iReplacements
-eq
0
]
;
then
_err
"ERROR: No replacements were found ... wrong syntax? Use KEY = VALUE."
_err
"ERROR: No replacements were found ... maybe a wrong syntax?"
_err
" Use KEY=VALUE; no spaces in front; now quotes around VALUE"
exit
2
exit
2
fi
fi
...
@@ -94,19 +96,27 @@ do
...
@@ -94,19 +96,27 @@ do
key
=
$(
echo
$line
|
cut
-f
2-
-d
":"
|
cut
-f
1
-d
"="
)
key
=
$(
echo
$line
|
cut
-f
2-
-d
":"
|
cut
-f
1
-d
"="
)
val
=
$(
echo
$line
|
cut
-f
2-
-d
"="
)
val
=
$(
echo
$line
|
cut
-f
2-
-d
"="
)
regex
=
"<
\%\=\
*
\@
replace
\[\"
$key
\"\]\
*
\%
>"
# Ruby erb template syntax to write a variable: <% @replace["mykey"] %>
grep
"
$regex
"
$tmpfile
>
/dev/null
||
echo
"WARNING: template [
$tplfile
] has no placeholder key [
$key
]"
# Here are 2 regex to handle single and double quotes
# Ruby erb template syntax: <% @replace["mykey"] %>
regex1
=
"<
\%\=\
*
\@
replace
\[\'
$key
\'\]\
*
\%
>"
# sed -i "s#<\%\ *\@replace\[\"$key\"\]\ *\%>#$val#g" $tmpfile
regex2
=
"<
\%\=\
*
\@
replace
\[\"
$key
\"\]\
*
\%
>"
sed
-i
"s#
$regex
#
$val
#g"
$tmpfile
# Show a warning if both regex do not match
grep
"
$regex1
"
$tmpfile
>
/dev/null
\
||
grep
"
$regex2
"
$tmpfile
>
/dev/null
\
||
echo
"WARNING: template [
$tplfile
] has no placeholder key [
$key
]"
sed
-i
"s#
$regex1
#
$val
#g"
$tmpfile
sed
-i
"s#
$regex2
#
$val
#g"
$tmpfile
done
done
# --- verify changes
# --- verify changes
echo
echo
echo
---
c
hanges:
echo
---
C
hanges:
diff
"
$tplfile
"
"
$tmpfile
"
diff
"
$tplfile
"
"
$tmpfile
"
if
[
$?
-eq
0
]
;
then
if
[
$?
-eq
0
]
;
then
_err
"ERROR: template was unchanged. Check placeholders in
$tplfile
and replacements:"
_err
"ERROR: template was unchanged. Check placeholders in
$tplfile
and replacements:"
echo
Content of relacement files:
cat
$replacefile
cat
$replacefile
exit
3
exit
3
fi
fi
...
@@ -115,23 +125,24 @@ fi
...
@@ -115,23 +125,24 @@ fi
mv
-f
"
${
tmpfile
}
"
"
${
outfile
}
"
mv
-f
"
${
tmpfile
}
"
"
${
outfile
}
"
echo
echo
echo
---
o
utput file:
echo
---
O
utput file:
ls
-l
"
${
outfile
}
"
ls
-l
"
${
outfile
}
"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
_err
"ERROR: unable to write target file
$outfile
."
_err
"ERROR: unable to write target file
$outfile
."
exit
4
exit
4
fi
fi
grep
'<\%\=\ *\@replace\[\"'
${
outfile
}
>
/dev/null
echo
---
Check missing replacements
grep
'<\%\=\ *\@replace\['
${
outfile
}
>
/dev/null
if
[
$?
-eq
0
]
;
then
if
[
$?
-eq
0
]
;
then
echo
echo
_warn
"WARNING: Maybe you need to verify replacements (
can
be a false positive)"
_warn
"WARNING: Maybe you need to verify replacements (
hmmm, could
be a false positive
too
)"
grep
'<\%\=\ *\@replace\[
\"
'
${
outfile
}
grep
'<\%\=\ *\@replace\['
${
outfile
}
else
else
_ok
"OK"
_ok
"OK"
fi
fi
exit
0
exit
0
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment