Skip to content

Commit

Permalink
dongles: over write the modem.conf file
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Jan 31, 2017
1 parent e519633 commit ea91d9e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/urfave/cli"
)

const (
dongleFile = "modem.conf"
)

type DongleConfig map[string]struct {
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
Expand Down Expand Up @@ -65,12 +68,13 @@ func Dongles(ctx *cli.Context) error {
}
var buf bytes.Buffer
PrintAst(&buf, o)
fmt.Println(&buf)
return nil
return ioutil.WriteFile(filepath.Join(asteriskDir(), dongleFile),
buf.Bytes(), 0644,
)
}

func PatchAst(dst *Ast) (*Ast, error) {
name := filepath.Join(asteriskDir(), "modem.conf")
name := filepath.Join(asteriskDir(), dongleFile)
b, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
Expand Down Expand Up @@ -98,9 +102,7 @@ func PatchAst(dst *Ast) (*Ast, error) {

var buf bytes.Buffer
PrintAst(&buf, patch)
fmt.Println(&buf)
o := &Ast{}
fmt.Println(len(patch.Sections))
for _, v := range patch.Sections {
for _, i := range v.values {
if i.key == "imei" {
Expand All @@ -115,7 +117,6 @@ func PatchAst(dst *Ast) (*Ast, error) {
}
o.Sections = append(o.Sections, v)
}
fmt.Println("HERE")
return o, nil
}

Expand Down

0 comments on commit ea91d9e

Please sign in to comment.