# Ignition Install Path from G Script?

**URL:** <https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881>\
**Category:** Ignition\
**Created:** [November 5, 2017, 12:55am UTC](https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881 "2017-11-05T00:55:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 5, 2017, 12:55am UTC](https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881/1 "2017-11-05T00:55:25Z")

</div>

Is there a way to determine the Ignition installation path from a gateway script?

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 5, 2017, 1:55am UTC](https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881/2 "2017-11-05T01:55:47Z")

</div>

I guess this is a good start `context.getServletContext().getRealPath('/')`

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 5, 2017, 1:47pm UTC](https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881/3 "2017-11-05T13:47:29Z")

</div>

Try:

```auto
import os
print os.getcwd()

```

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 5, 2017, 2:23pm UTC](https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881/4 "2017-11-05T14:23:44Z")

</div>

Thanks again… that was easy.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 5, 2017, 2:32pm UTC](https://forum.inductiveautomation.com/t/ignition-install-path-from-g-script/15881/5 "2017-11-05T14:32:55Z")

</div>

Here is a class that I use to download activemq-all-xxx.jar from maven if not in lib/core/gateway.

```auto
AMQLibDownloader().Download('activemq-all')

```

```auto
from java.lang import Exception
from java.io import IOException
from java.nio.file import Paths
from java.net import URL
from org.apache.commons.io import FileUtils
import sys
import os

class AMQLibDownloader():
	def __init__ (self):
		self._logger = system.util.getLogger('activemq.AMQLibDownloader')
		self._localGatwayCoreRelativePathString = "//lib//core//gateway"
		
	def _buildLatestMavenUrl(self,artifactId):
		try:
			searchUrl = "http://search.maven.org/solrsearch/select?q=%s&rows=1&wt=json" % artifactId
			json = system.net.httpGet(searchUrl)
			dict = system.util.jsonDecode(json)
			artifact = dict['response']['docs'][0]
			url = "http://%s.maven.org/maven2/%s/%s/%s/%s-%s.%s" \
				% (artifact['repositoryId'],artifact['g'].replace('.','/'),artifact['a'],artifact['latestVersion'],artifact['a'],artifact['latestVersion'],artifact['p'])
			return url, artifact
		except Exception, ex:
			self._logger.error("unable to build maven url for artifactId: '%s'" % artifactId)
			self._logger.info(str(ex))
			return None, None
		
	def Download(self,artifactId,force=False):
		mavenUrl, mavenArtifact = self._buildLatestMavenUrl(artifactId)
		
		if mavenUrl is not None:
			gatewayCorePath = Paths.get(os.getcwd() + self._localGatwayCoreRelativePathString)
			libraryLocalPath = Paths.get(gatewayCorePath.toString() + "//%s-latest.%s" % (mavenArtifact['a'],mavenArtifact['p'])).toFile()
			libraryRemotePath = URL(mavenUrl)
			
			if not force:
				if not system.file.fileExists(libraryLocalPath.toString()):
					force = True
					self._logger.warn("'%s' was not found" % libraryLocalPath.toString())
				else:
					pass
					# get local SHA
					# search maven by SHA
					# compare local version against latest version
					# update if mavent has newer version => set force=True
					
			else:
				self._logger.info("'%s' download forced" % libraryRemotePath.toString())
				
			if force:
				try:
					self._logger.info("downloading '%s' => '%s'" % (libraryRemotePath.toString(), libraryLocalPath.toString()))
					FileUtils.copyURLToFile(libraryRemotePath, libraryLocalPath)
					sys.path.append(libraryLocalPath.toString()) #manual append until gateway is rebooted
					self._logger.info('done')
				except IOException, iex:
					self._logger.error(iex)
				except Exception, ex:
					self._logger.error(ex)

```
