Add RHEL Learning script and assets
This commit is contained in:
0
assets/level.txt
Normal file
0
assets/level.txt
Normal file
30
assets/questions.txt
Normal file
30
assets/questions.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
Which command is used to temporarily change a SELinux boolean?|semanage boolean|setsebool|getsebool|2
|
||||
How do you enable a systemd service at boot?|systemctl enable|systemctl start|systemctl active|1
|
||||
Which command lists all active SELinux booleans?|getsebool -a|semanage boolean -l|setsebool|2
|
||||
How do you force a container to stop?|podman kill|podman stop|podman rm|1
|
||||
Which systemctl command switches to another target?|systemctl isolate|systemctl switch|systemctl target|1
|
||||
How do you check the status of a SELinux boolean?|semanage boolean|getsebool|setsebool -P|2
|
||||
How do you create a new partition with parted?|parted /dev/vdb mkpart|mkfs.ext4 /dev/vdb|fdisk /dev/vdb|1
|
||||
Which command lists all configured SELinux ports?|semanage port -l|getsebool -a|setsebool|1
|
||||
Which command lists all systemd targets?|systemctl list-units --type=target --all|systemctl list-targets|systemctl list-active-targets|1
|
||||
How do you persistently change a SELinux boolean?|setsebool -P|getsebool -P|semanage boolean -P|1
|
||||
Which command shows the partition table?|fdisk -l|parted print|lsblk|1
|
||||
How do you restart a systemd service?|systemctl restart|systemctl reload|service restart|1
|
||||
Which command shows all running systemd services?|systemctl list-units --type=service|systemctl status --all|systemctl active-services|1
|
||||
How do you schedule a one-time job with cron?|at|crontab -e|cron add-job|1
|
||||
How do you list installed packages?|rpm -qa|yum list installed|dnf list installed|1
|
||||
How do you add a new user?|useradd|adduser|usermod|1
|
||||
How do you change file ownership?|chown user:group file|chmod user file|ls -l file|1
|
||||
Which command shows disk usage of a directory?|du -sh /dir|df -h /dir|ls -lh /dir|1
|
||||
How do you create a new logical volume?|lvcreate -L 10G -n volume group|vgcreate -L 10G|lvextend -L +10G volume|1
|
||||
How do you deactivate a user?|passwd -l user|usermod -L user|userdel user|2
|
||||
How do you view all available network interfaces?|ip addr|ifconfig|netstat -i|1
|
||||
How do you display the system uptime?|uptime|top|vmstat|1
|
||||
How do you view swap usage?|free -h|swapon -s|cat /proc/swaps|1
|
||||
How do you reload firewalld rules?|firewall-cmd --reload|iptables reload|firewallctl restart|1
|
||||
How do you list kernel modules?|lsmod|modprobe -l|dmesg|1
|
||||
How do you analyze CPU usage?|top|htop|vmstat|1
|
||||
Which command lists active TCP connections?|netstat -tulpn|ss -tulpn|lsof -i|1
|
||||
How do you stop a systemd service?|systemctl stop|systemctl disable|systemctl restart|1
|
||||
How do you check the DNS cache?|systemd-resolve --statistics|systemctl dns|dns cache|1
|
||||
|
||||
1
assets/session.log
Normal file
1
assets/session.log
Normal file
@@ -0,0 +1 @@
|
||||
Session started: 2025-01-04 19:37:40
|
||||
0
assets/total_time.txt
Normal file
0
assets/total_time.txt
Normal file
0
assets/xp.txt
Normal file
0
assets/xp.txt
Normal file
160
rhel_learning.sh
Executable file
160
rhel_learning.sh
Executable file
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables
|
||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
||||
ASSETS_DIR="$SCRIPT_DIR/assets"
|
||||
XP_FILE="$ASSETS_DIR/xp.txt"
|
||||
LEVEL_FILE="$ASSETS_DIR/level.txt"
|
||||
SESSION_LOG="$ASSETS_DIR/session.log"
|
||||
QUESTIONS_FILE="$ASSETS_DIR/questions.txt"
|
||||
TOTAL_TIME_FILE="$ASSETS_DIR/total_time.txt"
|
||||
URL="https://rol.redhat.com"
|
||||
TIMER_MINUTES=20
|
||||
|
||||
# Ensure assets directory and files exist
|
||||
initialize_assets() {
|
||||
if [ ! -d "$ASSETS_DIR" ]; then
|
||||
echo "Assets directory not found: $ASSETS_DIR"
|
||||
echo "Please create the 'assets' folder and include the required files:"
|
||||
echo "- questions.txt: Contains the questions"
|
||||
echo "- xp.txt (optional): Tracks XP, default 0"
|
||||
echo "- level.txt (optional): Tracks Level, default 1"
|
||||
echo "- total_time.txt (optional): Tracks total session time, default 0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check required files
|
||||
[ ! -f "$XP_FILE" ] && echo "0" > "$XP_FILE"
|
||||
[ ! -f "$LEVEL_FILE" ] && echo "1" > "$LEVEL_FILE"
|
||||
[ ! -f "$SESSION_LOG" ] && touch "$SESSION_LOG"
|
||||
[ ! -f "$TOTAL_TIME_FILE" ] && echo "0" > "$TOTAL_TIME_FILE"
|
||||
if [ ! -f "$QUESTIONS_FILE" ]; then
|
||||
echo "Questions file not found: $QUESTIONS_FILE"
|
||||
echo "Please create 'questions.txt' in the 'assets' folder."
|
||||
exit 1
|
||||
fi
|
||||
echo "Assets initialized in $ASSETS_DIR"
|
||||
}
|
||||
|
||||
# Log session start and end
|
||||
log_session() {
|
||||
local action=$1
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
if [ "$action" == "start" ]; then
|
||||
echo "Session started: $timestamp" >> "$SESSION_LOG"
|
||||
elif [ "$action" == "end" ]; then
|
||||
echo "Session ended: $timestamp, Duration: $TIMER_MINUTES minutes" >> "$SESSION_LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
# Display session summary
|
||||
display_summary() {
|
||||
local total_time=$(cat "$TOTAL_TIME_FILE")
|
||||
local xp=$(cat "$XP_FILE")
|
||||
local level=$(cat "$LEVEL_FILE")
|
||||
local hours=$((total_time / 60))
|
||||
local minutes=$((total_time % 60))
|
||||
echo "Welcome to the RHEL Learning Script!"
|
||||
echo "Total session time: $hours hours and $minutes minutes."
|
||||
echo "Current Level: $level"
|
||||
echo "Current XP: $xp"
|
||||
echo
|
||||
}
|
||||
|
||||
# Function to kill Steam processes
|
||||
kill_steam() {
|
||||
while true; do
|
||||
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
|
||||
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."
|
||||
xdg-open "$URL" >/dev/null 2>&1 &
|
||||
sleep 2 # Allow the browser to open
|
||||
|
||||
# Keep the browser and terminal on top using wmctrl
|
||||
wmctrl -r ":ACTIVE:" -b add,above
|
||||
for ((i = 1; i <= seconds; i++)); do
|
||||
echo -ne "Time remaining: $((seconds - i)) seconds\r"
|
||||
sleep 1
|
||||
done
|
||||
echo -e "\nSession complete!"
|
||||
|
||||
# Add session time to total
|
||||
local total_time=$(cat "$TOTAL_TIME_FILE")
|
||||
total_time=$((total_time + TIMER_MINUTES))
|
||||
echo "$total_time" > "$TOTAL_TIME_FILE"
|
||||
}
|
||||
|
||||
# XP and level-up system
|
||||
add_xp() {
|
||||
local xp=$(cat "$XP_FILE")
|
||||
local level=$(cat "$LEVEL_FILE")
|
||||
local new_xp=$((xp + 10))
|
||||
if ((new_xp >= level * 100)); then
|
||||
level=$((level + 1))
|
||||
echo "LEVEL UP! You are now Level $level!"
|
||||
new_xp=$((new_xp - (level - 1) * 100))
|
||||
fi
|
||||
echo "$new_xp" > "$XP_FILE"
|
||||
echo "$level" > "$LEVEL_FILE"
|
||||
echo "XP and level updated: $new_xp XP, Level $level" >> "$SESSION_LOG"
|
||||
}
|
||||
|
||||
# Initialize assets
|
||||
initialize_assets
|
||||
|
||||
# Log session start
|
||||
log_session "start"
|
||||
|
||||
# Display session summary
|
||||
display_summary
|
||||
|
||||
# Start killing Steam processes in the background
|
||||
kill_steam &
|
||||
STEAM_KILL_PID=$!
|
||||
|
||||
# Start session
|
||||
echo "Starting RHEL Learning Session..."
|
||||
show_timer
|
||||
|
||||
# Stop killing Steam processes
|
||||
kill $STEAM_KILL_PID
|
||||
|
||||
# Log session end
|
||||
log_session "end"
|
||||
|
||||
# Ask a question
|
||||
ask_random_question
|
||||
|
||||
# Add XP
|
||||
add_xp
|
||||
|
||||
Reference in New Issue
Block a user