@@ -9,12 +9,14 @@ while File.symlink?(msfbase)
9
9
msfbase = File . expand_path ( File . readlink ( msfbase ) , File . dirname ( msfbase ) )
10
10
end
11
11
12
+ msfbase_dir = File . dirname ( msfbase )
13
+
12
14
@args = ARGV . dup
13
15
14
16
# May be changed
15
17
@configdir = File . expand_path ( File . join ( File . dirname ( msfbase ) , "data" , "svn" ) )
16
18
17
- Dir . chdir ( File . dirname ( msfbase ) )
19
+ Dir . chdir ( msfbase_dir )
18
20
19
21
$stderr. puts "[*]"
20
22
$stderr. puts "[*] Attempting to update the Metasploit Framework..."
@@ -26,16 +28,32 @@ if not (Process.uid == 0 or File.stat(msfbase).owned?)
26
28
$stderr. puts "Please run msfupdate as the same user who installed metasploit."
27
29
end
28
30
31
+
32
+ def is_git ( msfbase_dir )
33
+ File . directory? ( File . join ( msfbase_dir , ".git" ) )
34
+ end
35
+
36
+ def is_svn
37
+ File . directory? ( File . join ( msfbase_dir , ".svn" ) )
38
+ end
39
+
40
+ # TODO
41
+ def print_depreciation_warning
42
+
43
+ end
44
+
45
+ # Some of these args are meaningful for SVN, some for Git,
46
+ # some for both. Fun times.
29
47
@args . each_with_index do |arg , i |
30
48
case arg
31
- # Handle the old wait/nowait argument behavior
49
+ # Handle the old wait/nowait argument behavior
32
50
when "wait" , "nowait"
33
51
@wait_index = i
34
52
@actually_wait = ( arg == "wait" )
35
- # An empty or absent config-dir means a default config-dir
53
+ # An empty or absent config-dir means a default config-dir
36
54
when "--config-dir"
37
55
@configdir_index = i
38
- # A defined config dir means a defined config-dir
56
+ # A defined config dir means a defined config-dir
39
57
when /--config-dir=(.*)?/
40
58
# Spaces in the directory should be fine since this whole thing is passed
41
59
# as a single argument via the multi-arg syntax for system() below.
48
66
@args [ @wait_index ] = nil if @wait_index
49
67
@args [ @configdir_index ] = nil if @configdir_index
50
68
@args = @args . compact
51
- @args . push ( "--config-dir=#{ @configdir } " )
52
- @args . push ( "--non-interactive" )
53
69
54
- res = system ( "svn" , "cleanup" )
55
- if res . nil?
56
- $stderr. puts "[-] ERROR: Failed to run svn"
57
- $stderr. puts ""
58
- $stderr. puts "[-] If you used a binary installer, make sure you run the symlink in"
59
- $stderr. puts "[-] /usr/local/bin instead of running this file directly (e.g.: ./msfupdate)"
60
- $stderr. puts "[-] to ensure a proper environment."
61
- else
62
- # Cleanup worked, go ahead and update
63
- system ( "svn" , "update" , *@args )
70
+ ####### Since we're SVN, do it all this way #######
71
+ if is_svn
72
+ print_depreciation_warning
73
+ @args . push ( "--config-dir=#{ @configdir } " )
74
+ @args . push ( "--non-interactive" )
75
+
76
+ res = system ( "svn" , "cleanup" )
77
+ if res . nil?
78
+ $stderr. puts "[-] ERROR: Failed to run svn"
79
+ $stderr. puts ""
80
+ $stderr. puts "[-] If you used a binary installer, make sure you run the symlink in"
81
+ $stderr. puts "[-] /usr/local/bin instead of running this file directly (e.g.: ./msfupdate)"
82
+ $stderr. puts "[-] to ensure a proper environment."
83
+ exit 1
84
+ else
85
+ # Cleanup worked, go ahead and update
86
+ system ( "svn" , "update" , *@args )
87
+ end
88
+ end
89
+
90
+ ####### Since we're Git, do it all that way #######
91
+ if is_git
92
+ # Always lose any local changes, but not unchecked files
93
+ # TODO: Allow for git stash and git stash pop
94
+ res = system ( "git" , "reset" , "HEAD" , "--hard" )
95
+ if res . nil?
96
+ $stderr. puts "[-] ERROR: Failed to run git"
97
+ $stderr. puts ""
98
+ $stderr. puts "[-] If you used a binary installer, make sure you run the symlink in"
99
+ $stderr. puts "[-] /usr/local/bin instead of running this file directly (e.g.: ./msfupdate)"
100
+ $stderr. puts "[-] to ensure a proper environment."
101
+ exit 1
102
+ end
103
+
104
+ # TODO: Allow msfupdate to take a branch argument
105
+ system ( "git" , "checkout" , "master" )
106
+ system ( "git" , "fetch" )
107
+ system ( "git" , "merge" , "origin/master" )
108
+ end
109
+
110
+ unless is_svn || is_git
111
+ raise RuntimeError , "Cannot determine checkout type: `#{ msfbase_dir } '"
64
112
end
65
113
66
114
if @actually_wait
0 commit comments