use tlmgr if dnf not available

This commit is contained in:
lukas 2021-08-26 23:29:19 +02:00
parent 89960a86ae
commit 2f62f6c407
2 changed files with 50 additions and 26 deletions

73
Main.go
View File

@ -7,9 +7,11 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strconv" "strconv"
"strings"
) )
const ( const (
@ -53,17 +55,16 @@ func compileAndInstall() {
} else { } else {
fmt.Println(*out) fmt.Println(*out)
fmt.Println("another build error occured!") fmt.Println("Another build error occured!")
} }
} else { } else {
fmt.Println("document built successfully!") fmt.Println("Document built successfully!")
} }
} }
func parseMissingFile(output *string) string { func parseMissingFile(output *string) string {
matchfile := regexp.MustCompile("! LaTeX Error: File `([^`']*)' not found|! I can't find file `([^`']*)'.") matchfile := regexp.MustCompile("! LaTeX Error: File `([^`']*)' not found|! I can't find file `([^`']*)'.")
matches := matchfile.FindStringSubmatch(*output) matches := matchfile.FindStringSubmatch(*output)
fmt.Printf("%#v\n", matches)
if matches != nil { if matches != nil {
if matches[1] != "" { if matches[1] != "" {
return matches[1] return matches[1]
@ -75,7 +76,6 @@ func parseMissingFile(output *string) string {
// ok now we try to find a font error // ok now we try to find a font error
fontregex := regexp.MustCompile(`! Font \\[^=]*=([^\s]*)\s`) fontregex := regexp.MustCompile(`! Font \\[^=]*=([^\s]*)\s`)
fontmatch := fontregex.FindStringSubmatch(*output) fontmatch := fontregex.FindStringSubmatch(*output)
fmt.Printf("%#v\n", fontmatch)
if fontmatch != nil { if fontmatch != nil {
if fontmatch[1] != "" { if fontmatch[1] != "" {
return fontmatch[1] return fontmatch[1]
@ -129,6 +129,7 @@ func compileLatex() (*string, error) {
stdout, _ := cmd.StdoutPipe() stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe() stderr, _ := cmd.StderrPipe()
fmt.Println("Building:")
cmd.Start() cmd.Start()
output := "" output := ""
@ -198,29 +199,51 @@ func rootCheck() bool {
} }
func installFile(filename string) bool { func installFile(filename string) bool {
if !commandExists("dnf") { if commandExists("dnf") {
fmt.Println("dnf not existing!") cmd := exec.Command("dnf", "-y", "install", fmt.Sprintf("tex(%s)", filename))
fmt.Println(cmd.String())
stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
fmt.Println("running dnf install now!")
cmd.Start()
printReadCloserToStdout(stdout)
printReadCloserToStdout(stderr)
err := cmd.Wait()
if err != nil {
fmt.Println(err.Error())
return false
}
return true
} else if commandExists("tlmgr") {
fmt.Println("dnf not existing -> trying to install with tlmgr")
// tlmgr package name should be filename without suffix
cmd := exec.Command("tlmgr", "install", strings.TrimSuffix(filename, filepath.Ext(filename)))
fmt.Println(cmd.String())
stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
fmt.Println("running tlmgr install now!")
cmd.Start()
printReadCloserToStdout(stdout)
printReadCloserToStdout(stderr)
err := cmd.Wait()
if err != nil {
fmt.Println(err.Error())
return false
}
return true
} else {
fmt.Println("There seems to be no tex distribution to be installed??")
return false return false
} }
cmd := exec.Command("dnf", "-y", "install", fmt.Sprintf("tex(%s)", filename))
fmt.Println(cmd.String())
stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
fmt.Println("running dnf install now!")
cmd.Start()
printReadCloserToStdout(stdout)
printReadCloserToStdout(stderr)
err := cmd.Wait()
if err != nil {
fmt.Println(err.Error())
return false
}
return true
} }
func printReadCloserToStdout(reader io.ReadCloser) { func printReadCloserToStdout(reader io.ReadCloser) {

View File

@ -4,4 +4,5 @@ This application installs all neccessary latex packages to perform a successfull
## Currently Supported OS ## Currently Supported OS
* Fedora * Fedora (dnf) with native package manager
* every linux with tlmgr available