2018-01-02 02:49:14 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
func input(s string) (string, error) {
|
2018-01-03 00:54:49 -07:00
|
|
|
stdinBuf := bufio.NewReader(os.Stdin)
|
2018-01-02 02:49:14 -07:00
|
|
|
|
|
|
|
fmt.Print(s)
|
|
|
|
|
2018-01-03 00:54:49 -07:00
|
|
|
text, err := stdinBuf.ReadString('\n')
|
2018-01-02 02:49:14 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return text[:len(text)-1], err
|
|
|
|
}
|
|
|
|
|
|
|
|
func searchRepo() {
|
2018-01-02 23:37:32 -07:00
|
|
|
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")
|
2018-01-03 00:54:49 -07:00
|
|
|
print("Type: 'm' for main menu\n")
|
2018-01-02 23:37:32 -07:00
|
|
|
print("Type: 'q' to quit the application\n\n")
|
|
|
|
|
|
|
|
var programName, _ = input(">> ")
|
|
|
|
|
2018-01-03 00:54:49 -07:00
|
|
|
if programName == "m" {
|
2018-01-02 23:37:32 -07:00
|
|
|
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")
|
2018-01-03 00:54:49 -07:00
|
|
|
searchRepo()
|
2018-01-02 02:49:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func installPak() {
|
2018-01-02 23:37:32 -07:00
|
|
|
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")
|
2018-01-03 00:54:49 -07:00
|
|
|
print("Type: 'm' for main menu\n")
|
2018-01-02 23:37:32 -07:00
|
|
|
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(">> ")
|
|
|
|
|
2018-01-03 00:54:49 -07:00
|
|
|
if programName == "m" {
|
2018-01-02 23:37:32 -07:00
|
|
|
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")
|
2018-01-03 00:54:49 -07:00
|
|
|
installPak()
|
2018-01-02 02:49:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-02 23:37:32 -07:00
|
|
|
func listPak() {
|
|
|
|
print("\n| List of installed Flatpaks |\n\n")
|
|
|
|
cmd := exec.Command("flatpak", "list")
|
2018-01-02 02:49:14 -07:00
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
|
|
}
|
2018-01-02 23:37:32 -07:00
|
|
|
fmt.Print(string(out), "\n\n")
|
2018-01-02 02:49:14 -07:00
|
|
|
}
|
|
|
|
|
2018-01-02 23:37:32 -07:00
|
|
|
func removePak() {
|
2018-01-03 00:54:49 -07:00
|
|
|
print("\n| Remove Flatpaks |\n\n")
|
2018-01-02 23:37:32 -07:00
|
|
|
listPak()
|
2018-01-03 00:54:49 -07:00
|
|
|
print("\n\nCopy and paste a namespace above and press enter to remove from system\n\n")
|
|
|
|
print("Type: 'm' for main menu\n")
|
2018-01-02 23:37:32 -07:00
|
|
|
print("Type: 'q' to quit the application\n\n")
|
|
|
|
var programName, _ = input(">> ")
|
|
|
|
|
2018-01-03 00:54:49 -07:00
|
|
|
if programName == "m" {
|
2018-01-02 23:37:32 -07:00
|
|
|
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")
|
2018-01-03 00:54:49 -07:00
|
|
|
removePak()
|
2018-01-02 02:49:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-02 03:17:33 -07:00
|
|
|
//// TODO
|
2018-01-02 02:49:14 -07:00
|
|
|
/*
|
|
|
|
func optionsMenu() {
|
|
|
|
var choice string
|
|
|
|
print("\n| FlatFace Options |\n\n")
|
|
|
|
print("\n1. Add Repository\n\n")
|
|
|
|
|
|
|
|
choice, _ = input(">> ")
|
|
|
|
|
|
|
|
if choice == "1" {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2018-01-02 23:37:32 -07:00
|
|
|
func syncRepo() {
|
|
|
|
print("Syncing repo data...\n")
|
2018-01-02 03:32:32 -07:00
|
|
|
cmd := exec.Command("flatpak", "update", "--appstream")
|
2018-01-02 02:49:14 -07:00
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
|
|
}
|
2018-01-02 03:17:33 -07:00
|
|
|
fmt.Print(string(out))
|
2018-01-02 02:49:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkRepo() {
|
2018-01-02 23:37:32 -07:00
|
|
|
print("\nAdding flathub repo if needed...\n")
|
2018-01-02 02:49:14 -07:00
|
|
|
cmd := exec.Command("flatpak", "remote-add", "--if-not-exists", "flathub", "https://flathub.org/repo/flathub.flatpakrepo")
|
|
|
|
out, err := cmd.CombinedOutput()
|
2018-01-02 23:37:32 -07:00
|
|
|
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()
|
2018-01-02 02:49:14 -07:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
|
|
}
|
2018-01-02 03:17:33 -07:00
|
|
|
fmt.Print(string(out))
|
2018-01-02 02:49:14 -07:00
|
|
|
}
|
|
|
|
func mainMenu() {
|
2018-01-03 00:54:49 -07:00
|
|
|
print("\n\n| FlatFace v0.0.1a-3 |\n\n")
|
2018-01-02 02:49:14 -07:00
|
|
|
var choice string
|
2018-01-03 00:54:49 -07:00
|
|
|
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")
|
2018-01-02 02:49:14 -07:00
|
|
|
|
|
|
|
choice, _ = input(">> ")
|
|
|
|
|
2018-01-03 00:54:49 -07:00
|
|
|
if choice == "s" {
|
2018-01-02 02:49:14 -07:00
|
|
|
searchRepo()
|
|
|
|
|
2018-01-03 00:54:49 -07:00
|
|
|
} else if choice == "i" {
|
2018-01-02 02:49:14 -07:00
|
|
|
installPak()
|
2018-01-03 00:54:49 -07:00
|
|
|
} else if choice == "r" {
|
2018-01-02 02:49:14 -07:00
|
|
|
removePak()
|
2018-01-03 00:54:49 -07:00
|
|
|
} else if choice == "l" {
|
2018-01-02 02:49:14 -07:00
|
|
|
listPak()
|
2018-01-03 00:54:49 -07:00
|
|
|
} else if choice == "u" {
|
2018-01-02 02:49:14 -07:00
|
|
|
updatePak()
|
|
|
|
} else if choice == "q" {
|
2018-01-02 23:37:32 -07:00
|
|
|
os.Exit(0)
|
2018-01-02 02:49:14 -07:00
|
|
|
} else {
|
|
|
|
print("Unknown option")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2018-01-02 02:56:39 -07:00
|
|
|
checkRepo()
|
2018-01-02 02:49:14 -07:00
|
|
|
for {
|
|
|
|
mainMenu()
|
|
|
|
}
|
|
|
|
}
|