Browse Source

DEV-3918 feat(auto-exec-bin) add new subject and tests for auto-exec-bin exercise

DEV-4191-DeepInSystem
Zouhair AMAZZAL 2 years ago committed by Niccolò Primo
parent
commit
d1295b02a8
  1. 56
      sh/tests/auto-exec-bin_test.sh
  2. 3
      sh/tests/solutions/auto-exec-bin.sh
  3. 33
      subjects/devops/auto-exec-bin/README.md

56
sh/tests/auto-exec-bin_test.sh

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Unofficial Bash Strict Mode
set -euo pipefail
IFS='
'
FILENAME="student/auto-exec-bin.sh"
script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd)
setupbin() {
if [ -f ${FILENAME} ]; then
echo "bin already exists!"
else
mkdir -p ~/myBins
curl -o ~/myBins/01exec https://assets.01-edu.org/devops-branch/01exec
chmod +x ~/myBins/01exec
echo "bin installed!"
fi
}
challenge() {
# run soultion script
export PATH=""
$(bash "$script_dirS"/$FILENAME)
submitted=$(cd / && 01exec)
# run student script
export PATH=""
$(bash "$script_dirS"/solutions/auto-exec-bin.sh)
expected=$(cd / && 01exec)
# diff
diff <(echo "$submitted") <(echo "$expected")
}
# True if FILE exists and is a regular file
if [ -f ${FILENAME} ]; then
# FILE exists and it's not empty
if [ -s ${FILENAME} ]; then
if [[ $(cat $FILENAME | grep echo | wc -l) -ne 0 ]]; then
echo "echo is not allowed in this exercise!"
exit 1
fi
setupbin
challenge
else
echo "The file exist but is empty"
exit 1
fi
else
echo "File does not exist"
exit 1
fi

3
sh/tests/solutions/auto-exec-bin.sh

@ -0,0 +1,3 @@
#!/usr/bin/env bash
export PATH=$PATH:~/myBins

33
subjects/devops/auto-exec-bin/README.md

@ -0,0 +1,33 @@
## auto-exec-bin
### Instructions
Create a file `auto-exec-bin.sh`, which will make a binary with the name `01exec` in `~/myBins` executable from any working directory.
You can use any binary from your choice or you can use our binary: [01exec](https://assets.01-edu.org/devops-branch/01exec)
> If our binary is not working in your environment, you can pick any binary for the tests!
Expected Output:
```console
$ ls -l ~/myBins # the binary
01exec
$ 01exec
error: command not found: 01exec
$ ./auto-exec-bin.sh
$ 01exec
Hello 01 Scripting Pool
$ cd /{random-path} && 01exec
Hello 01 Scripting Pool
$
```
### Hints
`PATH` environment variable is a variable where the shell search for the binaries for the execution.
when you put a command the shell will search for binary in `PATH` folders
![auto binary exec](https://assets.01-edu.org/devops-branch/auto-exec-diagram.png)
> You have to use Man or Google to know more about commands flags, in order to solve this exercise!
> Google and Man will be your friends!
Loading…
Cancel
Save