diff --git a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java index 2b32b0e5ca..87e7388cd9 100644 --- a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java +++ b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java @@ -26,12 +26,18 @@ public class Autoupdate { private static final String COM_RUSEFI_LAUNCHER = "com.rusefi.Launcher"; public static void main(String[] args) { + String bundleFullName = readBundleFullName(); + + if (args.length > 0 && args[0].equalsIgnoreCase("release")) { + handleBundle(bundleFullName, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE); + return; + } + UpdateMode mode = getMode(); if (mode != UpdateMode.NEVER) { - String bundleFullName = readBundleFullName(); if (bundleFullName != null) { System.out.println("Handling " + bundleFullName); - handleBundle(bundleFullName, mode); + handleBundle(bundleFullName, mode, ConnectionAndMeta.BASE_URL_LATEST); } } else { System.out.println("Update mode: NEVER"); @@ -63,10 +69,10 @@ public class Autoupdate { } } - private static void handleBundle(String bundleFullName, UpdateMode mode) { + private static void handleBundle(String bundleFullName, UpdateMode mode, String baseUrl) { try { String zipFileName = bundleFullName + "_autoupdate" + ".zip"; - ConnectionAndMeta connectionAndMeta = new ConnectionAndMeta(zipFileName).invoke(); + ConnectionAndMeta connectionAndMeta = new ConnectionAndMeta(zipFileName).invoke(baseUrl); System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified())); if (AutoupdateUtil.hasExistingFile(zipFileName, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) { diff --git a/java_console/bin/broadcast.sh b/java_console/bin/broadcast.sh index 6a5d670992..821e851de7 100755 --- a/java_console/bin/broadcast.sh +++ b/java_console/bin/broadcast.sh @@ -10,9 +10,14 @@ do echo Exit code: ${exit_status} # in java code that's UPDATE_SBC_EXIT_CODE magic number if [ $exit_status -eq 15 ]; then - echo Connector software update was requested + echo Connector software update to latest was requested bin/update_bundle.sh fi + # in java code that's UPDATE_RELEASE_SBC_EXIT_CODE magic number + if [ $exit_status -eq 17 ]; then + echo Connector software update to latest was requested + bin/update_bundle_latest.sh + fi # in java code that's UPDATE_FIRMWARE_EXIT_CODE magic number if [ $exit_status -eq 16 ]; then echo Firmware update was requested @@ -20,4 +25,11 @@ do # todo: we need to start validating that SBC software matches board type, maybe update bundle type based on existing controller? bin/dfu_switch_and_program.sh fi + # in java code that's UPDATE_RELEASE_FIRMWARE_EXIT_CODE magic number + if [ $exit_status -eq 18 ]; then + echo Firmware update was requested + bin/update_bundle_latest.sh + # todo: we need to start validating that SBC software matches board type, maybe update bundle type based on existing controller? + bin/dfu_switch_and_program.sh + fi done \ No newline at end of file diff --git a/java_console/bin/update_bundle_release.sh b/java_console/bin/update_bundle_release.sh old mode 100644 new mode 100755 diff --git a/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java b/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java index 15ca54d05b..141e311459 100644 --- a/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java +++ b/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java @@ -10,8 +10,9 @@ import static com.devexperts.logging.Logging.getLogging; public class NetworkConnectorContext { private static final Logging log = getLogging(NetworkConnectorContext.class); private static final int UPDATE_LATEST_SBC_EXIT_CODE = 15; - public static final int UPDATE_FIRMWARE_EXIT_CODE = 16; + public static final int UPDATE_LATEST_FIRMWARE_EXIT_CODE = 16; private static final int UPDATE_RELEASE_SBC_EXIT_CODE = 17; + public static final int UPDATE_RELEASE_FIRMWARE_EXIT_CODE = 18; public int reconnectDelay() { return 15; // this one is seconds @@ -46,6 +47,6 @@ public class NetworkConnectorContext { public void onFirmwareUpdateRequest() { log.info("onFirmwareUpdateRequest"); - System.exit(UPDATE_FIRMWARE_EXIT_CODE); + System.exit(UPDATE_LATEST_FIRMWARE_EXIT_CODE); } } diff --git a/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java b/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java index 5a6fe6455a..d3dbad0782 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java +++ b/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java @@ -11,6 +11,9 @@ import java.security.cert.X509Certificate; import java.util.Objects; public class ConnectionAndMeta { + public static final String BASE_URL_RELEASE = "https://github.com/rusefi/rusefi/releases/latest/download/"; + public static final String BASE_URL_LATEST = "https://rusefi.com/build_server/autoupdate/"; + private static final int BUFFER_SIZE = 32 * 1024; public static final int STEPS = 1000; private String zipFileName; @@ -68,12 +71,12 @@ public class ConnectionAndMeta { return lastModified; } - public ConnectionAndMeta invoke() throws IOException, NoSuchAlgorithmException, KeyManagementException { + public ConnectionAndMeta invoke(String baseUrl) throws IOException, NoSuchAlgorithmException, KeyManagementException { // user can have java with expired certificates or funny proxy, we shall accept any certificate :( SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[]{new AcceptAnyCertificateTrustManager()}, new SecureRandom()); - URL url = new URL("https://rusefi.com/build_server/autoupdate/" + zipFileName); + URL url = new URL(baseUrl + zipFileName); httpConnection = (HttpsURLConnection) url.openConnection(); httpConnection.setSSLSocketFactory(ctx.getSocketFactory()); completeFileSize = httpConnection.getContentLength();