Skip to content

Commit 2b5c1c8

Browse files
errantodb
authored andcommitted
Update msfupdate to accommodate for forks and clones.
1 parent 1085357 commit 2b5c1c8

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

msfupdate

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ def is_svn
4040
File.directory?(File.join(@msfbase_dir, ".svn"))
4141
end
4242

43+
# Adding an upstream enables msfupdate to pull updates from
44+
# Rapid7's metasploit-framework repo instead of the repo
45+
# the user originally cloned or forked.
46+
def add_git_upstream
47+
$stdout.puts "[*] Attempting to add remote 'upstream' to your local git repository."
48+
system("git", "remote", "add", "upstream", "git://github.com/rapid7/rapid7metasploit-framework.git")
49+
$stdout.puts "[*] Added remote 'upstream' to your local git repository."
50+
end
51+
4352
def print_deprecation_warning
4453
$stdout.puts "[*] Deprecation Note: The next version of Metasploit will"
4554
$stdout.puts "[*] update over the git protocol, which requires outbound"
@@ -102,8 +111,12 @@ end
102111

103112
####### Since we're Git, do it all that way #######
104113
if is_git
105-
remote = @git_remote || "origin"
106-
branch = @git_branch || "master"
114+
out = `git remote show upstream`
115+
add_git_upstream unless $?.success? and out =~ %r{(https|git|git@github\.com):(//github\.com/)?(rapid7/metasploit-framework\.git)}
116+
117+
remote = @git_remote || "upstream"
118+
branch = @git_branchch || "master"
119+
107120
# This will save local changes in a stash, but won't
108121
# attempt to reapply them. If the user wants them back
109122
# they can always git stash pop them, and that presumes
@@ -114,22 +127,23 @@ if is_git
114127
# Note, this requires at least user.name and user.email
115128
# to be configured in the global git config. Installers should
116129
# take care that this is done. TODO: Enforce this in msfupdate
117-
res = system("git", "stash")
118-
if res.nil?
130+
committed = system("git", "diff", "--quiet", "HEAD")
131+
if committed.nil?
119132
$stderr.puts "[-] ERROR: Failed to run git"
120133
$stderr.puts ""
121134
$stderr.puts "[-] If you used a binary installer, make sure you run the symlink in"
122135
$stderr.puts "[-] /usr/local/bin instead of running this file directly (e.g.: ./msfupdate)"
123136
$stderr.puts "[-] to ensure a proper environment."
124137
exit 1
125-
else
126-
$stdout.puts "[*] Stashed local changes (if any) to avoid merge conflicts."
127-
$stdout.puts "[*] Run 'git stash pop' to reapply local changes."
138+
elsif not committed
139+
system("git", "stash")
140+
$stdout.puts "[*] Stashed local changes to avoid merge conflicts."
141+
$stdout.puts "[*] Run `git stash pop` to reapply local changes."
128142
end
129143

130144
system("git", "reset", "HEAD", "--hard")
131145
system("git", "checkout", branch)
132-
system("git", "fetch")
146+
system("git", "fetch", remote)
133147
system("git", "merge", "#{remote}/#{branch}")
134148
end
135149

0 commit comments

Comments
 (0)