Skip to content

Instantly share code, notes, and snippets.

@jazinheira
Created November 28, 2018 00:09
Show Gist options
  • Save jazinheira/439467ca123b6eda513eebfa92616100 to your computer and use it in GitHub Desktop.
Save jazinheira/439467ca123b6eda513eebfa92616100 to your computer and use it in GitHub Desktop.
Pull all the legacy courses listed in course_list.txt and replace old resource URLs with archival URLs
#!/bin/bash
old_url_regex="https?://www.saylor.org/site"
replace_url="https://resources.saylor.org/archived"
commit_msg="Replace legacy www.saylor.org resource URLs with archival URLs."
while read course_name; do
echo $course_name;
repo="https://github.com/saylordotorg/${course_name}"
git clone ${repo} ${course_name}
# Replace old url instances on all files
cd ./${course_name}
git checkout master
for file in ./*.md; do
echo "sed - ${file}"
sed -r -i 's|(https?://web.archive.org/[a-zA-Z0-9/]+)?https?://www.saylor.org/site|https://resources.saylor.org/archived|g' ${file}
done
# Commit and push changes
echo "Git - Adding changes"
git add .
echo "Git - Commiting changes"
git commit -m "${commit_msg}"
# Push changes
git push -u origin master
# Merge changes into jekyll branch
git checkout jekyll
git merge master
git push -u origin jekyll
# Move back to base directory
cd ../
done <course_list.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment