From 9b975fdf0fd8f63d6d70f109187032a046f620a9 Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 13 Dec 2022 18:24:41 +0000 Subject: [PATCH] feat(hard-perms): add subject, test and solution for the exercise --- sh/tests/hard-perm/1 | 0 sh/tests/hard-perm/2 | 0 sh/tests/hard-perm/4 | 0 sh/tests/hard-perm/5 | 0 sh/tests/hard-perm/6 | 0 sh/tests/hard-perm/7 | 0 sh/tests/hard-perm/8 | 0 sh/tests/hard-perm/9 | 0 sh/tests/hard-perm_test.sh | 16 +++++++++ sh/tests/solutions/hard-perm.sh | 1 + subjects/devops/hard-perm/README.md | 51 +++++++++++++++++++++++++++++ 11 files changed, 68 insertions(+) create mode 100644 sh/tests/hard-perm/1 create mode 100644 sh/tests/hard-perm/2 create mode 100755 sh/tests/hard-perm/4 create mode 100644 sh/tests/hard-perm/5 create mode 100644 sh/tests/hard-perm/6 create mode 100755 sh/tests/hard-perm/7 create mode 100644 sh/tests/hard-perm/8 create mode 100644 sh/tests/hard-perm/9 create mode 100755 sh/tests/hard-perm_test.sh create mode 100755 sh/tests/solutions/hard-perm.sh create mode 100644 subjects/devops/hard-perm/README.md diff --git a/sh/tests/hard-perm/1 b/sh/tests/hard-perm/1 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/2 b/sh/tests/hard-perm/2 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/4 b/sh/tests/hard-perm/4 new file mode 100755 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/5 b/sh/tests/hard-perm/5 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/6 b/sh/tests/hard-perm/6 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/7 b/sh/tests/hard-perm/7 new file mode 100755 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/8 b/sh/tests/hard-perm/8 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm/9 b/sh/tests/hard-perm/9 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/hard-perm_test.sh b/sh/tests/hard-perm_test.sh new file mode 100755 index 000000000..53f89b265 --- /dev/null +++ b/sh/tests/hard-perm_test.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' +script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) + +challenge() { + submitted=$(ls -l "$1" && bash "$script_dirS"/student/hard-perm.sh) + expected=$(ls -l "$1" && bash "$script_dirS"/solutions/hard-perm.sh) + + diff <(echo "$submitted") <(echo "$expected") +} + +challenge hard-perm/ diff --git a/sh/tests/solutions/hard-perm.sh b/sh/tests/solutions/hard-perm.sh new file mode 100755 index 000000000..c32e4a8ca --- /dev/null +++ b/sh/tests/solutions/hard-perm.sh @@ -0,0 +1 @@ +chmod 401 hard-perm/0 hard-perm/A && chmod 402 hard-perm/1 hard-perm/9 && chmod 604 hard-perm/2 hard-perm/8 && chmod 777 hard-perm/3 && chmod 510 hard-perm/4 hard-perm/7 && chmod 460 hard-perm/5 hard-perm/6 diff --git a/subjects/devops/hard-perm/README.md b/subjects/devops/hard-perm/README.md new file mode 100644 index 000000000..1a43589c7 --- /dev/null +++ b/subjects/devops/hard-perm/README.md @@ -0,0 +1,51 @@ +## hard-perm + +### Instructions + +Create a file `hard-perm.sh`, which will change the default permissions for the files and folders inside the folder `hard-perms`, to the ones bellow: + +Right now the folder looks like this: + +```console +$ ls -l hard-perm +total 12 +drwxrwxr-x 2 user user 4096 dez 13 18:10 0 +-rw-rw-r-- 1 user user 0 dez 13 18:11 1 +-rw-rw-r-- 1 user user 0 dez 13 18:11 2 +drwxrwxr-x 2 user user 4096 dez 13 18:10 3 +-rw-rw-r-- 1 user user 0 dez 13 18:11 4 +-rw-rw-r-- 1 user user 0 dez 13 18:11 5 +-rw-rw-r-- 1 user user 0 dez 13 18:11 6 +-rw-rw-r-- 1 user user 0 dez 13 18:11 7 +-rw-rw-r-- 1 user user 0 dez 13 18:11 8 +-rw-rw-r-- 1 user user 0 dez 13 18:11 9 +drwxrwxr-x 2 user user 4096 dez 13 18:10 A + +``` + +Expected output: + +```console +$ ls -l hard-perm +total 12 +dr-------x 2 user user 4096 dez 13 17:50 0 +-r------w- 1 user user 0 dez 13 17:51 1 +-rw----r-- 1 user user 0 dez 13 17:51 2 +drwxrwxrwx 2 user user 4096 dez 13 17:51 3 +-r-x--x--- 1 user user 0 dez 13 17:51 4 +-r--rw---- 1 user user 0 dez 13 17:51 5 +-r--rw---- 1 user user 0 dez 13 17:51 6 +-r-x--x--- 1 user user 0 dez 13 17:51 7 +-rw----r-- 1 user user 0 dez 13 17:51 8 +-r------w- 1 user user 0 dez 13 17:51 9 +dr-------x 2 user user 4096 dez 13 17:50 A +``` + +### Hints + +> 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)