Script to change footer for sites in multiple git repos
I have several static sites and the content is in separate GitHub repositories. Each site has a footer with a copyright date. I wrote a script to update this copyright date.
# need the gh cli and jq
brew install gh jq
ORG=my-org
# get names only of all site repos
gh repo list --topic website --json name | jq ".[].name" -r > /tmp/repos.txt
for i in `cat /tmp/repos.txt`; do
echo $i
# checkout each repo to local
cd /tmp
gh repo clone $ORG/$i
cd /tmp/$i
# change the copyright footer and commit and store in a temp file
sed "s/2023/2024/g" index.html > index2.html
# swap into the correct file
mv index2.html index.html
# commit and push
git commit -am "Extend copyright into 2024"
git push
cd /tmp
# cleanup the local repo
rm -rf /tmp/$i
done;
# cleanup the list of repos
rm -rf /tmp/repos.txt
I learned about sponge a few days after using this script.