Helper scripts

Helper scripts are pre-written scripts to help implement lifecycle scripts.

Overview

When bootstrapping a sandbox container or virtual machine, Instruqt injects some helper scripts. These scripts assist you in setting up the environment or applying check scripts. See the currently available set of helper scripts on GitHub.

Helper scripts assume the host has a POSIX shell available at/bin/sh.

This article covers the following helper scripts:

  • fail-message

  • set-workdir

fail-message

The fail-message helper script provides feedback to the learner when writing check scripts. The function will write a given string to stdout, prefixed with FAIL:.

fail-message "your fail message here..."

Consider the following example:

#!/bin/bash

if [ !$EVERYTHING_WENT_WELL ]; then
  fail-message "Your challenge failed because of REASON"
  exit 1
fi

Without the helper script, the format would be:

#!/bin/bash

if [ !$EVERYTHING_WENT_WELL ]; then
  echo "FAIL: Your challenge failed because of REASON"
  exit 1
fi

set-workdir

The set-workdir script can be used to change the active working directory for a terminal tab from a challenge setup script.

set-workdir <dir>

Example

Consider the following example, which sets the usr directory as the active working directory:

#!/bin/bash

set-workdir usr

The set-workdir script is implemented using $HOME/.bashrc. This means you will have to use bash as the shell for the container or virtual machine.

If you don't have bash available, you can achieve the same behavior by adding a cd /path/to/workdir command to the shell's profile (e.g. $HOME/.profile or /etc/profile).

When using the ash shell (which most busybox based containers do), you can also indicate that the .bashrc profile needs to be loaded. To do so, add an environment variable ENV with value $HOME/.bashrc. to the container's environment variables in the config.yml.

Last updated