Working on installer.to with SCoRe Lab for GSoC 2020: Week 1

Heshan Geasman
SCoRe Lab
Published in
3 min readMay 17, 2020

Week 1

This week I invested in looking into CLI based testing frameworks to test the installer scripts. My mentors suggested we need to test for different platforms thus we discussed to run test scripts on different Docker images which has different operating systems.

Boom! We got an issue. I tried running a installer script on a docker container and the script failed. The script has sudo commands and when on Docker you don’t get sudo command as the docker runs as root. Then I tried fixing this.

I checked how others has done this and got a clue from get.docker.com

sh_c='sh -c'
if [ "$user" != 'root' ]; then
if command_exists sudo; then
sh_c='sudo -E sh -c'
elif command_exists su; then
sh_c='su -c'
else
cat >&2 <<-'EOF'
Error: this installer needs the ability to run commands as root.
We are unable to find either "sudo" or "su" available to make this happen.
EOF
exit 1
fi
fi

Then I did the same, checked if the user is root and checked if user has sudo and then only user the sudo command with installation commands

PREFIX=''
if [ "$USER" != 'root' ]; then
if command_exists sudo; then
PREFIX='sudo'
else
cat >&2 <<-'EOF'
Error: this installer needs the ability to run commands as root.
We are unable to find "sudo" available to make this happen.
EOF
exit 1
fi
fi
if [ ! -z $APT_GET_CMD ]; then
$PREFIX apt-get update
$PREFIX apt-get install git
fi

We agreed we will try out ShellSpec as a testing framework this week and I started playing with it. I could run a spec test to check if the site is working and pull installer script of git from installer.to repo via curl and test installing it.

Writing tests with ShellSpec is fun. Below is a test to check the installer script to install git.

Describe "Installer script for"
Describe "git"
It "should install with curl"
When call bash -c "curl https://installer.to/git | bash"
The output should include "git version"
End
End
End

This will actually download the installer script from the intaller.to with cURL and run it with bash to install the tool. We discussed to use docker containers for this because unless we can’t install the same tool again.

I tired out GitHub actions also this week! I created a simple set of GitHub Actions which runs ubuntu and alpine dockers.

Screenshot of GitHub Actions on a PR

This way, we can run tests on each PR and tests scripts can run the installers and confirm if the tool is correctly installed by the installer script.

But my mentors pointed out when we have lot of installers scripts, this will take a log time to run the whole test suite which runs all the installers scripts in the repo. I will check if we can get only the modified or added installer scripts and run tests on them only in the coming week.

--

--