From 96a901922254294f44a0d3a2e1a22945791bc4ad Mon Sep 17 00:00:00 2001 From: tectiv3 Date: Fri, 15 Sep 2017 17:58:44 +0900 Subject: [PATCH 1/4] Fix wifi config on asus tinker board --- device/config/configurator.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/device/config/configurator.go b/device/config/configurator.go index 709f796..6e3451c 100644 --- a/device/config/configurator.go +++ b/device/config/configurator.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - log "github.com/sirupsen/logrus" "github.com/pkg/errors" + log "github.com/sirupsen/logrus" "github.com/xshellinc/tools/dialogs" "github.com/xshellinc/tools/lib/help" "github.com/xshellinc/tools/lib/ping" @@ -266,6 +266,21 @@ func SaveWifi(storage map[string]interface{}) error { return errors.New(err.Error() + ":" + eut) } + if _, ok := storage[Interface]; !ok { + log.Debug("Adding wlan0 to interfaces...") + fp := help.AddPathSuffix("unix", MountDir, IsaaxConfDir, "network", "interfaces") + + _, eut, err := ssh.Run(fmt.Sprintf(`echo "%s" > %s`, ` + auto wlan0 + iface wlan0 inet dhcp + source-directory /etc/network/interfaces.d +`, fp)) + if err != nil { + log.WithField("eut", eut).Error(err.Error()) + } + + } + return nil } @@ -291,7 +306,7 @@ func SetInterface(storage map[string]interface{}) error { if dialogs.YesNoDialog("Change values?") { AskInterfaceParams(&i) } - + //TODO: allow user to setup several static interfaces at once switch device[num] { case "eth0": storage[Interface] = fmt.Sprintf(InterfaceETH, i.Address, i.Netmask, i.Gateway, i.DNS) From bb68f88dae79533528bda35ab93306b925a8cde5 Mon Sep 17 00:00:00 2001 From: tectiv3 Date: Tue, 19 Sep 2017 14:20:07 +0900 Subject: [PATCH 2/4] Update asus image --- mapping.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapping.json b/mapping.json index 17592e0..6b2ed2d 100644 --- a/mapping.json +++ b/mapping.json @@ -285,7 +285,7 @@ "Pass": "linaro" }, { - "URL": "http://isaax-distro.s3-website-ap-northeast-1.amazonaws.com/boards/tinker/v1.8/20170417-tinker-board-linaro-stretch-alip-v1.8.img.zip", + "URL": "http://isaax-distro.s3-website-ap-northeast-1.amazonaws.com/boards/tinker/v2.0.1/20170817-tinker-board-linaro-stretch-alip-v2.0.1.img.zip", "Title": "TinkerOS Debian", "Alias": "debian", "User": "linaro", From 48860b990fdfec2f8ed9c1c8b2df1064f62c3f6d Mon Sep 17 00:00:00 2001 From: tectiv3 Date: Wed, 20 Sep 2017 12:21:45 +0900 Subject: [PATCH 3/4] Fix setting static IP on wlan0 interface for asus tinker board --- device/config/constants.go | 1 + 1 file changed, 1 insertion(+) diff --git a/device/config/constants.go b/device/config/constants.go index d1946dd..7012203 100644 --- a/device/config/constants.go +++ b/device/config/constants.go @@ -28,6 +28,7 @@ const ( "iface eth0 inet manual\n" + "\n" + "allow-hotplug wlan0\n" + + "auto wlan0\n" + "iface wlan0 inet static\n" + "address %s\n" + "netmask %s\n" + From ff99333fb32865548f8ad083947c40f77a414056 Mon Sep 17 00:00:00 2001 From: tectiv3 Date: Wed, 20 Sep 2017 13:55:22 +0900 Subject: [PATCH 4/4] Add ability to set hostname on configuration --- device/config/configurator.go | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/device/config/configurator.go b/device/config/configurator.go index 6e3451c..3e557d2 100644 --- a/device/config/configurator.go +++ b/device/config/configurator.go @@ -59,6 +59,7 @@ func NewDefault(ssh ssh_helper.Util) *Configurator { config.AddConfigFn(Wifi, NewCallbackFn(SetWifi, SaveWifi)) config.AddConfigFn(Interface, NewCallbackFn(SetInterface, SaveInterface)) config.AddConfigFn(DNS, NewCallbackFn(SetSecondaryDNS, SaveSecondaryDNS)) + config.AddConfigFn("Hostname", NewCallbackFn(SetHostname, SaveHostname)) return config } @@ -411,3 +412,57 @@ func AskInterfaceParams(i *Interfaces) { i.Netmask = dialogs.GetSingleAnswer("Please enter your netmask: ", dialogs.IpAddressValidator) i.DNS = dialogs.GetSingleAnswer("Please enter your dns server: ", dialogs.IpAddressValidator) } + +// SetHostname is a default method with a dialog to configure device hostname +func SetHostname(storage map[string]interface{}) error { + ssh, ok := storage["ssh"].(ssh_helper.Util) + if !ok { + return errors.New("Cannot get ssh config") + } + fp := help.AddPathSuffix("unix", MountDir, "/etc/hostname") + out, eut, err := ssh.Run("cat " + fp) + if err != nil || strings.TrimSpace(eut) != "" { + log.WithField("eut", eut).Error(err) + return err + } + hostname := strings.TrimSpace(out) + fmt.Println("[+] Default hostname: ", hostname) + + if dialogs.YesNoDialog("Do you want to change default hostname?") { + storage["NewHostname"] = dialogs.GetSingleAnswer("New hostname: ", dialogs.EmptyStringValidator) + storage["OldHostname"] = hostname + } + + return nil +} + +// SaveHostname is a default method to save hostname into the image +func SaveHostname(storage map[string]interface{}) error { + + if _, ok := storage["OldHostname"]; !ok { + return nil + } + if _, ok := storage["NewHostname"]; !ok { + return nil + } + + ssh, ok := storage["ssh"].(ssh_helper.Util) + if !ok { + return errors.New("Cannot get ssh config") + } + + hosts := help.AddPathSuffix("unix", MountDir, "/etc/hosts") + hostname := help.AddPathSuffix("unix", MountDir, "/etc/hostname") + data := fmt.Sprintf("'s/%s/%s/g'", storage["OldHostname"], storage["NewHostname"]) + + if _, eut, err := ssh.Run(fmt.Sprintf(`sed -i %s %s`, data, hosts)); err != nil || strings.TrimSpace(eut) != "" { + log.WithField("eut", eut).Error(err) + return err + } + if _, eut, err := ssh.Run(fmt.Sprintf(`sed -i %s %s`, data, hostname)); err != nil || strings.TrimSpace(eut) != "" { + log.WithField("eut", eut).Error(err) + return err + } + + return nil +}