github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/juju/home.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package juju 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/utils/ssh" 9 "gopkg.in/juju/charmrepo.v2-unstable" 10 11 "github.com/juju/juju/juju/osenv" 12 ) 13 14 // InitJujuXDGDataHome initializes the charm cache, environs/config and utils/ssh packages 15 // to use default paths based on the $JUJU_DATA or $HOME environment variables. 16 // This function should be called before running a Juju CLI command. 17 func InitJujuXDGDataHome() error { 18 jujuXDGDataHome := osenv.JujuXDGDataHomeDir() 19 if jujuXDGDataHome == "" { 20 return errors.New("cannot determine juju data home, required environment variables are not set") 21 } 22 osenv.SetJujuXDGDataHome(jujuXDGDataHome) 23 charmrepo.CacheDir = osenv.JujuXDGDataHomePath("charmcache") 24 if err := ssh.LoadClientKeys(osenv.JujuXDGDataHomePath("ssh")); err != nil { 25 return errors.Annotate(err, "cannot load ssh client keys") 26 } 27 return nil 28 }