#!/usr/bin/env bash source "$rvm_scripts_path/base" usage() { echo "Usage: rvm repair {symlinks,environments,archives,all}" >&2 return 1 } # Removes stale symlinks in $rvm_bin_path, likely # related to wrappers. repair_symlinks() { __rvm_pushpop "$rvm_bin_path" for executable_name in $(\find \. -type l); do [[ -e "$executable_name" || "$(readlink "$executable_name")" != "$rvm_wrappers_path/"* ]] && continue if [[ -f "$executable_name" ]] ; then $rvm_scripts_path/log "info" "Removing stale symlink from $(basename "$executable_name")" \rm -f "$executable_name" fi done; unset executable_name __rvm_pushpop } # Regenerates each symlink file. repair_environments() { for environment_name in $(\ls "$rvm_environments_path"); do [[ -L "$rvm_environments_path/$environment_name" ]] && continue $rvm_scripts_path/log "info" "Regenerating environment file for '$environment_name'" [[ -f "$rvm_environments_path/$environment_name" ]] && \rm -f "$rvm_environments_path/$environment_name" (source "$rvm_scripts_path/base"; __rvm_become "$environment_name"; __rvm_ensure_has_environment_files) done; unset environment_name } # Removes archives that have incorrect md5 sums. repair_archives() { for archive_file in $(\ls "$rvm_archives_path"); do [[ -f "$rvm_archives_path/$archive_file" ]] || continue local stored_md5sum="$($rvm_scripts_path/db "$rvm_config_path/md5" "$archive_file" | head -n1)" if [[ -n "$stored_md5sum" ]] && ! $rvm_scripts_path/md5 "$rvm_archives_path/$archive_file" "$stored_md5sum" ; then $rvm_scripts_path/log "info" "Removing archive for '$archive_file' - Incorrect md5 checksum." \rm -rf "$rvm_archives_path/$archive_file" fi done; unset archive_file } repair_all() { repair_symlinks repair_archives repair_environments $rvm_scripts_path/log "info" "All items repaired." } if [[ -z "$1" ]]; then usage exit $? fi case "$1" in all) repair_all ;; symlinks) repair_symlinks ;; environments) repair_environments ;; archives) repair_archives;; *) usage ;; esac exit $?