Helper scripts
This page describes helper scripts that let you take a shortcut.
When bootstrapping a sandbox container or virtual machine, Instruqt injects a couple of 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 container or virtual machine has a POSIX shell available at
/bin/sh
.fail-message
and set-workdir
are the most common helper scripts and are highlighted here.fail-message
["message"]
The
fail-message
script can be used to provide feedback to the learner when writing check scripts. The function will write a given string to stdout
, prefixed with FAIL:
. message
The fail message you want to show to the learner.
Bash
#!/bin/bash
# check
echo "Checking the solution of the challenge"
if [ !$EVERYTHING_WENT_WELL ]; then
fail-message "Your challenge failed because of REASON"
# which is equivalent to
echo "FAIL: Your challenge failed because of REASON"
exit 1
fi
set-workdir
[directory]
The
set-workdir
script can be used to change the active working directory for a terminal tab from a challenge setup script.directory
The directory you want to set as the active working directory.
To set the
usr
directory as the active working directory:Bash
#!/bin/bash
# setup
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 modified 1mo ago