2018-07-19 19:48:46 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2018-07-21 17:18:19 +02:00
|
|
|
"path/filepath"
|
2018-07-19 19:48:46 +02:00
|
|
|
"strings"
|
2018-07-19 19:56:40 +02:00
|
|
|
"time"
|
2020-05-02 16:17:20 +02:00
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2020-07-05 02:45:23 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/settings"
|
2020-06-13 19:29:50 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2018-07-19 19:48:46 +02:00
|
|
|
)
|
|
|
|
|
2018-07-19 19:56:40 +02:00
|
|
|
func sudoLoopBackground() {
|
|
|
|
updateSudo()
|
|
|
|
go sudoLoop()
|
|
|
|
}
|
|
|
|
|
|
|
|
func sudoLoop() {
|
|
|
|
for {
|
|
|
|
updateSudo()
|
2021-03-13 12:08:11 +01:00
|
|
|
time.Sleep(241 * time.Second)
|
2018-07-19 19:56:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateSudo() {
|
|
|
|
for {
|
2021-03-13 12:06:31 +01:00
|
|
|
err := config.Runtime.CmdRunner.Show(exec.Command(config.SudoBin, "-v"))
|
2018-07-19 19:56:40 +02:00
|
|
|
if err != nil {
|
2018-11-14 13:14:41 +01:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2018-07-19 19:56:40 +02:00
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 17:18:19 +02:00
|
|
|
// waitLock will lock yay checking the status of db.lck until it does not exist
|
2020-07-05 15:34:27 +02:00
|
|
|
func waitLock(dbPath string) {
|
|
|
|
lockDBPath := filepath.Join(dbPath, "db.lck")
|
|
|
|
if _, err := os.Stat(lockDBPath); err != nil {
|
2018-07-21 17:18:19 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-05 15:34:27 +02:00
|
|
|
text.Warnln(gotext.Get("%s is present.", lockDBPath))
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Warn(gotext.Get("There may be another Pacman instance running. Waiting..."))
|
2018-07-21 17:18:19 +02:00
|
|
|
|
|
|
|
for {
|
|
|
|
time.Sleep(3 * time.Second)
|
2020-07-05 15:34:27 +02:00
|
|
|
if _, err := os.Stat(lockDBPath); err != nil {
|
2018-07-21 18:36:16 +02:00
|
|
|
fmt.Println()
|
2018-07-21 17:18:19 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 02:45:23 +02:00
|
|
|
func passToPacman(args *settings.Arguments) *exec.Cmd {
|
2020-08-19 01:48:07 +02:00
|
|
|
argArr := make([]string, 0, 32)
|
2019-03-19 22:10:58 +01:00
|
|
|
|
2020-07-05 03:17:35 +02:00
|
|
|
if args.NeedRoot(config.Runtime) {
|
2019-03-19 22:10:58 +01:00
|
|
|
argArr = append(argArr, config.SudoBin)
|
2020-08-19 01:48:07 +02:00
|
|
|
argArr = append(argArr, strings.Fields(config.SudoFlags)...)
|
2018-07-19 19:48:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
argArr = append(argArr, config.PacmanBin)
|
2020-07-08 03:22:01 +02:00
|
|
|
argArr = append(argArr, args.FormatGlobals()...)
|
2020-07-05 02:45:23 +02:00
|
|
|
argArr = append(argArr, args.FormatArgs()...)
|
2020-08-19 00:17:35 +02:00
|
|
|
if settings.NoConfirm {
|
2018-07-19 19:48:46 +02:00
|
|
|
argArr = append(argArr, "--noconfirm")
|
|
|
|
}
|
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
argArr = append(argArr, "--config", config.PacmanConf, "--")
|
2020-07-05 02:45:23 +02:00
|
|
|
argArr = append(argArr, args.Targets...)
|
2018-07-19 19:48:46 +02:00
|
|
|
|
2020-07-05 03:17:35 +02:00
|
|
|
if args.NeedRoot(config.Runtime) {
|
2020-07-05 15:34:27 +02:00
|
|
|
waitLock(config.Runtime.PacmanConf.DBPath)
|
2018-07-21 17:18:19 +02:00
|
|
|
}
|
2018-07-19 19:48:46 +02:00
|
|
|
return exec.Command(argArr[0], argArr[1:]...)
|
|
|
|
}
|