// Install rules will install all the rules and update the port sets.
325036
func (i *Instance) installRules(cfg *ACLInfo, containerInfo *policy.PUInfo) error {
	var err error
	var appACLIPset, netACLIPset []aclIPset
	policyrules := containerInfo.Policy

	if err := i.updateProxySet(containerInfo.Policy, cfg.ProxySetName); err != nil {
		return err
	}

	if appACLIPset, err = i.createACLIPSets(cfg.ContextID, policyrules.ApplicationACLs()); err != nil {
		return err
	}

	if netACLIPset, err = i.createACLIPSets(cfg.ContextID, policyrules.NetworkACLs()); err != nil {
		return err
	}

	// Install the PU specific chain first.
	if err := i.addContainerChain(cfg.AppChain, cfg.NetChain); err != nil {
		return err
	}

	// If its a remote and thus container, configure container rules.
	if i.mode == constants.RemoteContainer || i.mode == constants.Sidecar {
		if err := i.configureContainerRules(cfg); err != nil {
			return err
		}
	}

	// If its a Linux process configure the Linux rules.
	if i.mode == constants.LocalServer {
		if err := i.configureLinuxRules(cfg); err != nil {
			return err
		}
	}

	isHostPU := extractors.IsHostPU(containerInfo.Runtime, i.mode)

	if err := i.addExternalACLs(cfg.ContextID, cfg.AppChain, cfg.NetChain, appACLIPset, true); err != nil {
		return err
	}

	if err := i.addExternalACLs(cfg.ContextID, cfg.NetChain, cfg.AppChain, netACLIPset, false); err != nil {
		return err
	}

	if err := i.addPacketTrap(cfg, isHostPU); err != nil {
		return err
	}

	return nil
}
251866
func (c *Client) UpdateInstallation(installation Installation) (updateTime time.Time, err error) {
	payload, err := json.Marshal(installation)
	uri := fmt.Sprintf("/1/installations/%s", installation.ObjectID())
	resp, err := c.doWithBody("PUT", uri, bytes.NewReader(payload))
	if err != nil {
		return updateTime, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return updateTime, err
	}
	c.trace("UpdateInstallation", uri, string(body))
	updatedAt := &struct {
		Time time.Time `json:"updatedAt"`
	}{}
	err = json.Unmarshal(body, updatedAt)
	return updatedAt.Time, err
}
1151213
func Install(scheme *runtime.Scheme) {
	utilruntime.Must(templateapiv1.Install(scheme))
	utilruntime.Must(scheme.SetVersionPriority(templatev1.GroupVersion))
}
1181158
func Install(scheme *runtime.Scheme) {
	utilruntime.Must(authorizationapi.Install(scheme))
	utilruntime.Must(rbacconversion.AddToScheme(scheme))
	utilruntime.Must(authorizationapiv1.Install(scheme))
	utilruntime.Must(scheme.SetVersionPriority(authorizationv1.GroupVersion))
}
90317
func Install(c *cli.Context) {
	cfg, err := config.New()
	if err != nil {
		log.Fatal(err)
	}

	installedParsers := make(map[string]struct{})
	for _, parser := range getInstalledParsers() {
		installedParsers[parser] = struct{}{}
	}

	if !c.Args().Present() {
		installAll(cfg, installedParsers)
	} else {
		parser := c.Args().First()
		parserName := genParserName(parser)
		if _, ok := installedParsers[parser]; !ok {
			if err := installParser(cfg, parserName, true); err != nil {
				log.Fatal(err)
			}
		} else {
			log.Info(parserName, " already installed")
		}
	}
}
138580
func NewRules() *rules {
	rules := &rules{namesKeys: nameToKey, phoneDevices: phoneDevices, tabletDevices: tabletDevices, operatingSystems: operatingSystems, browsers: browsers}
	rules.setMobileDetectionRules(nameToKey)
	return rules
}
520436
func (agent *Agent) install(ctx context.Context) error {
	exe, err := os.Executable()
	if err != nil {
		return err
	}

	substitutions := map[string]string{
		"Agent":          exe,
		"Server":         agent.server,
		"ServiceAccount": agent.serviceAccount,
		"User":           agent.swarmingUser,
	}
	content, err := substituteAsset(ctx, agent.agentAutoStartTemplate, substitutions)
	if err != nil {
		return err
	}
	path, err := substitute(ctx, agent.agentAutoStartPath, substitutions)
	if err != nil {
		return err
	}

	_, err = os.Stat(path)
	if err == nil || os.IsExist(err) {
		bytes, err := ioutil.ReadFile(path)
		if err != nil {
			return err
		}
		if string(bytes) == content {
			logging.Infof(ctx, "Already installed: %s.", path)
			return nil
		}
		logging.Infof(ctx, "Reinstalling: %s.", path)
		if err = agent.strategy.stop(ctx); err != nil {
			return err
		}
	} else {
		logging.Infof(ctx, "Installing: %s.", path)
	}
	if err = ioutil.WriteFile(path, []byte(content), 0644); err != nil {
		return err
	}
	return agent.strategy.start(ctx, path)
}
1001299
func (c *Client) Install(argv []string) error {
	usage := fmt.Sprintf(`Loads the definitions of components from local unit files.

After install, the components will be available to start.

"deisctl install" looks for unit files in these directories, in this order:
- the $DEISCTL_UNITS environment variable, if set
- $HOME/.deis/units
- /var/lib/deis/units

Usage:
  deisctl install [<target>...] [options]

Options:
  --router-mesh-size=<num>  Number of routers to be loaded when installing the platform [default: %d].
`, cmd.DefaultRouterMeshSize)
	// parse command-line arguments
	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		return err
	}

	meshSizeArg, _ := args["--router-mesh-size"].(string)
	parsedValue, err := strconv.ParseUint(meshSizeArg, 0, 8)
	if err != nil || parsedValue < 1 {
		fmt.Print("Error: argument --router-mesh-size: invalid value, make sure the value is an integer between 1 and 255.\n")
		return err
	}
	cmd.RouterMeshSize = uint8(parsedValue)

	return cmd.Install(args["<target>"].([]string), c.Backend, c.configBackend, cmd.CheckRequiredKeys)
}
630009
func (fs *Filters) Install(watcher *Filter) (string, error) {
	if watcher.KeySym != nil && watcher.KeyAsym != nil {
		return "", fmt.Errorf("filters must choose between symmetric and asymmetric keys")
	}

	if watcher.Messages == nil {
		watcher.Messages = make(map[common.Hash]*ReceivedMessage)
	}

	id, err := GenerateRandomID()
	if err != nil {
		return "", err
	}

	fs.mutex.Lock()
	defer fs.mutex.Unlock()

	if fs.watchers[id] != nil {
		return "", fmt.Errorf("failed to generate unique ID")
	}

	if watcher.expectsSymmetricEncryption() {
		watcher.SymKeyHash = crypto.Keccak256Hash(watcher.KeySym)
	}

	watcher.id = id
	fs.watchers[id] = watcher
	fs.addTopicMatcher(watcher)
	return id, err
}
1077834
func Setup(conf config.Config) error {
	downlinkLockDuration = conf.NetworkServer.Scheduler.ClassC.DownlinkLockDuration
	schedulerInterval = conf.NetworkServer.Scheduler.SchedulerInterval
	installationMargin = conf.NetworkServer.NetworkSettings.InstallationMargin
	downlinkTXPower = conf.NetworkServer.NetworkSettings.DownlinkTXPower

	return nil
}
555406
func Install(scheme *runtime.Scheme) {
	utilruntime.Must(autoscaling.AddToScheme(scheme))
	utilruntime.Must(v2beta2.AddToScheme(scheme))
	utilruntime.Must(v2beta1.AddToScheme(scheme))
	utilruntime.Must(v1.AddToScheme(scheme))
	utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v2beta1.SchemeGroupVersion, v2beta2.SchemeGroupVersion))
}
1106689
func Install(scheme *runtime.Scheme) {
	utilruntime.Must(appsapiv1.Install(scheme))
	utilruntime.Must(scheme.SetVersionPriority(appsv1.GroupVersion))
}
779602
func (i *Installer) Install() ([]string, error) {
	if len(i.RemoteFiles) == 0 {
		return nil, errNoFilesToInstall
	}

	allErrors := *errors.New("")
	var installedDirectories []string // not strict to the remote file len because it continues on error

	// create a copy of the remote files
	remoteFiles := append([]string{}, i.RemoteFiles...)
	// clear the installers's remote files
	i.mu.Lock()
	i.RemoteFiles = nil

	for _, remoteFileZip := range remoteFiles {
		p, err := Install(remoteFileZip, i.InstallDir, i.Indicator)
		if err != nil {
			allErrors = allErrors.AppendErr(err)
			// add back the remote file if the install of this remote file has failed
			i.RemoteFiles = append(i.RemoteFiles, remoteFileZip)
		}

		installedDirectories = append(installedDirectories, p)
	}
	i.mu.Unlock()
	if !allErrors.IsAppended() {
		return installedDirectories, nil
	}

	return installedDirectories, allErrors
}
889642
func installDockerCerts(s DockerHandlerSettings, dstDir string) error {
	m := []struct {
		src string
		dst string
	}{
		{s.Certs.CABase64, filepath.Join(dstDir, dockerCaCert)},
		{s.Certs.ServerCertBase64, filepath.Join(dstDir, dockerSrvCert)},
		{s.Certs.ServerKeyBase64, filepath.Join(dstDir, dockerSrvKey)},
	}

	// Check if certs are provided
	for _, v := range m {
		if len(v.src) == 0 {
			log.Printf("Docker certificate %s is not provided in the extension settings, skipping docker certs installation", v.dst)
			return nil
		}
	}

	// Check the target directory, if not create
	if ok, err := util.PathExists(dstDir); err != nil {
		return fmt.Errorf("error checking cert dir: %v", err)
	} else if !ok {
		if err := os.MkdirAll(dstDir, 0755); err != nil {
			return err
		}
	}

	// Write the certs
	for _, v := range m {
		// Decode base64
		in := strings.TrimSpace(v.src)
		f, err := base64.StdEncoding.DecodeString(in)
		if err != nil {
			// Fallback to original file input
			f = []byte(in)
		}

		if err := ioutil.WriteFile(v.dst, f, 0600); err != nil {
			return fmt.Errorf("error writing certificate: %v", err)
		}
	}
	return nil
}
70220
func (darwin *darwinRecord) Install(args ...string) (string, error) {
	installAction := "Install " + darwin.description + ":"

	if ok, err := checkPrivileges(); !ok {
		return installAction + failed, err
	}

	srvPath := darwin.servicePath()

	if darwin.isInstalled() {
		return installAction + failed, ErrAlreadyInstalled
	}

	file, err := os.Create(srvPath)
	if err != nil {
		return installAction + failed, err
	}
	defer file.Close()

	execPatch, err := executablePath(darwin.name)
	if err != nil {
		return installAction + failed, err
	}

	templ, err := template.New("propertyList").Parse(propertyList)
	if err != nil {
		return installAction + failed, err
	}

	if err := templ.Execute(
		file,
		&struct {
			Name, Path string
			Args       []string
		}{darwin.name, execPatch, args},
	); err != nil {
		return installAction + failed, err
	}

	return installAction + success, nil
}
462688
func (r *Redirect) updateRules(l4 *policy.L4Filter) revert.RevertFunc {
	oldRules := r.rules
	r.rules = make(policy.L7DataMap, len(l4.L7RulesPerEp))
	for key, val := range l4.L7RulesPerEp {
		r.rules[key] = val
	}
	return func() error {
		r.mutex.Lock()
		r.rules = oldRules
		r.mutex.Unlock()
		return nil
	}
}
313199
func Install(i Installer) error {
	basePath := filepath.Dir(i.Path())
	if _, pathErr := os.Stat(basePath); os.IsNotExist(pathErr) {
		if err := os.MkdirAll(basePath, 0755); err != nil {
			return err
		}
	}

	if _, pathErr := os.Stat(i.Path()); !os.IsNotExist(pathErr) {
		return i.Update()
	}

	return i.Install()
}