Fixed some internet packages errors

This commit is contained in:
Andrey Egorov 2024-07-29 14:02:06 +03:00
parent ebab41c510
commit 2eb21228e3
3 changed files with 20 additions and 14 deletions

View File

@ -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"]
CMD ["/modem-test"]

View File

@ -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)
}

View File

@ -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