package main import ( "fmt" "os" "github.com/pborman/getopt/v2" "git.server.ky/slackcoder/pkgtools" ) //Usage: installpkg [options] // //Installpkg is used to install a .t{gz,bz,lz,xz} package like this: // installpkg slackware-package-1.0.0-i486-1.tgz (or .tbz, .tlz, .txz) // //options: --warn (warn if files will be overwritten, but do not install) // --root /mnt (install someplace else, like /mnt) // --infobox (use dialog to draw an info box) // --terse (display a one-line short description for install) // --terselength (line length in terse mode - default is // the number of columns available) // --menu (confirm package installation with a menu, unless // the priority is [required] or ADD) // --ask (used with menu mode: always ask if a package should be // installed regardless of what the package's priority is) // --priority ADD|REC|OPT|SKP (provide a priority for the entire // package list to use instead of the priority in the // tagfile) // --tagfile /somedir/tagfile (specify a different file to use // for package priorities. The default is "tagfile" in // the package's directory) // --threads For xz/plzip compressed packages, set the max // number of threads to be used for decompression. Only has // an effect if a multithreaded compressor was used, and then // only on large packages. For plzip, the default is equal to // the number of CPU threads available on the machine. For xz, // the default is equal to 2. // --md5sum (record the package's md5sum in the metadata file) // --no-overwrite When extracting the package, do not overwrite // existing files. Usually, this option should not be used. // It exists so that upgradepkg can use it for the second // installation pass. The first pass has already overwritten // the previous package's files, and this will catch the few // corner cases without generating unnecessary writes. func usage() { getopt.PrintUsage(os.Stdout) } func ParseFlags() *pkgtools.InstallPkgFlags { flags := pkgtools.DefaultInstallPkgFlags flags.SetEnvValues() getopt.FlagLong(&flags.Root, "root", 0, "/mnt (install someplace else, like /mnt)") getopt.FlagLong(&flags.NoOverwrite, "no-overwrite", 0, "When extracting the package, do not overwrite existing files. Usually, this option should not be used. It exists so that upgradepkg can use it for the second installation pass. The first pass has already overwritten the previous package's files, and this will catch the few corner cases without generating unnecessary writes.") getopt.Parse() return &flags } func main() { getopt.SetParameters("package_filename ...") help := getopt.BoolLong("help", 0, "display help") flags := ParseFlags() if len(getopt.Args()) == 0 || *help { usage() return } for _, pkg := range getopt.Args() { err := pkgtools.InstallPkg(flags, pkg) if err != nil { fmt.Println(err) os.Exit(-1) } } }