This commit is contained in:
2025-01-07 21:32:02 +01:00
parent e167151785
commit 7397e295e8
6 changed files with 88 additions and 36 deletions
+1
View File
@@ -0,0 +1 @@
/home/alex/git/rhel_learning/assets/level.txt
+33
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
180
+1
View File
@@ -0,0 +1 @@
80
+8 -36
View File
@@ -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
+44
View File
@@ -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..."