Allow force lower case commands (Issue #15)

This commit is contained in:
Terence Boldt 2021-09-28 17:34:22 -04:00
parent 18c25108b3
commit 1b184a9b5a
1 changed files with 15 additions and 6 deletions

View File

@ -9,6 +9,8 @@ import (
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io" "github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
) )
var forceLowercase = false
func ExecCommand() { func ExecCommand() {
workingDirectory, err := os.Getwd() workingDirectory, err := os.Getwd()
if err != nil { if err != nil {
@ -18,6 +20,9 @@ func ExecCommand() {
fmt.Printf("Reading command to execute...\n") fmt.Printf("Reading command to execute...\n")
linuxCommand, err := a2io.ReadString() linuxCommand, err := a2io.ReadString()
if forceLowercase {
linuxCommand = strings.ToLower(linuxCommand)
}
fmt.Printf("Command to run: %s\n", linuxCommand) fmt.Printf("Command to run: %s\n", linuxCommand)
if strings.HasPrefix(linuxCommand, "cd ") { if strings.HasPrefix(linuxCommand, "cd ") {
workingDirectory = strings.Replace(linuxCommand, "cd ", "", 1) workingDirectory = strings.Replace(linuxCommand, "cd ", "", 1)
@ -39,9 +44,13 @@ func ExecCommand() {
"Built-in commands:\r" + "Built-in commands:\r" +
"a2help - display this message\r" + "a2help - display this message\r" +
"a2wifi - set up wifi\r" + "a2wifi - set up wifi\r" +
"A2LOWER - force lowercase for II+\r" +
"\r") "\r")
return return
} }
if linuxCommand == "A2LOWER" {
forceLowercase = true
}
if linuxCommand == "a2wifi" { if linuxCommand == "a2wifi" {
a2io.WriteString("\r" + a2io.WriteString("\r" +
"Usage: a2wifi list\r" + "Usage: a2wifi list\r" +
@ -54,18 +63,18 @@ func ExecCommand() {
} }
if strings.HasPrefix(linuxCommand, "a2wifi select") { if strings.HasPrefix(linuxCommand, "a2wifi select") {
params := strings.Fields(linuxCommand) params := strings.Fields(linuxCommand)
if (len(params) != 4) { if len(params) != 4 {
a2io.WriteString("\rIncorrect number of parameters. Usage: a2wifi select SSID PASSWORD\r\r") a2io.WriteString("\rIncorrect number of parameters. Usage: a2wifi select SSID PASSWORD\r\r")
return return
} }
ssid := params[2] ssid := params[2]
psk := params[3] psk := params[3]
linuxCommand = "printf \"country=ca\\nupdate_config=1\\nctrl_interface=/var/run/wpa_supplicant\\n\\nnetwork={\\n scan_ssid=1\\n ssid=\\\"%s\\\"\n psk=\\\"%s\\\"\\n}\\n\" " + linuxCommand = "printf \"country=ca\\nupdate_config=1\\nctrl_interface=/var/run/wpa_supplicant\\n\\nnetwork={\\n scan_ssid=1\\n ssid=\\\"%s\\\"\n psk=\\\"%s\\\"\\n}\\n\" " +
ssid + " " + ssid + " " +
psk + " " + psk + " " +
" > /tmp/wpa_supplicant.conf; " + " > /tmp/wpa_supplicant.conf; " +
"sudo mv /tmp/wpa_supplicant.conf /etc/wpa_supplicant/; " + "sudo mv /tmp/wpa_supplicant.conf /etc/wpa_supplicant/; " +
"sudo wpa_cli -i wlan0 reconfigure" "sudo wpa_cli -i wlan0 reconfigure"
} }
cmd := exec.Command("bash", "-c", linuxCommand) cmd := exec.Command("bash", "-c", linuxCommand)
cmd.Dir = workingDirectory cmd.Dir = workingDirectory