diff --git a/cmd/root.go b/cmd/root.go index aad4ec5..f2f2e7b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,8 +24,10 @@ Konwn-Issue: 1. Only support upload ftp now. Konwn-Behavior: - 1. Upload project to device, ELF executable or shared object file will be chmod to 0755. - 2. Generate upload yaml file from real evo project. + 1. Upload project to device. + 2. On Remote device, ELF executable or shared object file will be chmod to 0755. + 3. On Remote device, konwn executable script will be chmod to 0755. + 4. Generate upload yaml file from real evo project. Upload-Example: sylixos-uploader upload --path ~/sylixos-workspace/base-project --device 10.13.16.250 --method ftp diff --git a/common/defs.go b/common/defs.go index 7558e90..68685c4 100644 --- a/common/defs.go +++ b/common/defs.go @@ -14,3 +14,21 @@ const ( var ( Version = "v0.0.0" ) + +var KnownExecutables = map[string]bool{ + ".elf": true, + ".so": true, + ".exe": true, + ".bat": true, + ".cmd": true, + ".sh": true, + ".bash": true, + ".lua": true, + ".py": true, + ".rb": true, + ".pl": true, + ".elv": true, + ".js": true, + ".jsc": true, + ".php": true, +} diff --git a/pusher/ftp_pusher.go b/pusher/ftp_pusher.go index ac5d4e1..a45f85c 100644 --- a/pusher/ftp_pusher.go +++ b/pusher/ftp_pusher.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "sylixos-uploader/common" "sylixos-uploader/log" "sync" @@ -19,6 +20,8 @@ type FtpSylixOSPusher struct { m sync.Mutex } +// NewFtpPusher creates a new instance of FtpSylixOSPusher for the specified device. +// It initializes the connection status as not logged in. func NewFtpPusher(device string) *FtpSylixOSPusher { return &FtpSylixOSPusher{ device: device, @@ -109,6 +112,14 @@ func (f *FtpSylixOSPusher) Push(src, dst string, return f.pushFile(src, dst, logFn, logClear) } +// pushDir uploads a directory to the remote FTP server. +// It recursively walks through the local directory and for each file and +// directory it creates the remote directory if it doesn't exist and then +// calls pushFile to upload the file. +// If a log function is provided, it is called with log level LogLevelError on +// error and with log level LogLevelInfo for successful operations. +// If a log clear function is provided, it is called with log level LogLevelInfo +// after each successful operation to clear the previous log line. func (f *FtpSylixOSPusher) pushDir(src, dst string, logFn func(level log.LogLevel, format string, @@ -191,8 +202,8 @@ func (f *FtpSylixOSPusher) pushFile(src, dst string, return err } - // Set executable permissions if the file is ELF - if isELFExecutable(src) { + // Set executable permissions if the file is ELF or known executable + if isELFExecutable(src) || isKnownExecutable(src) { if err := f.conn.Chmod(dst, 0755); err != nil { return err } @@ -245,3 +256,13 @@ func isELFExecutable(path string) bool { return false } } + +// isKnownExecutable checks if a file is a known executable +func isKnownExecutable(path string) bool { + for ext := range common.KnownExecutables { + if strings.HasSuffix(path, ext) { + return true + } + } + return false +}