diff --git a/README.md b/README.md index 6a73567..04cf561 100755 --- a/README.md +++ b/README.md @@ -31,14 +31,24 @@ Shuttle is a utility that facilitates seamless file transfer from a source devic ## **Usage** -> **Note:** If you used the [ShuttleBuilder](https://github.com/ComPlat/shuttlebuilder), CLI arguments are preconfigured and do not need to be manually added. +### ShuttleBuilder +If you used the [ShuttleBuilder](https://github.com/ComPlat/shuttlebuilder), CLI arguments are preconfigured and do not need to be manually added. +### Execute by adding command line arguments To run the utility, execute the following command: ```shell +go build shuttle -src < source_directory_path > -duration < time_in_seconds > -dst < destination_server > -user < username > -pass < password > -type < file|folder|zip|tar|flat_tar > -transfer < webdav|sftp > -commonRegex < Regexp > ``` +### Create a executable that contains default parameters +1. Edit the default parameters in "default_parameter.go" +1. Execute build which will create an executable for the desired operating system +```shell +python build.py +``` + ### Parameters: - < source_directory_path >: Path to the source directory containing files to transfer. @@ -102,5 +112,5 @@ This project is licensed under the MIT License. - + diff --git a/build.py b/build.py new file mode 100755 index 0000000..3ce9f29 --- /dev/null +++ b/build.py @@ -0,0 +1,22 @@ +#!/usr/local/bin/python +# This cannot be in go, since you cannot execute a go command from within go +import os + +# get data from go-file +with open('default_parameter.go', encoding='utf-8') as fIn: + text = fIn.read() + text = text.split('return Parameter{')[1] + lines = text.split('}')[0].split('\n') + lines = [i.strip() for i in lines if i.strip()] + data = {i.split(":")[0]:i.split(":")[1].replace('"','').replace(',','').strip() for i in lines} + +osDict = { + #label os arch extension + "linux":["linux", "amd64", "out"] , + "winxp":["windows", "386", "exe"], + "win10":["windows", "amd64", "exe"] +} +osList = osDict[data['os'].lower()] + +os.system(f"env GOOS={osList[0]} GOARCH={osList[1]} go build -o shuttle.{osList[2]}") + diff --git a/cmd_manager.go b/cmd_manager.go index 8172ddc..18ccf8a 100755 --- a/cmd_manager.go +++ b/cmd_manager.go @@ -30,25 +30,27 @@ func (m Args) LogString() string { // GetCmdArgs Get/Parse command line arguments manager func GetCmdArgs() Args { - var fp, dst, user, pass, crt, durationStr, tType, name string + var fp, dst, user, pass, durationStr, tType, sendType, name string + var crt string var duration int var commonRegexStr string var commonRegex *regexp.Regexp - var sendType string var err error - flag.StringVar(&fp, "src", "{{ src }}", "Source directory to be watched.") - flag.StringVar(&name, "name", "{{ name }}", "Name of the EFW instance.") - flag.StringVar(&dst, "dst", "{{ dst }}", "WebDAV destination URL. If the destination is on the lsdf, the URL should be as follows:\nhttps://os-webdav.lsdf.kit.edu///projects//\n -Organisationseinheit, z.B. kit.\n -Institut-Name, z.B. ioc, scc, ikp, imk-asf etc.\n -User-Name z.B. xy1234, bs_abcd etc.\n -Projekt-Name") - flag.StringVar(&user, "user", "{{ user }}", "WebDAV or SFTP user") - flag.StringVar(&pass, "pass", "{{ password }}", "WebDAV or SFTP Password") - flag.StringVar(&durationStr, "duration", "{{ duration }}", "Duration in seconds, i.e., how long a file must not be changed before sent.") - flag.StringVar(&crt, "crt", "{{ crt }}", "Path to server TLS certificate. Only needed if the server has a self signed certificate.") + var defaultParameter = DefaultParameter() + + flag.StringVar(&fp, "src", defaultParameter.src, "Source directory to be watched.") + flag.StringVar(&name, "name", defaultParameter.name, "Name of the EFW instance.") + flag.StringVar(&dst, "dst", defaultParameter.dst, "WebDAV destination URL. If the destination is on the lsdf, the URL should be as follows:\nhttps://os-webdav.lsdf.kit.edu///projects//\n -Organisationseinheit, z.B. kit.\n -Institut-Name, z.B. ioc, scc, ikp, imk-asf etc.\n -User-Name z.B. xy1234, bs_abcd etc.\n -Projekt-Name") + flag.StringVar(&user, "user", defaultParameter.user, "WebDAV or SFTP user") + flag.StringVar(&pass, "pass", defaultParameter.pass, "WebDAV or SFTP Password") + flag.StringVar(&durationStr, "duration", defaultParameter.duration, "Duration in seconds, i.e., how long a file must not be changed before sent.") + flag.StringVar(&crt, "crt", "{{ crt }}", "Path to server TLS certificate. Only needed if the server has a self signed certificate.") /// Only considered if result are stored in a folder. /// If zipped is set the result folder will be transferred as zip file - flag.StringVar(&sendType, "type", "{{ type }}", "Type must be 'file', 'folder', 'tar', 'zip' or 'flat_tar'. The 'file' option means that each file is handled individually, the 'folder' option means that entire folders are transmitted only when all files in them are ready. The option 'tar' and/or 'zip' send a folder zipped, only when all files in a folder are ready. The flat_tar option packs all files with have a common prefix into a tar file in a flat folder hierarchy") - flag.StringVar(&commonRegexStr, "commonRegex", "{{ common_regex }}", "The common prefix length is only required if the type is flat_tar. This value specifies the number of leading characters that must be the same in order for files to be packed together.") - flag.StringVar(&tType, "transfer", "{{ tType }}", "Type must be 'webdav' or 'sftp'.") + flag.StringVar(&sendType, "type", defaultParameter.tType, "Type must be 'file', 'folder', 'tar', 'zip' or 'flat_tar'. The 'file' option means that each file is handled individually, the 'folder' option means that entire folders are transmitted only when all files in them are ready. The option 'tar' and/or 'zip' send a folder zipped, only when all files in a folder are ready. The flat_tar option packs all files with have a common prefix into a tar file in a flat folder hierarchy") + flag.StringVar(&commonRegexStr,"commonRegex", "{{ common_regex }}", "The common prefix length is only required if the type is flat_tar. This value specifies the number of leading characters that must be the same in order for files to be packed together.") + flag.StringVar(&tType, "transfer", defaultParameter.sendType, "Type must be 'webdav' or 'sftp'.") flag.Parse() if duration, err = strconv.Atoi(durationStr); err != nil { diff --git a/default_parameter.go b/default_parameter.go new file mode 100644 index 0000000..b2f2237 --- /dev/null +++ b/default_parameter.go @@ -0,0 +1,18 @@ +package main + +type Parameter struct { + src, user, pass, dst, sendType, tType, name, duration, os string +} + +func DefaultParameter() Parameter { + return Parameter{ + src: "", + name: "Instrument 1", + os: "winXP", + dst: "", + user: "", + pass: "", + duration: "5", + sendType: "sftp", + tType: "file"} +} \ No newline at end of file diff --git a/go.mod b/go.mod index 7bf362d..319ee77 100755 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module Shuttle -go 1.23 +go 1.23.0 require ( github.com/StarmanMartin/gowebdav v0.0.0-20220901075112-8721ee532c0c