Fixed some internet packages errors
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user