I am trying to modify the set of YAML files & Swagger YAML files using bash script to avoid manual copy paste work.
My directory looks like below :-
C:.
├───folder-1
├─── README.md
├─── dev.yaml
├─── prod.yaml
├─── qa.yaml
└─── run.ps1
├───folder-2
├─── README.md
├─── dev.yaml
├─── prod.yaml
├─── qa.yaml
├─── run.ps1
├─── sample.yaml
├─── swagger-1.yaml
└─── swagger-2.yaml
I wanted loop over folder-1 , folder-2 And edit all dev, qa, prod YAML for appending some text and all swagger.yaml in another appending
Here is my beginning level of script
for d in *; do
echo $d
cd $d
ls -l
cd ..
done
With above script I am only able to list all folders and its files. I need help how do I append the file ? for just an example, I wanted add 'dummy' as content in each of target files.
Thanks in advance !!
CodePudding user response:
for d in *; do
echo $d
cp -a ./resources/. ./$d/
cd $d
for f in *.yaml; do
if [[ "$f" = kong* ]];
then
yq e -i '._info.select_tags = [.services[].name]' $f
else
yq e -i '(.security.gas-oidc = []) | (.components.securitySchemes.gas-oidc.type = "oauth2") ' $f
fi
done
echo "Files are modified now pushing to git repository"
git add .
git commit -m "Batch for commit in git"
git commit
git push origin master:dev
cd ..
done