-
Notifications
You must be signed in to change notification settings - Fork 2
Install
kless edited this page Jul 27, 2012
·
8 revisions
The own developer should include on its program a way to manage extra files related to his project, instead of to be managed by another person (the package's maintainer into an operating system).
Here you have a simple way for the developer and easy to integrate in whatever system, with the advantage of be cross-platform. You only have to add code in functions Install, Remove, and Purge.
If you use Gowizard: gowizard -installer
Else, use this template in "<Go project>/Installer/install.go"
// Installer manages files related to the system.
//
// During the development, it could be used the command:
//
// sudo env PATH=$PATH GOPATH=$GOPATH go run install.go <flag...>
package main
import (
"flag"
"log"
"os"
//"runtime"
)
func Install() {
}
func Remove() {
// Remove binary files.
}
func Purge() {
Remove()
// Remove config files, directories, etc.
}
// * * *
func init() {
log.SetFlags(0)
log.SetPrefix("ERROR: ")
/* If a system has not been implemented on this manager, use:
if runtime.GOOS == "windows" {
log.Fatal("TODO: handle Windows")
}*/
if os.Getuid() != 0 {
log.Fatal("you have to be root")
}
}
func main() {
install := flag.Bool("i", false, "install")
remove := flag.Bool("r", false, "remove")
purge := flag.Bool("p", false, "purge")
flag.Parse()
if flag.NFlag() == 0 {
flag.PrintDefaults()
os.Exit(2)
}
if *purge {
Purge()
} else if *remove {
Remove()
}
if *install {
Install()
}
}