-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
repair
executable file
·110 lines (76 loc) · 2.52 KB
/
repair
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
source "$rvm_path/scripts/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() {
(
builtin cd "$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_path/scripts/log" "info" \
"Removing stale symlink from $(basename "$executable_name")"
\rm -f "$executable_name"
fi
done
)
}
# Regenerates each symlink file.
repair_environments() {
local environment_name environments
environments=($(cd "$rvm_environments_path" ; find . -maxdepth 1 -mindepth 1 -type f))
for environment_name in "${environments[@]//.\/}" ; do
[[ -L "$rvm_environments_path/$environment_name" ]] && continue
"$rvm_path/scripts/log" "info" \
"Regenerating environment file for '$environment_name'"
[[ -f "$rvm_environments_path/$environment_name" ]] && \rm -f "$rvm_environments_path/$environment_name"
(
source "$rvm_path/scripts/base"
__rvm_become "$environment_name"
__rvm_ensure_has_environment_files
)
done
}
# Removes archives that have incorrect md5 sums.
repair_archives() {
local archive_file archives stored_md5sum
archives=($(cd "$rvm_archives_path" ; find . -maxdepth 1 -mindepth 1 -type f))
for archive_file in "${archives[@]//.\/}" ; do
[[ -f "$rvm_archives_path/$archive_file" ]] || continue
stored_md5sum="$($rvm_path/scripts/db "$rvm_config_path/md5" "$archive_file" | head -n1)"
if [[ -n "$stored_md5sum" ]] ; then
if [[ ! "$rvm_path/scripts/md5" "$rvm_archives_path/$archive_file" "$stored_md5sum" ]] ; then
"$rvm_path/scripts/log" "info" "Removing archive for '$archive_file' - Incorrect md5 checksum."
rm -rf "$rvm_archives_path/$archive_file"
fi
fi
done
return 0
}
repair_all() {
repair_symlinks
repair_archives
repair_environments
"$rvm_path/scripts/log" "info" \
"symlinks, archives and environments have been repaired."
return 0
}
args=($*)
action="${args[0]}"
args="$(echo ${args[@]:1}) " # Strip trailing / leading / extra spacing.
if [[ -z "$action" ]]; then
usage
exit $?
fi
case "$action" in
all) repair_all ;;
symlinks) repair_symlinks ;;
environments) repair_environments ;;
archives) repair_archives;;
*) usage ;;
esac
exit $?