diff --git a/sh/tests/remake_test.sh b/sh/tests/remake_test.sh new file mode 100644 index 00000000..e707468e --- /dev/null +++ b/sh/tests/remake_test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +IFS=' +' + +challenge () { + if [[ $# -eq 1 ]]; then + submitted=$(bash student/remake.sh "$1") + expected=$(bash solutions/remake.sh "$1"-expected) + diff <(echo $submitted) <(echo $expected) + diff <(ls -ltr $1) <(ls -ltr $1-expected) + else + diff <(bash student/remake.sh "$@") <(bash solutions/remake.sh "$@") + fi +} + +challenge a +challenge diff --git a/sh/tests/solutions/remake.sh b/sh/tests/solutions/remake.sh new file mode 100644 index 00000000..4460b92d --- /dev/null +++ b/sh/tests/solutions/remake.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +IFS=' +' + +if [[ $# -eq 1 ]]; then + mkdir -p $1 + cd $1 + touch -t 01010001 ciao + chmod 442 ciao + mkdir mamma + touch -t 01020001 mamma + chmod 777 mamma + touch -t 01030001 guarda + chmod 400 guarda + touch -t 01040001 come + chmod 642 come + mkdir mi + touch -t 01050001 mi + chmod 452 mi + touch -t 01060001 diverto + chmod 421 diverto +else + echo Error + exit 1 +fi diff --git a/subjects/devops/remake/README.md b/subjects/devops/remake/README.md new file mode 100644 index 00000000..30550e82 --- /dev/null +++ b/subjects/devops/remake/README.md @@ -0,0 +1,73 @@ +## remake + +### Instructions + +Create a file `remake.sh`, which will take one argument, the relative path of a directory, and will create new files and directories in it. + +If the number of given arguments is not one, your script should print `Error` and exit with the status code 1. + +Below the expected behavior of your script: + +```console +$ bash remake.sh given-path +$ ls -ltr given-path +total 8 +-r--r---w- 1 nprimo nprimo 0 Jan 1 00:01 ciao +drwxrwxrwx 2 nprimo nprimo 4096 Jan 2 00:01 mamma +-r-------- 1 nprimo nprimo 0 Jan 3 00:01 guarda +-rw-r---w- 1 nprimo nprimo 0 Jan 4 00:01 come +dr--r-x-w- 2 nprimo nprimo 4096 Jan 5 00:01 mi +-r---w---x 1 nprimo nprimo 0 Jan 6 00:01 diverto +$ +``` + +### Hints + +- `mkdir ` command is used to create a new directory in the specified ``. For example: + +```console +$ ls -l +total 0 +-rw-rw-r-- 1 nprimo nprimo 0 Jan 12 14:26 a +-rw-rw-r-- 1 nprimo nprimo 0 Jan 12 14:26 b +-rw-rw-r-- 1 nprimo nprimo 0 Jan 12 14:26 c +$ mkdir d +$ ls -l +total 4 +-rw-rw-r-- 1 nprimo nprimo 0 Jan 12 14:26 a +-rw-rw-r-- 1 nprimo nprimo 0 Jan 12 14:26 b +-rw-rw-r-- 1 nprimo nprimo 0 Jan 12 14:26 c +drwxrwxr-x 2 nprimo nprimo 4096 Jan 12 14:26 d +$ +``` + +- `touch ` command is used to change the modification and/or access time of the specified `` to the current time. If the file does not exist yet, a new empty file is created at the specified ``. + +The flag `-t` allow to specify the time in the format `[[CC]YY]MMDDhhmm[.ss]` instead of the current time. + +- `chmod` The chmod, or change mode, command allows an administrator to set or modify a file’s permissions. Every UNIX/Linux file has an owner user and an owner group attached to it, and every file has permissions associated with it. The permissions are as follows: read, write, or execute. + +This is what the default permissions looks like when you create a file. + +```console +$ touch example.txt +$ ls -l example.txt +-rw-rw-r-- 1 user user 348 dez 13 15:31 example.txt +$ +``` + +This is what it looks like if you want to give permissions to read, write and execute to every group. + +```console +$ chmod 777 example.txt +$ ls -l example.txt +-rwxrwxrwx 1 user user 348 dez 13 15:31 example.txt +$ +``` + +> 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! + +### References + +- [Chmod](https://www.linode.com/docs/guides/modify-file-permissions-with-chmod/#modify-file-permissions-with-chmod)