Add override for package manager
This commit is contained in:
parent
33a2a834ab
commit
dbd6a3162d
59
Makefile
59
Makefile
@ -5,34 +5,83 @@ pak: main.go
|
||||
|
||||
installbinonly: pak
|
||||
install -Dm755 pak $(DESTDIR)/usr/bin/pak
|
||||
mkdir -p $(DESTDIR)/etc/pak.d
|
||||
|
||||
aptinstall: pak.cfg pak
|
||||
install -Dm644 pak.cfg $(DESTDIR)/etc/pak.cfg
|
||||
aptinstall: plugins/apt/pak.cfg pak
|
||||
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
|
||||
|
||||
snapinstall: plugins/snap/pak.cfg pak
|
||||
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
|
||||
|
||||
yayinstall: plugins/yay/pak.cfg pak
|
||||
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
|
||||
|
||||
pacinstall: plugins/pacman/pak.cfg pak
|
||||
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
|
||||
|
||||
aptitude: plugins/aptitude/pak.cfg pak
|
||||
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
|
||||
|
||||
brewinstall: plugins/brew/pak.cfg pak
|
||||
mount -uw /
|
||||
install -m644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.cfg
|
||||
install -m755 pak $(DESTDIR)/usr/bin/pak
|
||||
install -Dm644 plugins/brew/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/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
|
||||
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
|
||||
|
||||
.PHONY: pak $(MAKECMDGOALS)
|
||||
|
22
main.go
22
main.go
@ -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
|
||||
config, err := ioutil.ReadFile("/etc/pak.cfg")
|
||||
config, err := ioutil.ReadFile(configFileLocation)
|
||||
if err != nil { log.Fatal(err) }
|
||||
commentRegex := regexp.MustCompile(`#.*`)
|
||||
emptyLineRegex := regexp.MustCompile(`(?m)^\s*\n`)
|
||||
@ -101,7 +119,7 @@ func main() {
|
||||
|
||||
// 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") {
|
||||
printHelpMessage(packageManagerCommand, useRootBool, rootCommand, commands, shortcuts)
|
||||
printHelpMessage(packageManagerCommand, useRootBool, rootCommand, commands, shortcuts, isOverridden)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
5
usage.go
5
usage.go
@ -6,9 +6,10 @@ import (
|
||||
)
|
||||
|
||||
// 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("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") }
|
||||
fmt.Println()
|
||||
fmt.Println("Usage: pak <command> [package]")
|
||||
|
Loading…
Reference in New Issue
Block a user