Disabling resin-specific scripts in your package.json

Say you want to install some system packages into your image before deploying to your devices, or perhaps, you want to startup services that your application would require (a DB? enabling udev?).

So you follow the deployment instructions, where you place your startup initalizations commands into little shell scripts, initalized by package.json via preinstall and start. Everything works great, until you realize there is no way to disable them in your local dev/test environment :confused: crap.

One way would be to maintain your resin-specific changes to a separate branch, but that can get unwieldy sometimes, especially if you perform modifications on package.json in master.

Currently, I’m eschewing this method, and am getting the scripts themselves to bypass running if they detect they’re not on a resin system.

In the top of my shell scripts, I check for the presence of RESIN_DEVICE_UUID :

# Don't run deps if not running on Resin device.
if [ ! ${RESIN_DEVICE_UUID} ]; then
  exit 0;

And that’s it. :smile:

Do reply here if you have another way of handling this problem, I admit this isn’t the cleanest solution, but it works for me (for now).

Hi bakavic,

Massive apologies for taking so long to get back to you!

I think this is the best solution for the time being as we will always export this environment variable and I think it’s reasonably sane to use the unique identifier for the device to determine it’s there.

The only change I’d make is to use exit, as it defaults to 0, and also no need for the trailing semicolon :smile:

I’ll raise the issue of adding a separate IS_RESIN_DEVICE environment variable internally and see what people think!

Best, Lorenzo

Hi bakavic,

I just discussed this with my colleagues, and found out that in fact we already have a variable that fulfills this function - RESIN - so your code can be updated to:-

# Don't run deps if not running on Resin device.
if [ ! $RESIN ]; then

Let me know if you have any further issues!

Best, Lorenzo

1 Like

Ah, this works well for when detecting if the script is being run on a resin.io device.

But I’m also wondering about detecting when the script is being run on the build server? - reason being that I wouldn’t want the preinstall script to run when during local development.


Is this relating to the architecture of the device you are pushing to? I.e. you want to install some GPIO-related stuff on the device, but of course would rather not locally? If so you could potentially adjust your code to determine architecture, and behave differently in the 2 environments, e.g., adding the following to the top of your preinstall script:-

if [[ ! "$(uname -m)" =~ ^arm ]]; then
	echo not arm >&2
	exit 1

Would this achieve what you need?

Best, Lorenzo

Just putting this useful blog post “Where is my Code Running?”, which covers some useful topics related to this question. Hopefully other people will find it useful :smile: