This commit is contained in:
cnbattle
2020-05-07 09:29:56 +08:00
parent 5f95c675ce
commit 7c2d02cc6f
3 changed files with 60 additions and 14 deletions
+7 -3
View File
@@ -7,15 +7,19 @@ import (
)
// Cmd exec.Command
func Cmd(name string, arg ...string) {
func Cmd(name string, arg ...string) error {
command := exec.Command(name, arg...)
var buffer bytes.Buffer
command.Stdout = &buffer
if err := command.Start(); err != nil {
panic(fmt.Sprintf("Error: The first command can not be startup %s\n", err))
return err
}
if err := command.Wait(); err != nil {
panic(fmt.Sprintf("Error: Couldn't wait for the second command: %s\n", err))
return err
}
fmt.Printf("%s", buffer.Bytes())
fmt.Println("===================================================")
fmt.Println(" Successfully ")
fmt.Println("===================================================")
return nil
}
+51 -11
View File
@@ -1,26 +1,66 @@
package main
import (
"fmt"
"errors"
"github.com/cnbattle/drone-upx/cmd"
"log"
"os"
"github.com/urfave/cli/v2"
)
var (
level string
saveFile string
originalFile string
// Version Version
Version string
)
func init() {
level = os.Getenv("PLUGIN_LEVEL")
saveFile = os.Getenv("PLUGIN_SAVE_FILE")
originalFile = os.Getenv("PLUGIN_ORIGINAL_FILE")
fmt.Println("Version:", Version)
func main() {
app := &cli.App{
Name: "drone-upx",
Usage: "UPX - the Ultimate Packer for eXecutables.",
Copyright: "Copyright (c) 2020 Qi-ai Li",
Version: Version,
Authors: []*cli.Author{
{
Name: "Qi-ai Li",
Email: "qiaicn@gmail.com",
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "level, l",
Value: "5",
Usage: "upx level",
EnvVars: []string{"PLUGIN_LEVEL"},
},
&cli.StringFlag{
Name: "originalFile, of",
Usage: "original file",
EnvVars: []string{"PLUGIN_ORIGINAL_FILE"},
},
&cli.StringFlag{
Name: "saveFile, sf",
Usage: "save file name",
EnvVars: []string{"PLUGIN_SAVE_FILE"},
},
},
Action: run,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func main() {
cmd.Cmd("/bin/upx", "-"+level, "-o", saveFile, originalFile)
func run(ctx *cli.Context) error {
var level, originalFile, saveFile = ctx.String("level"), ctx.String("originalFile"), ctx.String("saveFile")
if len(originalFile) == 0 {
return errors.New("miss originalFile")
}
if len(saveFile) == 0 {
return errors.New("miss saveFile")
}
return cmd.Cmd("/bin/upx", "-"+level, "-o", saveFile, originalFile)
}
+2
View File
@@ -1,3 +1,5 @@
module github.com/cnbattle/drone-upx
go 1.13
require github.com/urfave/cli/v2 v2.2.0