borgbutler-core/src/main/java/de/micromata/borgbutler/config/Configuration.java
@@ -21,36 +21,16 @@ */ private static final String RESTORE_DIRNAME = "restore"; @Getter private String binariesDownloadVersion = "1.1.8"; @Getter private String binariesDownloadUrl = "https://github.com/borgbackup/borg/releases/download/" + binariesDownloadVersion + "/"; @Getter private String[][] borgBinaries = { {"freebsd64", "FreeBSD 64"}, {"linux32", "Linux 32"}, {"linux64", "Linux 64"}, {"macosx64", "MacOS X 64"}}; @Getter private String minimumRequiredBorgVersion = "1.1.8"; @JsonIgnore @Setter(AccessLevel.PACKAGE) private File workingDir; /** * One of the values "macosx64", "linux64" etc. for using a binary provided by BorgButler or null / "manual" for * using a manual installed borg version. */ @Getter private String borgBinary; /** * The path of the borg command to use. */ @Getter @Setter private String borgCommand = "borg"; private String borgCommand; /** * Default is 100 MB (approximately). */ borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgInstallation.java
@@ -41,35 +41,31 @@ if (version(configuration)) { return; } log.warn("No working borg version found. Please configure a borg version with minimal version '" + configuration.getMinimumRequiredBorgVersion() + "'."); log.warn("No working borg version found. Please configure a borg version with minimal version '" + borgVersion.getMinimumRequiredBorgVersion() + "'."); } /** * * @return a clone of this.borgVersion. */ public BorgVersion getVersion() { return new BorgVersion() .setVersion(borgVersion.getVersion()) .setVersionOK(borgVersion.isVersionOK()); return new BorgVersion().copyFrom(borgVersion); } private boolean version(Configuration configuration) { String versionString = BorgCommands.version(); boolean versionOK = false; if (versionString != null) { if (versionString.compareTo(configuration.getMinimumRequiredBorgVersion()) < 0) { log.info("Found borg version '" + versionString + "' is less than minimum required version '" + configuration.getMinimumRequiredBorgVersion() + "'."); borgVersion.setVersionOK(false); int cmp = versionString.compareTo(borgVersion.getMinimumRequiredBorgVersion()); if (cmp < 0) { log.info("Found borg version '" + versionString + "' is less than minimum required version '" + borgVersion.getMinimumRequiredBorgVersion() + "'."); } else { log.info("Found borg '" + configuration.getBorgCommand() + "', version: " + versionString + " (newer than '" + configuration.getMinimumRequiredBorgVersion() versionOK = true; log.info("Found borg '" + configuration.getBorgCommand() + "', version: " + versionString + " (equals to or newer than '" + borgVersion.getMinimumRequiredBorgVersion() + "', OK)."); borgVersion.setVersionOK(true); } } else { borgVersion.setVersionOK(false); return false; } return true; borgVersion.setVersionOK(versionOK); return versionOK; } private String[] getBinary(RunningMode.OSType osType) { @@ -88,7 +84,7 @@ if (os == null) { return null; } for (String[] binary : ConfigurationHandler.getConfiguration().getBorgBinaries()) { for (String[] binary : borgVersion.getBorgBinaries()) { if (binary[0].contains(os)) { return binary; } @@ -111,7 +107,7 @@ // File already downloaded, nothing to do. return file; } String url = ConfigurationHandler.getConfiguration().getBinariesDownloadUrl() + getDownloadFilename(binary); String url = borgVersion.getBinariesDownloadUrl() + getDownloadFilename(binary); log.info("Trying to download borg binary '" + binary[0] + "' (" + binary[1] + ") from url: " + url + "..."); HttpClientBuilder builder = HttpClients.custom() .setDefaultRequestConfig(RequestConfig.custom() @@ -141,7 +137,7 @@ log.info("Creating binary directory: " + dir.getAbsolutePath()); dir.mkdirs(); } return new File(dir, getDownloadFilename(binary) + "-" + ConfigurationHandler.getConfiguration().getBinariesDownloadVersion()); return new File(dir, getDownloadFilename(binary) + "-" + borgVersion.getBinariesDownloadVersion()); } private String getDownloadFilename(String[] binary) { borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgVersion.java
@@ -6,9 +6,44 @@ public class BorgVersion { @Getter private String binariesDownloadVersion = "1.1.8"; @Getter private String binariesDownloadUrl = "https://github.com/borgbackup/borg/releases/download/" + binariesDownloadVersion + "/"; @Getter private String[][] borgBinaries = { {"freebsd64", "FreeBSD 64"}, {"linux32", "Linux 32"}, {"linux64", "Linux 64"}, {"macosx64", "MacOS X 64"}}; @Getter private String minimumRequiredBorgVersion = "1.1.8"; /** * One of the values "macosx64", "linux64" etc. for using a binary provided by BorgButler or null / "manual" for * using a manual installed borg version. */ @Getter private String borgBinary; /** * The path of the borg command to use. */ @Getter @Setter private String borgCommand; @Getter @Setter(AccessLevel.PACKAGE) private boolean versionOK = false; @Getter @Setter(AccessLevel.PACKAGE) private String version; public BorgVersion copyFrom(BorgVersion other) { this.borgCommand = other.borgCommand; this.borgBinary = other.borgBinary; this.versionOK = other.versionOK; this.version = other.version; return this; } } borgbutler-server/src/main/java/de/micromata/borgbutler/server/ServerConfiguration.java
@@ -4,6 +4,7 @@ import de.micromata.borgbutler.cache.ButlerCache; import de.micromata.borgbutler.config.Configuration; import de.micromata.borgbutler.config.ConfigurationHandler; import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,6 +19,8 @@ private int port = WEBSERVER_PORT_DEFAULT; private boolean webDevelopmentMode = WEB_DEVELOPMENT_MODE_PREF_DEFAULT; @Getter private BorgVersion borgVersion = new BorgVersion(); @JsonProperty public String getCacheDir() { return ButlerCache.getInstance().getCacheDir().getAbsolutePath(); @@ -65,5 +68,6 @@ super.copyFrom(other); this.port = other.port; this.webDevelopmentMode = other.webDevelopmentMode; this.borgVersion.copyFrom(other.borgVersion); } } borgbutler-server/src/test/java/de/micromata/borgbutler/server/BorgInstallationTest.java
@@ -14,7 +14,7 @@ @Test void foo() throws Exception { ConfigurationHandler.getConfiguration().setBorgCommand("hurzel"); ConfigurationHandler.getConfiguration().setBorgCommand(null); BorgInstallation borgInstallation = BorgInstallation.getInstance(); borgInstallation.initialize(); ConfigurationHandler.getConfiguration().setBorgCommand("borg"); @@ -23,7 +23,7 @@ @Test void downloadTest() { String version = ConfigurationHandler.getConfiguration().getBinariesDownloadVersion(); String version = new BorgVersion().getBinariesDownloadVersion(); checkDownload(RunningMode.OSType.LINUX, "borg-linux64-" + version); checkDownload(RunningMode.OSType.MAC_OS, "borg-macosx64-" + version); checkDownload(RunningMode.OSType.FREEBSD, "borg-freebsd64-" + version); borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
@@ -58,7 +58,7 @@ showDemoRepos: true, maxArchiveContentCacheCapacityMb: 100, redirect: false, binary: 'manual' borgVersion: null }; this.handleTextChange = this.handleTextChange.bind(this); @@ -113,7 +113,7 @@ if (this.state.failed) { return <ErrorAlertGenericRestFailure handleClick={this.loadConfig}/>; } const borgVersion = this.state.borgVersion; return ( <div> <form> @@ -121,12 +121,12 @@ <FormLabel>{'Borg command'}</FormLabel> <FormField length={2}> <FormSelect value={this.state.binary} value={borgVersion.binary} name={'binary'} onChange={this.handleTextChange} hint={`Choose your OS and BorgButler will download and use a ready to run borg binary from ${this.state.binariesDownloadUrl} or choose a manual installed version.`} hint={`Choose your OS and BorgButler will download and use a ready to run borg binary from ${borgVersion.binariesDownloadUrl} or choose a manual installed version.`} > {this.state.borgBinaries {borgVersion.borgBinaries .map((binary, index) => <FormOption label={binary[1]} value={binary[0]} key={index}/>)} <FormOption label={'Manual'} value={'manual'}/>