Add override for package manager

This commit is contained in:
Elara 2020-11-27 18:26:42 -08:00
parent 33a2a834ab
commit dbd6a3162d
4 changed files with 77 additions and 9 deletions

View File

@ -5,34 +5,83 @@ pak: main.go
installbinonly: pak installbinonly: pak
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
mkdir -p $(DESTDIR)/etc/pak.d
aptinstall: pak.cfg pak aptinstall: plugins/apt/pak.cfg pak
install -Dm644 pak.cfg $(DESTDIR)/etc/pak.cfg install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.cfg
mkdir -p $(DESTDIR)/etc/pak.d
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.d/snap.cfg
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.d/yay.cfg
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.d/zypper.cfg
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.d/pacman.cfg
install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.d/brew.cfg
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.d/aptitude.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
snapinstall: plugins/snap/pak.cfg pak snapinstall: plugins/snap/pak.cfg pak
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.cfg install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.cfg
mkdir -p $(DESTDIR)/etc/pak.d
install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.d/apt.cfg
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.d/yay.cfg
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.d/zypper.cfg
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.d/pacman.cfg
install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.d/brew.cfg
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.d/aptitude.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
yayinstall: plugins/yay/pak.cfg pak yayinstall: plugins/yay/pak.cfg pak
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.cfg install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.cfg
mkdir -p $(DESTDIR)/etc/pak.d
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.d/snap.cfg
install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.d/apt.cfg
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.d/zypper.cfg
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.d/pacman.cfg
install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.d/brew.cfg
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.d/aptitude.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
pacinstall: plugins/pacman/pak.cfg pak pacinstall: plugins/pacman/pak.cfg pak
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.cfg install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.cfg
mkdir -p $(DESTDIR)/etc/pak.d
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.d/snap.cfg
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.d/yay.cfg
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.d/zypper.cfg
install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.d/apt.cfg
install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.d/brew.cfg
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.d/aptitude.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
aptitude: plugins/aptitude/pak.cfg pak aptitude: plugins/aptitude/pak.cfg pak
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.cfg install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.cfg
mkdir -p $(DESTDIR)/etc/pak.d
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.d/snap.cfg
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.d/yay.cfg
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.d/zypper.cfg
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.d/pacman.cfg
install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.d/brew.cfg
install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.d/apt.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
brewinstall: plugins/brew/pak.cfg pak brewinstall: plugins/brew/pak.cfg pak
mount -uw / install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.cfg
install -m644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.cfg mkdir -p $(DESTDIR)/etc/pak.d
install -m755 pak $(DESTDIR)/usr/bin/pak install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.d/snap.cfg
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.d/yay.cfg
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.d/zypper.cfg
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.d/pacman.cfg
install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.d/apt.cfg
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.d/aptitude.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
zyppinstall: plugins/zypper/pak.cfg pak zyppinstall: plugins/zypper/pak.cfg pak
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.cfg install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.cfg
mkdir -p $(DESTDIR)/etc/pak.d
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.d/snap.cfg
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.d/yay.cfg
install -Dm644 plugins/apt/pak.cfg $(DESTDIR)/etc/pak.d/apt.cfg
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.d/pacman.cfg
install -Dm644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.d/brew.cfg
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.d/aptitude.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak install -Dm755 pak $(DESTDIR)/usr/bin/pak
.PHONY: pak $(MAKECMDGOALS) .PHONY: pak $(MAKECMDGOALS)

22
main.go
View File

@ -52,8 +52,26 @@ func main() {
} }
} }
// Define variables for config file location, and override state boolean
var configFileLocation string
var isOverridden bool
// Get PAK_MGR_OVERRIDE environment variable
override := os.Getenv("PAK_MGR_OVERRIDE")
// If override is set
if override != "" {
// Set configFileLocation to /etc/pak.d/{override}.cfg
configFileLocation = "/etc/pak.d/" + override + ".cfg"
// Set override state to true
isOverridden = true
} else {
// Otherwise, set configFileLocation to default config
configFileLocation = "/etc/pak.cfg"
// Set override state to false
isOverridden = false
}
// Parse config file removing all comments and empty lines // Parse config file removing all comments and empty lines
config, err := ioutil.ReadFile("/etc/pak.cfg") config, err := ioutil.ReadFile(configFileLocation)
if err != nil { log.Fatal(err) } if err != nil { log.Fatal(err) }
commentRegex := regexp.MustCompile(`#.*`) commentRegex := regexp.MustCompile(`#.*`)
emptyLineRegex := regexp.MustCompile(`(?m)^\s*\n`) emptyLineRegex := regexp.MustCompile(`(?m)^\s*\n`)
@ -101,7 +119,7 @@ func main() {
// Displays help message if no arguments provided or -h/--help is passed // Displays help message if no arguments provided or -h/--help is passed
if len(args) == 0 || Contains(args, "-h") || Contains(args, "--help") || Contains(args, "help") { if len(args) == 0 || Contains(args, "-h") || Contains(args, "--help") || Contains(args, "help") {
printHelpMessage(packageManagerCommand, useRootBool, rootCommand, commands, shortcuts) printHelpMessage(packageManagerCommand, useRootBool, rootCommand, commands, shortcuts, isOverridden)
os.Exit(0) os.Exit(0)
} }

View File

@ -6,9 +6,10 @@ import (
) )
// Print help screen // Print help screen
func printHelpMessage(packageManagerCommand string, useRootBool bool, rootCommand string, commands []string, shortcuts []string) { func printHelpMessage(packageManagerCommand string, useRootBool bool, rootCommand string, commands []string, shortcuts []string, isOverridden bool) {
fmt.Println("Arsen Musayelyan's Package Manager Wrapper") fmt.Println("Arsen Musayelyan's Package Manager Wrapper")
fmt.Println("Current package manager is:", packageManagerCommand) fmt.Print("Current package manager is: ", packageManagerCommand)
if isOverridden { fmt.Println(" (overridden)") } else { fmt.Print("\n") }
if useRootBool { fmt.Println("Using root with command:", rootCommand) } else { fmt.Println("Not using root") } if useRootBool { fmt.Println("Using root with command:", rootCommand) } else { fmt.Println("Not using root") }
fmt.Println() fmt.Println()
fmt.Println("Usage: pak <command> [package]") fmt.Println("Usage: pak <command> [package]")