Skip to content

Instantly share code, notes, and snippets.

@tamsky
Created February 12, 2014 04:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsky/8949934 to your computer and use it in GitHub Desktop.
Save tamsky/8949934 to your computer and use it in GitHub Desktop.
script that performs global search and replace of a URL within a Chrome User Profile
#!/bin/bash
# Primary goal is renaming $OLD http or https urls to $NEW https urls
# Instructions
#
# Before you start, locate and *BACKUP* your Chrome folder:
# on OSX it's at: ~/Library/Application Settings/Google/Chrome
#
# Next:
# Disable chrome sync at https://www.google.com/settings/chrome/sync
# Use the "Stop and Clear" button on that page.
# This will disable chrome sync for this account on all devices, including phones.
# 1. Quit Chrome. Make sure it is not running.
# 2. Find the correct user's profile directory
# on OSX: ~/Library/Application Settings/Google/Chrome/Profile [0-9]+/
# 3. cd to the profile directory found in step 2.
# 4. 'grep username Preferences' to verify.
# 5. run this script
# 6. launch Chrome
# 7. QUIT CHROME AGAIN
# 8. run this script AGAIN
# 9. launch Chrome
# 10. Re-enable sync at chrome://settings/, click "Set up sync..." button, set options, click ok.
# Re-enable sync on any other devices (phones, other computers, etc).
# 11. profit!
OLD_JIRA=jira.olddomain.example.com
NEW_JIRA=jira.newdomain.example.com
OLD_WIKI=wiki.olddomain.example.com
NEW_WIKI=wiki.newdomain.example.com
# stop on any error
set -e
function doit () {
cat << EOF | sqlite3 "Archived History"
select count(*) from urls where url like "http://${OLD}%";
select count(*) from urls where url like "https://${OLD}%";
update urls set url = replace(url, "http://${OLD}", "${NEW}") where url like "http://${OLD}%";
update urls set url = replace(url, "https://${OLD}", "${NEW}") where url like "https://${OLD}%";
select count(*) from urls where url like "https://${OLD}%";
select count(*) from urls where url like "http://${OLD}%";
EOF
cat << EOF | sqlite3 History
select count(*) from urls where url like "http://${OLD}%";
select count(*) from urls where url like "https://${OLD}%";
update urls set url = replace(url, "http://${OLD}", "${NEW}") where url like "http://${OLD}%";
update urls set url = replace(url, "https://${OLD}", "${NEW}") where url like "https://${OLD}%";
update segments set name = replace(name, "http://${OLD}", "${NEW}") where name like "http://${OLD}%";
update segments set name = replace(name, "https://${OLD}", "${NEW}") where name like "https://${OLD}%";
select count(*) from urls where url like "https://${OLD}%";
select count(*) from urls where url like "http://${OLD}%";
EOF
cat << EOF | sqlite3 "Top Sites"
update thumbnails set url = replace(url, "http://${OLD}", "${NEW}") where url like "http://${OLD}%";
update thumbnails set url = replace(url, "https://${OLD}", "${NEW}") where url like "https://${OLD}%";
EOF
cat << EOF | sqlite3 Shortcuts
select count(url) from omni_box_shortcuts where url like "%${OLD}%";
update omni_box_shortcuts set url = replace(url, "http://${OLD}", "${NEW}") where url like "http://${OLD}%";
update omni_box_shortcuts set url = replace(url, "https://${OLD}", "${NEW}") where url like "https://${OLD}%";
select count(url) from omni_box_shortcuts where url like "%${OLD}%";
EOF
sed -i".bak" "s@http://${OLD}/@https://${NEW}/@" Bookmarks
sed -i".bak" "s@https://${OLD}/@https://${NEW}/@" Bookmarks
}
OLD=${OLD_JIRA}
NEW=${NEW_JIRA}
doit
OLD=${OLD_WIKI}
NEW=${NEW_WIKI}
doit
rm "History Provider Cache"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment