package main import ( "fmt" "gitea.com/oreonproject/eonlite/library" "github.com/fatih/color" "os" "strconv" ) func main() { if len(os.Args) < 2 { fmt.Println(color.GreenString("[INFO]"), "Usage: eonlite ") return } filesInstalled, err, errorCode := library.InstallRPM(os.Args[1], func(severity string, content string, prompt bool) string { var severityPretty string switch severity { case "INFO": severityPretty = color.GreenString("[INFO]") case "WARN": severityPretty = color.YellowString("[WARN]") case "ERROR": severityPretty = color.HiYellowString("[ERROR]") case "CRITICAL": severityPretty = color.HiRedString("[CRITICAL]") case "FATAL": severityPretty = color.RedString("[FATAL]") } fmt.Println(severityPretty, content) if prompt { fmt.Print(": ") var userInput string _, err := fmt.Scanln(&userInput) if err != nil { fmt.Println(color.RedString("[FATAL]"), "Failed to read user input:", err) os.Exit(17) } else { return userInput } } return "" }) if err != nil { switch errorCode { case 1: fmt.Println(color.RedString("[FATAL]"), "Failed to open RPM", os.Args[1]) case 2: fmt.Println(color.RedString("[FATAL]"), "Failed to create buffer:", err) case 3: fmt.Println(color.RedString("[FATAL]"), "Failed to read RPM at offset:", err) case 4: fmt.Println(color.RedString("[FATAL]"), "Failed to close RPM:", err) case 5: fmt.Println(color.RedString("[FATAL]"), "Failed to create ZStandard decoder:", err) case 6: fmt.Println(color.RedString("[FATAL]"), "Failed to un-CPIO file number", strconv.Itoa(filesInstalled)+":", err) case 7: fmt.Println(color.RedString("[FATAL]"), "Failed to create directory (are you running as root?):", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 8: fmt.Println(color.RedString("[FATAL]"), "Failed to read directory (are you running as root?):", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 9: fmt.Println(color.RedString("[FATAL]"), "You cannot put a file into a non-directory. Another file may be conflicting with a directory name of this RPM.") fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 10: fmt.Println(color.RedString("[FATAL]"), "Failed to read file (are you running as root?):", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 11: fmt.Println(color.RedString("[FATAL]"), "You cannot write a file where a directory already exists. A directory name may be conflicting with a file in this RPM.") fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 12: fmt.Println(color.RedString("[FATAL]"), "Failed to remove file:", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 13: fmt.Println(color.RedString("[FATAL]"), "Failed open file for writing:", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 14: fmt.Println(color.RedString("[FATAL]"), "Failed to write file:", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") case 15: fmt.Println(color.RedString("[FATAL]"), "Failed to close file after writing:", err) fmt.Println(color.GreenString("[INFO]"), filesInstalled, "files were installed before the error occurred.") default: fmt.Println(color.RedString("[FATAL]"), "An impossible logic error has occurred. Please check if the laws of physics still apply, and if so, please move your computer to a location with less radiation, such as a lead nuclear bunker: value of", errorCode, "is not in library code") errorCode = 16 } os.Exit(errorCode) } else { fmt.Println(color.GreenString("[INFO]"), "Installation complete! Installed", filesInstalled, "files") os.Exit(errorCode) } }