-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce 'cleanup-browser-profiles.sh' (#17)
Refactor 'clone_repo_into' to handle optional git branch to switch to. Use string manipulation syntax instead of calling 'basename' for perf
- Loading branch information
Showing
10 changed files
with
159 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# vim:filetype=zsh syntax=zsh tabstop=2 shiftwidth=2 softtabstop=2 expandtab autoindent fileencoding=utf-8 | ||
|
||
# This script is used to cleanup browser profiles folders (delete cache, session and other files that will anyways be recreated when you restart that browser). It can be safely invoked even if that browser is running (in which case it will skip processing after printing a warning to quit that application) | ||
|
||
type is_non_zero_string &> /dev/null 2>&1 || source "${HOME}/.shellrc" | ||
|
||
check_app() { | ||
if is_non_zero_string "$(pgrep "${1}")"; then | ||
warn "Shutdown '${1}' first!; skipping processing of files for ${1}" | ||
return 1 | ||
else | ||
return 0 | ||
fi | ||
} | ||
|
||
find_and_destroy() { | ||
find "${1}" -type "${2}" -iname "${3}" -delete | ||
} | ||
|
||
vacuum_browser_profile_folder() { | ||
local profile_folder="${2}" | ||
! is_directory "${profile_folder}" && warn "skipping processing of '${profile_folder}' since it doesn't exist" && return | ||
|
||
section_header "Vacuuming '${1}' in '${profile_folder}'..." | ||
echo "--> Size before: $(folder_size "${profile_folder}")" | ||
|
||
command_exists sqlite && find "${profile_folder}" -type f -iname '*.sqlite' -exec sqlite3 -line {} "VACUUM; REINDEX;" \; | ||
|
||
file_array=( | ||
'.DS_Store' | ||
'.localized' | ||
'.parentlock' | ||
'*.log' | ||
'*.sqlite-shm' | ||
'*.sqlite-wal' | ||
'*.bak*' | ||
'compatibility.ini' | ||
'extensions.rdf' | ||
'msgFilterRules.dat' | ||
'popstate.dat' | ||
'sessionstore.bak' | ||
'signons*.txt' | ||
'*healthreport*' | ||
'global-messages-db.sqlite' | ||
) | ||
for file in "${file_array[@]}"; do | ||
find_and_destroy "${profile_folder}" 'f' "${file}" | ||
done | ||
|
||
directory_array=( | ||
'ABphotos' | ||
'bookmarkbackups' | ||
'sessionstore-backups' | ||
'GoogleContacts' | ||
"Local\ Folders" | ||
'lnubackups' | ||
'minidumps' | ||
'SDThumbs' | ||
"smart\ mailboxes" | ||
'startupCache' | ||
'thumbnails' | ||
'*telemetry*' | ||
'weave' | ||
'crashes' | ||
'*healthreport*' | ||
) | ||
for directory in "${directory_array[@]}"; do | ||
find_and_destroy "${profile_folder}" 'd' "${directory}" | ||
done | ||
|
||
echo "--> Size after: $(folder_size "${profile_folder}")" | ||
success "Successfully processed profile folder for '${1}'" | ||
} | ||
|
||
process_browser() { | ||
check_app "${1}" && vacuum_browser_profile_folder "$@" | ||
} | ||
|
||
# TODO: Commented out since I am moving away from Arc and will delete that folder completely | ||
# process_browser arc "${PERSONAL_PROFILES_DIR}/ArcProfile" | ||
process_browser brave "${PERSONAL_PROFILES_DIR}/BraveProfile" | ||
# TODO: Commented out since I haven't tested that this works without losing auto-recreated data | ||
# process_browser chrome "${PERSONAL_PROFILES_DIR}/ChromeProfile" | ||
process_browser firefox "${PERSONAL_PROFILES_DIR}/FirefoxProfile" | ||
process_browser thunderbird "${PERSONAL_PROFILES_DIR}/ThunderbirdProfile" | ||
process_browser zen "${PERSONAL_PROFILES_DIR}/ZenProfile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,22 +32,30 @@ set_ssh_folder_permissions() { | |
} | ||
|
||
clone_repo_into() { | ||
ensure_dir_exists "${2}" | ||
if ! is_git_repo "${2}"; then | ||
local target_folder="${2}" | ||
ensure_dir_exists "${target_folder}" | ||
if ! is_git_repo "${target_folder}"; then | ||
local tmp_folder="$(mktemp -d)" | ||
git -C "${tmp_folder}" clone -q "${1}" . | ||
mv "${tmp_folder}/.git" "${2}" | ||
git -C "${2}" checkout . | ||
git -C "${2}" submodule update --init --recursive --remote --rebase --force | ||
mv "${tmp_folder}/.git" "${target_folder}" | ||
git -C "${target_folder}" checkout . | ||
git -C "${target_folder}" submodule update --init --recursive --remote --rebase --force | ||
rm -rf "${tmp_folder}" | ||
success "Successfully cloned '${1}' into '${2}'" | ||
success "Successfully cloned '${1}' into '${target_folder}'" | ||
|
||
local target_branch="${3}" | ||
if is_non_zero_string "${target_branch}"; then | ||
git -C "${target_folder}" switch "${target_branch}" | ||
local checked_out_branch="$(git -C "${target_folder}" branch --show-current)" | ||
[[ "${checked_out_branch}" != "${target_branch}" ]] && error "'${target_branch}' is not equal to the branch that was checked out: '${checked_out_branch}'; something is wrong. Please correct before retrying!" | ||
fi | ||
else | ||
warn "Skipping cloning of '${1}' since '${2}' is already a git repo" | ||
warn "Skipping cloning of '${1}' since '${target_folder}' is already a git repo" | ||
fi | ||
} | ||
|
||
clone_omz_plugin_if_not_present() { | ||
clone_repo_into "${1}" "${ZSH_CUSTOM}/plugins/$(basename "${1}")" | ||
clone_repo_into "${1}" "${ZSH_CUSTOM}/plugins/${1##*/}" | ||
} | ||
|
||
replace_executable_if_exists_and_is_not_symlinked() { | ||
|
@@ -189,11 +197,7 @@ if is_non_zero_string "${DOTFILES_DIR}" && ! is_git_repo "${DOTFILES_DIR}"; then | |
rm -rf "${ZDOTDIR}/.zshrc" | ||
|
||
# Note: Cloning with https since the ssh keys will not be present at this time | ||
clone_repo_into "https://github.com/${GH_USERNAME}/dotfiles" "${DOTFILES_DIR}" | ||
|
||
git -C "${DOTFILES_DIR}" switch "${DOTFILES_BRANCH}" | ||
local_branch="$(git -C "${DOTFILES_DIR}" branch --show-current)" | ||
[[ "${local_branch}" != "${DOTFILES_BRANCH}" ]] && error "'DOTFILES_BRANCH' env var is not equal to the branch that was checked out: '${local_branch}'; something is wrong. Please correct before retrying!" | ||
clone_repo_into "https://github.com/${GH_USERNAME}/dotfiles" "${DOTFILES_DIR}" "${DOTFILES_BRANCH}" | ||
|
||
append_to_path_if_dir_exists "${DOTFILES_DIR}/scripts" | ||
|
||
|
@@ -355,8 +359,8 @@ if is_non_zero_string "${KEYBASE_USERNAME}"; then | |
if is_non_zero_string "${KEYBASE_PROFILES_REPO_NAME}" && is_non_zero_string "${PERSONAL_PROFILES_DIR}"; then | ||
clone_repo_into "$(build_keybase_repo_url "${KEYBASE_PROFILES_REPO_NAME}")" "${PERSONAL_PROFILES_DIR}" | ||
|
||
# Clone the natsumi-browser repo into the ZenProfile/Profiles/chrome folder | ||
is_directory "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/" && clone_repo_into "[email protected]:greeeen-dev/natsumi-browser" "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/chrome" | ||
# Clone the natsumi-browser repo into the ZenProfile/Profiles/chrome folder and switch to the 'dev' branch | ||
is_directory "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/" && clone_repo_into "[email protected]:vraravam/natsumi-browser" "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/chrome" dev | ||
else | ||
warn "skipping cloning of profiles repo since either the 'KEYBASE_PROFILES_REPO_NAME' or the 'PERSONAL_PROFILES_DIR' env var hasn't been set" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters