From f1f5eb155d2b48994d636c37137e9da11dbe9a52 Mon Sep 17 00:00:00 2001
From: Florent Gluck <florent.gluck@hesge.ch>
Date: Wed, 16 Apr 2025 12:14:40 +0200
Subject: [PATCH] Added serie1 correction

---
 .../03-Scripting/exercices/correction/convimg | 23 +++++++++++++++++++
 .../03-Scripting/exercices/correction/sigproc | 10 ++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 Cours/03-Scripting/exercices/correction/convimg
 create mode 100644 Cours/03-Scripting/exercices/correction/sigproc

diff --git a/Cours/03-Scripting/exercices/correction/convimg b/Cours/03-Scripting/exercices/correction/convimg
new file mode 100644
index 0000000..67e1770
--- /dev/null
+++ b/Cours/03-Scripting/exercices/correction/convimg
@@ -0,0 +1,23 @@
+#/bin/bash
+
+THUMB_SIZE=64x64
+THUMB_EXT=png
+
+if [ $# -ne 2 ]; then
+    name=$(basename $0)
+    echo "Usage: $name <input dir> <output dir>" >&2
+    exit 1
+fi
+
+function filetype {
+    file --mime-type "$1" | cut -d':' -f2 | cut -d'/' -f1 | tr -d ' '
+    # alternative plus simple:
+    #file --mime-type "$1" | cut -d' ' -f2 | cut -d'/' -f1
+}
+
+for f in "$1"/*; do
+    if [ $(filetype "$f") == "image" ]; then
+        basefile=$(basename "$f")
+        convert -thumbnail $THUMB_SIZE "$f" "$2/$basefile.$THUMB_EXT"
+    fi
+done
diff --git a/Cours/03-Scripting/exercices/correction/sigproc b/Cours/03-Scripting/exercices/correction/sigproc
new file mode 100644
index 0000000..1966298
--- /dev/null
+++ b/Cours/03-Scripting/exercices/correction/sigproc
@@ -0,0 +1,10 @@
+#!/bin/bash
+if [ "$#" -ne 2 ]; then
+    name=$(basename $0)
+    echo "Usage: $name <utilisateur> <signal>" >&2
+else
+    # tail +2 = affiche à partir de la 2ème ligne de l'entrée
+    kill -$2 $(ps -o pid -u "$1" | tail -n +2)
+    # Alternative:
+    #kill -$2 $(ps -o pid= -u "$1")
+fi
-- 
GitLab