11package edu .wpi .first .gradlerio .deploy .roborio ;
22
3+ import java .io .ByteArrayInputStream ;
34import java .io .IOException ;
45import java .io .InputStream ;
6+ import java .security .DigestInputStream ;
7+ import java .security .MessageDigest ;
8+ import java .security .NoSuchAlgorithmException ;
59
610import javax .inject .Inject ;
711
12+ import org .codehaus .groovy .runtime .EncodingGroovyMethods ;
13+
814import edu .wpi .first .deployutils .deploy .artifact .AbstractArtifact ;
915import edu .wpi .first .deployutils .deploy .context .DeployContext ;
1016import edu .wpi .first .gradlerio .deploy .DeployStage ;
@@ -18,20 +24,38 @@ public FRCProgramKillArtifact(String name, StagedDeployTarget target) {
1824 super (name , target );
1925
2026 target .setDeployStage (this , DeployStage .ProgramKill );
21-
22-
2327 }
2428
2529 @ Override
2630 public void deploy (DeployContext ctx ) {
27- ctx .getLogger ().log (" Deploying new frcKillRobot script" );
28- try (InputStream it = ToolInstallTask .class .getResourceAsStream ("/frcKillRobot.sh" )) {
29- ctx .put (it , "/usr/local/frc/bin/frcKillRobot.sh.tmp" );
31+
32+
33+ MessageDigest md ;
34+ try {
35+ md = MessageDigest .getInstance ("MD5" );
36+ } catch (NoSuchAlgorithmException e1 ) {
37+ throw new RuntimeException (e1 );
38+ }
39+
40+ try (DigestInputStream it = new DigestInputStream (ToolInstallTask .class .getResourceAsStream ("/frcKillRobot.sh" ), md );
41+ ByteArrayOutputStreamAccessor dump = new ByteArrayOutputStreamAccessor ()) {
42+ it .transferTo (dump );
43+ String local = EncodingGroovyMethods .encodeHex (md .digest ()).toString ();
44+
45+ String result = ctx .execute ("md5sum /usr/local/frc/bin/frcKillRobot.sh" ).getResult ();
46+ if (result != null && result .toLowerCase ().startsWith (local .toLowerCase ())) {
47+ ctx .getLogger ().log ("Skipping redeploy of frcKillRobot script" );
48+ } else {
49+ ctx .getLogger ().log ("Redeploying frcKillRobot script" );
50+ try (InputStream out = new ByteArrayInputStream (dump .getBackingArray (), 0 , dump .getBackingLength ())) {
51+ ctx .put (out , "/usr/local/frc/bin/frcKillRobot.sh.tmp" );
52+ }
53+ ctx .execute ("mv /usr/local/frc/bin/frcKillRobot.sh.tmp /usr/local/frc/bin/frcKillRobot.sh && chmod +x /usr/local/frc/bin/frcKillRobot.sh" );
54+ ctx .execute ("sync" );
55+ }
3056 } catch (IOException e ) {
3157 throw new RuntimeException (e );
3258 }
33- ctx .execute ("mv /usr/local/frc/bin/frcKillRobot.sh.tmp /usr/local/frc/bin/frcKillRobot.sh && chmod +x /usr/local/frc/bin/frcKillRobot.sh" );
34- ctx .execute ("sync" );
3559 ctx .execute (". /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t 2> /dev/null" );
3660 }
3761}
0 commit comments