github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/upgrades/dotprofile.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package upgrades
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/utils/exec"
    10  )
    11  
    12  // As of the middle of the 1.17 cycle, the proxy settings are written out to
    13  // /home/ubuntu/.juju-proxy both by cloud-init and the machine environ worker.
    14  // An older version of juju that has been upgraded will get the proxy settings
    15  // written out to the .juju-proxy file, but the .profile for the ubuntu user
    16  // wouldn't have been updated to source this file.
    17  //
    18  // This upgrade step is to add the line to source the file if it is missing
    19  // from the file.
    20  func ensureUbuntuDotProfileSourcesProxyFile(context Context) error {
    21  	// We look to see if the proxy line is there already as the manual
    22  	// provider may have had it aleady. The ubuntu user may not exist
    23  	// (local provider only).
    24  	command := fmt.Sprintf(""+
    25  		`([ ! -e %s/.profile ] || grep -q '.juju-proxy' %s/.profile) || `+
    26  		`printf '\n# Added by juju\n[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"\n' >> %s/.profile`,
    27  		ubuntuHome, ubuntuHome, ubuntuHome)
    28  	logger.Tracef("command: %s", command)
    29  	result, err := exec.RunCommands(exec.RunParams{
    30  		Commands: command,
    31  	})
    32  	if err != nil {
    33  		return err
    34  	}
    35  	logger.Tracef("stdout: %s", result.Stdout)
    36  	return nil
    37  }