36 lines
844 B
Go
36 lines
844 B
Go
package maker
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os/exec"
|
|
)
|
|
|
|
func (m *maker) DependencyCheck(ctx context.Context) error {
|
|
// 1. test wget command
|
|
if err := checkCommand(ctx, "wget", "--version"); err != nil {
|
|
return fmt.Errorf("wget 命令未找到: %w", err)
|
|
}
|
|
|
|
// 2. test tar command
|
|
if err := checkCommand(ctx, "tar", "--version"); err != nil {
|
|
return fmt.Errorf("tar 命令未找到: %w", err)
|
|
}
|
|
|
|
// 3. test docker command
|
|
if err := checkCommand(ctx, "docker", "info"); err != nil {
|
|
return fmt.Errorf("docker 命令未找到: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// checkCommand checks if a command is available by running it with the specified args
|
|
func checkCommand(ctx context.Context, name string, args ...string) error {
|
|
cmd := exec.CommandContext(ctx, name, args...)
|
|
if err := cmd.Run(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|