@@ -15,37 +15,45 @@ def run_update():
1515 pass
1616
1717
18- # 1. Determine Root with Precision
18+ # Determine Root with Precision
1919 base_dir = os .path .dirname (os .path .realpath (__file__ ))
2020 project_root = os .path .abspath (os .path .join (base_dir , ".." , ".." ))
2121 os .chdir (project_root )
2222
2323 print (f"{ C .SUCCESS } [*] Attempting to update Storm Framework.{ C .RESET } " )
2424
25- # 2. Check Connection & Fetch
26- # Use rebase to be cleaner and not create messy merge commits.
27- print (f"[*] Checking for new versions at github.com/storm-os/Cyber-Pentest" )
28-
29- # We use subprocess to catch errors more elegantly.
25+ # 1. Get the latest info without changing the locale first
3026 subprocess .run (["git" , "fetch" , "--all" ], stdout = subprocess .DEVNULL )
27+
28+ # 2. CHECK CHANGES: Compare local (HEAD) with server (origin/main)
29+ # Check if there are any different .go or .c files
30+ check_diff = subprocess .run (
31+ ["git" , "diff" , "--name-only" , "HEAD" , "origin/main" ],
32+ capture_output = True , text = True
33+ )
34+
35+ # Filter: are there any files ending in .go or .c?
36+ changed_files = check_diff .stdout .splitlines ()
37+ needs_recompile = any (f .endswith (('.go' , '.c' )) for f in changed_files )
38+
39+ # 3. Reset Execution (Update file to the latest version)
3140 process = subprocess .run (["git" , "reset" , "--hard" , "origin/main" ],
32- stderr = subprocess .PIPE ,
33- text = True )
41+ stderr = subprocess .PIPE , text = True )
3442
3543 if process .returncode == 0 :
36- print (f"{ C .SUCCESS } \n [+] Git synchronization complete.{ C .RESET } " )
37-
38- # 3. Trigger Compiler (The Hook)
39- compiler_path = os .path .join (project_root , "compiler" )
40- if os .path .exists (compiler_path ):
41- print (f"{ C .SUCCESS } \n [*] Triggering framework recompilation.{ C .RESET } " )
42- os .system (f'bash -c "source { compiler_path } && compile_modules"' )
43- print (f"{ C .SUCCESS } \n [✓] Framework updated to v{ latest_version } { C .RESET } " )
44+ print (f"{ C .SUCCESS } \n [+] System updated to latest version.{ C .RESET } " )
45+
46+ # 4. Trigger Compiler ONLY IF needed
47+ if needs_recompile :
48+ compiler_path = os .path .join (project_root , "compiler" )
49+ if os .path .exists (compiler_path ):
50+ print (f"{ C .SUCCESS } \n [*] Source code changes detected. Recompiling...{ C .RESET } " )
51+ os .system (f'bash -c "source { compiler_path } && compile_modules"' )
52+ print (f"{ C .SUCCESS } \n [✓] Framework recompiled successfully.{ C .RESET } " )
4453 else :
45- print (f"{ C .ERROR } \n [x] ERROR: Compiler hook not found at { compiler_path } { C .RESET } " )
46- else :
47- print (f"{ C .ERROR } \n [x] Update failed!{ C .RESET } " )
48- print (f"{ C .SUCCESS } [!] Logic: { process .stderr } { C .RESET } " )
49- print (f"[*] Suggestion: Run 'git stash' if you have local changes." )
54+ print (f"{ C .SUCCESS } [*] No source code changes. Skipping compilation. 😴{ C .RESET } " )
55+
56+ print (f"{ C .SUCCESS } \n [✓] Storm is now v{ latest_version } { C .RESET } " )
57+
5058
5159 sys .exit ()
0 commit comments