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
13dd2495
Commit
13dd2495
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
create a uniq tmp file
parent
b9493eda
No related branches found
No related tags found
1 merge request
!19
create a uniq tmp file
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/create_config.sh
+21
-10
21 additions, 10 deletions
bin/create_config.sh
with
21 additions
and
10 deletions
bin/create_config.sh
+
21
−
10
View file @
13dd2495
...
...
@@ -4,12 +4,15 @@
# IML DEPLOYMENT ... REPLACE SCRIPT FOR TEMPLATES
#
# ----------------------------------------------------------------------
#
# SYNTAX:
# create_config.sh TEMPLATEFILE OUTPUTFILE REPLACEMENTFILE(S)
# It finishes with non zero exitcode on any error.
# ----------------------------------------------------------------------
# 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-27 v1.1 <axel.hahn@iml.unibe.ch> Warn on missing replacements; handle Ruby vars with single and double quotes
# 2021-11-01 v1.2 <axel.hahn@iml.unibe.ch> save config diffs for deploy_app.sh
# 2023-12-19 v1.3 <axel.hahn@iml.unibe.ch> create a uniq tmp file
# ======================================================================
# ----------------------------------------------------------------------
...
...
@@ -22,7 +25,7 @@ shift 2
replacefile
=
$*
test
-z
"
$replacefile
"
&&
replacefile
=
"replace*.txt"
tmpfile
=
/tmp/myreplacement.tmp
tmpfile
=
$(
mktemp
-u
)
usage
=
"USAGE:
$(
basename
$0
)
TEMPLATE-FILE OUTFILE [optional: REPLACE-DATA-FILE(S)]"
# cfgdiff is set in setProfile in ../deploy_app.sh while running through a profile
...
...
@@ -89,11 +92,11 @@ echo --- Replacements to apply: $iReplacements
if
[
$iReplacements
-eq
0
]
;
then
_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
3
fi
# --- create temporary file to make all replacements in it
cat
$tplfile
>
$
tmpfile
cat
"
$tplfile
"
>
"
${
tmpfile
}
"
# --- apply replace rules
grep
"^[a-zA-Z]"
$replacefile
|
grep
"="
|
while
read
line
...
...
@@ -108,14 +111,21 @@ do
regex2
=
"<
\%\=\
*
\@
replace
\[\"
$key
\"\]\
*
\%
>"
# Show a warning if both regex do not match
grep
"
$regex1
"
$
tmpfile
>
/dev/null
\
||
grep
"
$regex2
"
$
tmpfile
>
/dev/null
\
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
sed
-i
"s#
$regex1
#
$val
#g"
"
${
tmpfile
}
"
sed
-i
"s#
$regex2
#
$val
#g"
"
${
tmpfile
}
"
done
# --- if file actions would destroy our file - maybe it never happens
if
[
!
-f
"
${
tmpfile
}
"
]
;
then
_err
"ERROR: Something strange happened: the created tmpfile does not exist anymore."
_err
"
${
tmpfile
}
"
exit
4
fi
# --- verify changes
echo
echo
---
Changes:
...
...
@@ -140,16 +150,17 @@ diff "${outfile}" "${tmpfile}" >/dev/null 2>/dev/null || bHasChanges=1
diff
"
${
outfile
}
"
"
${
tmpfile
}
"
|
sed
"s#^#
${
outfile
}
#g"
>>
${
cfgdiff
}
2>/dev/null
if
[
$bHasChanges
-eq
0
]
;
then
_warn
"INFO: no changes in
${
outfile
}
."
rm
-f
"
${
tmpfile
}
"
else
echo
"INFO: writing
${
outfile
}
..."
mv
-f
"
${
tmpfile
}
"
"
${
outfile
}
"
||
exit
4
mv
-f
"
${
tmpfile
}
"
"
${
outfile
}
"
||
exit
5
fi
ls
-l
"
${
outfile
}
"
if
[
$?
-ne
0
]
;
then
_err
"ERROR: unable to write target file
$outfile
."
exit
4
exit
6
fi
echo
...
...
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