package main import ( "bufio" "fmt" "log" "os" "os/exec" ) func input(s string) (string, error) { stdinBuf := bufio.NewReader(os.Stdin) fmt.Print(s) text, err := stdinBuf.ReadString('\n') if err != nil { panic(err) } return text[:len(text)-1], err } func searchRepo() { print("\n| Search Repositories |\n\n") print("Enter a search term and copy the namespace to clipboard\n") print("Paste this later to the install menu.\n\n") print("Type: 'm' for main menu\n") print("Type: 'q' to quit the application\n\n") var programName, _ = input(">> ") if programName == "m" { return } else if programName == "q" { os.Exit(0) } else { cmd := exec.Command("flatpak", "search", programName) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print("\n", "Results for ", programName, ": \n\n", string(out), "\n") searchRepo() } } func installPak() { print("\n| Install Menu |\n\n") print("To Use: Copy paste a flatpak namespace from search results\n\n") print("EXAMPLE: 'com.play0ad.zeroad' - installs the Game '0ad'\n\n") print("Type: 'm' for main menu\n") print("Type: 'q' to quit the application\n\n") print("NOTE: install can take several seconds and appear to hang. Please be patient...\n\n") var programName, _ = input(">> ") if programName == "m" { return } else if programName == "q" { os.Exit(0) } else { cmd := exec.Command("flatpak", "install", "flathub", programName) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out), "\n") installPak() } } func listPak() { print("\n| List of installed Flatpaks |\n\n") cmd := exec.Command("flatpak", "list") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out), "\n\n") } func removePak() { print("\n| Remove Flatpaks |\n\n") listPak() print("\n\nCopy and paste a namespace above and press enter to remove from system\n\n") print("Type: 'm' for main menu\n") print("Type: 'q' to quit the application\n\n") var programName, _ = input(">> ") if programName == "m" { return } else if programName == "q" { os.Exit(0) } else { cmd := exec.Command("flatpak", "uninstall", programName) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out), "\n\n") removePak() } } //// TODO /* func optionsMenu() { var choice string print("\n| FlatFace Options |\n\n") print("\n1. Add Repository\n\n") choice, _ = input(">> ") if choice == "1" { } } */ func syncRepo() { print("Syncing repo data...\n") cmd := exec.Command("flatpak", "update", "--appstream") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out)) } func checkRepo() { print("\nAdding flathub repo if needed...\n") cmd := exec.Command("flatpak", "remote-add", "--if-not-exists", "flathub", "https://flathub.org/repo/flathub.flatpakrepo") out, err := cmd.CombinedOutput() syncRepo() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out)) } func updatePak() { print("Checking for app upgrades..\n") cmd := exec.Command("flatpak", "update") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out)) } func mainMenu() { print("\n\n| FlatFace v0.0.1a-3 |\n\n") var choice string print("[S]earch remote for flatpaks\n") print("[I]nstall flatpaks from remote\n") print("[R]emove local flatpaks\n") print("[L]ist install flatpaks\n") print("[U]pdate\n") print("[Q]uit\n\n") choice, _ = input(">> ") if choice == "s" { searchRepo() } else if choice == "i" { installPak() } else if choice == "r" { removePak() } else if choice == "l" { listPak() } else if choice == "u" { updatePak() } else if choice == "q" { os.Exit(0) } else { print("Unknown option") } } func main() { checkRepo() for { mainMenu() } }