aboutsummaryrefslogtreecommitdiffsponsor
path: root/cmd/installpkg/main.go
blob: 5cc495579b146c1a0b16ba884841081fbc1e9da8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main

import (
	"fmt"
	"os"

	"github.com/pborman/getopt/v2"

	"git.server.ky/slackcoder/pkgtools"
)

//Usage: installpkg [options] <package_filename>
//
//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 <length> (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 <number> 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 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() {
	flags := ParseFlags()
	if len(getopt.Args()) == 0 {
		getopt.PrintUsage(os.Stdout)
		return
	}

	for _, pkg := range getopt.Args() {
		err := pkgtools.InstallPkg(flags, pkg)
		if err != nil {
			fmt.Println(err)
			os.Exit(-1)
		}
	}
}