diff --git a/pom.xml b/pom.xml index 536f45e..790d903 100644 --- a/pom.xml +++ b/pom.xml @@ -182,7 +182,7 @@ Bit Goblin /opt ${project.basedir}/src/build/changelog.txt - linux + ${os.name} /opt/dragoon diff --git a/src/main/java/tech/bitgoblin/config/Cmd.java b/src/main/java/tech/bitgoblin/config/Cmd.java index e991164..884182e 100644 --- a/src/main/java/tech/bitgoblin/config/Cmd.java +++ b/src/main/java/tech/bitgoblin/config/Cmd.java @@ -1,7 +1,16 @@ package tech.bitgoblin.config; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + import org.apache.commons.cli.*; +import tech.bitgoblin.Logger; +import tech.bitgoblin.io.IOUtils; + public class Cmd { private String helpHeader = "Start the Dragoon video transcoder."; @@ -16,6 +25,10 @@ public class Cmd { Option helpOption = new Option("h", "help", false, "Display CLI usage and options."); options.addOption(helpOption); + // install a config file in the user's home directory + Option installOption = new Option("i", "install", false, "Install configuration file in the user's home directory (or specify a location with -c)."); + options.addOption(installOption); + // allow the user to specify a config file manually Option configPath = new Option("c", "configPath", true, "Configuration file path (defaults to " + this.configPath + ")"); configPath.setRequired(false); @@ -28,6 +41,17 @@ public class Cmd { if (cmd.hasOption("help")) { this.printHelp(options); } + + // check if the install option was called + if (cmd.hasOption("install")) { + try { + this.installConfig(); + } catch (IOException e) { + e.printStackTrace(); + Logger.logger.error("Unable to install new configuration file; please refer to the stack trace above to resolve the error."); + System.exit(2); + } + } // set the configPath variable if the option was passed to the program if (cmd.hasOption("configPath")) { @@ -41,6 +65,15 @@ public class Cmd { System.exit(0); } + + public void installConfig() throws IOException { + ClassLoader classloader = Thread.currentThread().getContextClassLoader(); + InputStream is = classloader.getResourceAsStream("example.config"); + Files.copy(is, Paths.get(IOUtils.resolveTilda(this.configPath)), StandardCopyOption.REPLACE_EXISTING); + Logger.logger.info("A new configuration file has been installed at " + this.configPath + "."); + + System.exit(0); + } public String getConfigPath() { return this.configPath; diff --git a/src/main/resources/example.config b/src/main/resources/example.config new file mode 100644 index 0000000..35e82e1 --- /dev/null +++ b/src/main/resources/example.config @@ -0,0 +1,10 @@ +[transcoder] +repo_path = '~/dragoon' +interval = 15 +video_format = 'mov' +video_codec = 'dnxhd' +video_profile = 'dnxhr_hq' +video_resolution = '1920x1080' +video_framerate = '60' +video_color = 'yuv422p' +audio_codec = 'pcm_s16le'