From 7397e295e8f4cbc59f117b14d7e8bb3f724065d5 Mon Sep 17 00:00:00 2001 From: alexpolo1 Date: Tue, 7 Jan 2025 21:32:02 +0100 Subject: [PATCH] test2 --- assets/level.txt | 1 + assets/session.log | 33 +++++++++++++++++++++++++++++++ assets/total_time.txt | 1 + assets/xp.txt | 1 + rhel_learning.sh | 44 ++++++++---------------------------------- timer_and_questions.sh | 44 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 timer_and_questions.sh diff --git a/assets/level.txt b/assets/level.txt index e69de29..8ddbb35 100644 --- a/assets/level.txt +++ b/assets/level.txt @@ -0,0 +1 @@ +/home/alex/git/rhel_learning/assets/level.txt diff --git a/assets/session.log b/assets/session.log index 0a8dc1c..b47b887 100644 --- a/assets/session.log +++ b/assets/session.log @@ -1,3 +1,36 @@ Session started: 2025-01-04 19:37:40 Session started: 2025-01-07 19:20:39 Session started: 2025-01-07 19:21:53 +Session started: 2025-01-07 19:24:51 +Session started: 2025-01-07 19:28:28 +Session started: 2025-01-07 19:28:44 +Session started: 2025-01-07 19:29:50 +Session started: 2025-01-07 20:02:03 +How do you analyze CPU usage?|Wrong +XP and level updated: 10 XP, Level 1 +Session ended: 2025-01-07 20:02:06, Duration: 20 minutes +Session started: 2025-01-07 20:03:24 +How do you view swap usage?|Wrong +XP and level updated: 20 XP, Level 1 +Session ended: 2025-01-07 20:03:26, Duration: 20 minutes +Session started: 2025-01-07 20:08:22 +How do you reload firewalld rules?|Wrong +XP and level updated: 30 XP, Level 1 +Session ended: 2025-01-07 20:08:24, Duration: 20 minutes +Session started: 2025-01-07 20:09:27 +How do you change file ownership?|Wrong +XP and level updated: 40 XP, Level /home/alex/git/rhel_learning/assets/level.txt +Session ended: 2025-01-07 20:09:29, Duration: 20 minutes +Session started: 2025-01-07 20:10:54 +Which command lists all active SELinux booleans?|Wrong +XP and level updated: 50 XP, Level /home/alex/git/rhel_learning/assets/level.txt +Session ended: 2025-01-07 20:10:56, Duration: 20 minutes +Session started: 2025-01-07 20:14:10 +XP and level updated: 60 XP, Level /home/alex/git/rhel_learning/assets/level.txt +Session ended: 2025-01-07 20:14:12, Duration: 20 minutes +Session started: 2025-01-07 20:15:35 +XP and level updated: 70 XP, Level /home/alex/git/rhel_learning/assets/level.txt +Session ended: 2025-01-07 20:15:38, Duration: 20 minutes +Session started: 2025-01-07 20:15:48 +XP and level updated: 80 XP, Level /home/alex/git/rhel_learning/assets/level.txt +Session ended: 2025-01-07 20:15:51, Duration: 20 minutes diff --git a/assets/total_time.txt b/assets/total_time.txt index e69de29..3af99ee 100644 --- a/assets/total_time.txt +++ b/assets/total_time.txt @@ -0,0 +1 @@ +180 diff --git a/assets/xp.txt b/assets/xp.txt index e69de29..d15a2cc 100644 --- a/assets/xp.txt +++ b/assets/xp.txt @@ -0,0 +1 @@ +80 diff --git a/rhel_learning.sh b/rhel_learning.sh index d4db1fb..4af3002 100755 --- a/rhel_learning.sh +++ b/rhel_learning.sh @@ -67,51 +67,27 @@ kill_steam() { steam_pids=$(ps aux | grep steam | grep -v grep | awk '{print $2}') if [ -n "$steam_pids" ]; then echo "Killing Steam processes..." - sudo kill -9 $steam_pids || echo "Failed to kill Steam processes" + sudo /bin/kill -9 $steam_pids || echo "Failed to kill Steam processes" fi sleep 5 # Check every 5 seconds done } -# Function to display a random question -ask_random_question() { - mapfile -t questions < "$QUESTIONS_FILE" - local random_index=$((RANDOM % ${#questions[@]})) - IFS='|' read -r question opt1 opt2 opt3 correct <<<"${questions[random_index]}" - echo "$question" - echo "1. $opt1" - echo "2. $opt2" - echo "3. $opt3" - local answer - read -p "Choose an answer (1-3): " answer - if [ "$answer" -eq "$correct" ]; then - echo "Correct answer!" - echo "$question|Correct" >> "$SESSION_LOG" - else - echo "Wrong answer. The correct option was: $correct" - echo "$question|Wrong" >> "$SESSION_LOG" - fi -} - # Timer function with window focus show_timer() { - local seconds=$((TIMER_MINUTES * 60)) echo "The session will last $TIMER_MINUTES minutes." - # Open the URL in a private Firefox window + # Open the URL in Chromium if [ -n "$DISPLAY" ]; then - firefox --private-window "$URL" >/dev/null 2>&1 & + chromium "$URL" >/dev/null 2>&1 & sleep 2 # Allow the browser to open wmctrl -r ":ACTIVE:" -b add,above else echo "No graphical environment detected. Skipping browser opening." fi - for ((i = 1; i <= seconds; i++)); do - echo -ne "Time remaining: $((seconds - i)) seconds\r" - sleep 1 - done - echo -e "\nSession complete!" + # Open a new terminal window and run the secondary script + gnome-terminal -- bash -c "$SCRIPT_DIR/timer_and_questions.sh $TIMER_MINUTES $QUESTIONS_FILE $SESSION_LOG; exec bash" # Add session time to total local total_time=$(cat "$TOTAL_TIME_FILE") @@ -119,7 +95,6 @@ show_timer() { echo "$total_time" > "$TOTAL_TIME_FILE" } - # XP and level-up system add_xp() { local xp=$(cat "$XP_FILE") @@ -155,15 +130,12 @@ STEAM_KILL_PID=$! echo "Starting RHEL Learning Session..." show_timer +# Add XP +add_xp + # Stop killing Steam processes kill $STEAM_KILL_PID # Log session end log_session "end" -# Ask a question -ask_random_question - -# Add XP -add_xp - diff --git a/timer_and_questions.sh b/timer_and_questions.sh new file mode 100644 index 0000000..f8d13ae --- /dev/null +++ b/timer_and_questions.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +TIMER_MINUTES=$1 +QUESTIONS_FILE=$2 +SESSION_LOG=$3 + +# Timer function +run_timer() { + local seconds=$((TIMER_MINUTES * 60)) + for ((i = 1; i <= seconds; i++)); do + echo -ne "Time remaining: $((seconds - i)) seconds\r" + sleep 1 + done + echo -e "\nSession complete!" +} + +# Function to display a random question +ask_random_question() { + mapfile -t questions < "$QUESTIONS_FILE" + local random_index=$((RANDOM % ${#questions[@]})) + IFS='|' read -r question opt1 opt2 opt3 correct <<<"${questions[random_index]}" + echo "$question" + echo "1. $opt1" + echo "2. $opt2" + echo "3. $opt3" + local answer + read -p "Choose an answer (1-3): " answer + if [ "$answer" -eq "$correct" ]; then + echo "Correct answer!" + echo "$question|Correct" >> "$SESSION_LOG" + else + echo "Wrong answer. The correct option was: $correct" + echo "$question|Wrong" >> "$SESSION_LOG" + fi +} + +# Run the timer +run_timer + +# Ask a random question +ask_random_question + +# Wait for user input to close the terminal +read -p "Press Enter to close..."