diff --git a/Dockerfile b/Dockerfile index 0ebf38e..c5f7750 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,11 @@ WORKDIR /app COPY ./ ./ RUN go mod download +RUN apt-get update +RUN apt-get install -y ppp +RUN apt-get install -y net-tools + RUN CGO_ENABLED=0 GOOS=linux go build -o /modem-test -CMD ["/modem-test"] \ No newline at end of file +CMD ["/modem-test"] diff --git a/api/modem/internet/ic.go b/api/modem/internet/ic.go index 29c9bef..fdad76a 100644 --- a/api/modem/internet/ic.go +++ b/api/modem/internet/ic.go @@ -57,26 +57,28 @@ func New(logger *log.Logger, port at.Port) Conn { } func (c *conn) checkPackageExist(pname string) bool { - resp, err := exec.Command("sudo", "apt-mark", "showmanual", pname).Output() + resp, err := exec.Command("apt-mark", "showmanual", pname).Output() + c.logger.Println("CHECK:", resp) if err != nil { c.logger.Println("CHECK PACKAGE ERROR: ", err.Error()) return false } - return string(resp) == pname + return string(resp[:len(pname)]) == pname } func (c *conn) ensurePackage(pname string) error { if c.checkPackageExist(pname) { return nil } - c.logger.Println("Installing", pname, "package...") - resp, err := exec.Command("sudo", "apt-get", "install", pname).Output() - if err != nil { - return fmt.Errorf("execute install cmd: %w", err) - } - c.logger.Println(resp) - c.logger.Println("\x1b[38;2;255;0;0mComplete\x1b[38;2;255;255;255m") - return nil + return fmt.Errorf("package %s not installed", pname) + // c.logger.Println("Installing", pname, "package...") + // resp, err := exec.Command("apt-get", "install", pname).Output() + // if err != nil { + // return fmt.Errorf("execute install cmd: %w", err) + // } + // c.logger.Println(resp) + // c.logger.Println("\x1b[38;2;255;0;0mComplete\x1b[38;2;255;255;255m") + // return nil } // Check requirenments @@ -155,7 +157,7 @@ func (c *conn) setup() error { } func (c *conn) connect() error { - resp, err := exec.Command("sudo", "pon", pppConfigName).Output() + resp, err := exec.Command("pon", pppConfigName).Output() if err != nil { return fmt.Errorf("execute connect cmd: %w", err) } @@ -164,7 +166,7 @@ func (c *conn) connect() error { } func (c *conn) diconnect() error { - resp, err := exec.Command("sudo", "poff", pppConfigName).Output() + resp, err := exec.Command("poff", pppConfigName).Output() if err != nil { return fmt.Errorf("execute disconnect cmd: %w", err) } diff --git a/api/modem/modem.go b/api/modem/modem.go index 3df5486..632c13d 100644 --- a/api/modem/modem.go +++ b/api/modem/modem.go @@ -98,7 +98,7 @@ func (m *modem) Init() error { // Establish internet connection m.logger.Println("=============================== Internet") m.ic = internet.New(log.New(m.logger.Writer(), "internet", log.LstdFlags), m.port) - if err := m.Init(); err != nil { + if err := m.ic.Init(); err != nil { return fmt.Errorf("internet connection init: %w", err) } return nil