mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-06 19:43:10 +02:00
feat: better pre install challenge
This commit is contained in:
parent
95471e8fca
commit
b18de30fd8
@ -11,17 +11,7 @@ CYAN='\033[0;36m'
|
|||||||
BOLD='\033[1m'
|
BOLD='\033[1m'
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
# Define paths for both pacman and pacman.orig
|
|
||||||
PACMAN_BIN="/usr/bin/pacman"
|
PACMAN_BIN="/usr/bin/pacman"
|
||||||
PACMAN_ORIG_BIN="/usr/bin/pacman.orig.real"
|
|
||||||
|
|
||||||
# Detect if script is being called as pacman.orig
|
|
||||||
SCRIPT_NAME=$(basename "$0")
|
|
||||||
if [[ "$SCRIPT_NAME" == "pacman.orig" ]]; then
|
|
||||||
IS_PACMAN_ORIG=true
|
|
||||||
else
|
|
||||||
IS_PACMAN_ORIG=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Function to display help
|
# Function to display help
|
||||||
function show_help() {
|
function show_help() {
|
||||||
@ -65,124 +55,86 @@ function display_operation() {
|
|||||||
# Function to check if user is trying to install specific packages that require confirmation
|
# Function to check if user is trying to install specific packages that require confirmation
|
||||||
function check_for_steam() {
|
function check_for_steam() {
|
||||||
# List of packages that require confirmation
|
# List of packages that require confirmation
|
||||||
local restricted_packages=("steam" "freetube-bin" "seamonkey-bin" "seamonkey" "google-chrome" "mirosoft-edge-stable-bin" "opera" "slimjet" "vivaldi" "yandex-browser" "min-browser-bin" "vieb-bin")
|
local restricted_packages=("steam" "freetube-bin" "seamonkey-bin" "seamonkey")
|
||||||
|
|
||||||
# Check if the command is an installation command
|
# Check if the command is an installation command
|
||||||
if [[ "$1" == "-S" || "$1" == "-Sy" || "$1" == "-Syu" || "$1" == "-Syyu" || "$1" == "-U" ]]; then
|
if [[ "$1" == "-S" || "$1" == "-Sy" || "$1" == "-Syu" || "$1" == "-Syyu" || "$1" == "-U" ]]; then
|
||||||
# Check all arguments
|
# Check all arguments
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
# Fix the comment that was accidentally merged with code
|
# Check if argument matches any restricted packageExecuting: /usr/bin/pacman.orig -U --config /etc/pacman.conf -- /home/kuhy/.cache/yay/seamonkey-bin/seamonkey-bin-2.53.20-1-x86_64.pkg.tar.zst /home/kuhy/.cache/yay/seamonkey-bin/seamonkey-bin-debug-2.53.20-1-x86_64.pkg.tar.zst
|
||||||
# Check if argument matches any restricted package
|
|
||||||
for package in "${restricted_packages[@]}"; do
|
for package in "${restricted_packages[@]}"; do
|
||||||
if [[ "$arg" == "$package" ]]; then
|
if [[ "$arg" == "$package" ]]; then
|
||||||
return 0 # Restricted package found
|
return 0 # Restricted package found
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the argument is a path containing the restricted package
|
|
||||||
if [[ "$arg" == *"$package"*".pkg.tar."* ]]; then
|
|
||||||
return 0 # Restricted package found in path
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
return 1 # No restricted package found
|
return 1 # No restricted package found
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to prompt for solving a math problem
|
# Function to prompt for solving a word unscrambling challenge
|
||||||
function prompt_for_math_solution() {
|
function prompt_for_math_solution() {
|
||||||
echo -e "${YELLOW}WARNING: You are trying to install a restricted package.${NC}"
|
echo -e "${YELLOW}WARNING: You are trying to install a restricted package.${NC}"
|
||||||
|
echo -e "${YELLOW}Challenge will begin shortly...${NC}"
|
||||||
|
|
||||||
# Define possible operations
|
# Sleep for random 5-10 seconds
|
||||||
operations=('+' '-' '*' '/')
|
sleep_duration=$((RANDOM % 10 + 10))
|
||||||
mult_div_operations=('*' '/')
|
sleep $sleep_duration
|
||||||
add_sub_operations=('+' '-')
|
|
||||||
|
|
||||||
# Set minimum requirements
|
# Define path to words.txt (in the same directory as the script)
|
||||||
min_total_operations=6
|
script_dir="$(dirname "$(readlink -f "$0")")"
|
||||||
min_mult_div=3
|
words_file="$script_dir/words.txt"
|
||||||
|
|
||||||
# Start with a random number
|
# Check if words.txt exists
|
||||||
number_of_operations=$((RANDOM % 4 + min_total_operations))
|
if [[ ! -f "$words_file" ]]; then
|
||||||
current_value=$((RANDOM % 50 + 10))
|
echo -e "${RED}Error: words.txt file not found at $words_file${NC}"
|
||||||
problem="$current_value"
|
return 1
|
||||||
|
|
||||||
# Track how many multiplication/division operations we've used
|
|
||||||
mult_div_count=0
|
|
||||||
|
|
||||||
# Build the problem with minimum required operations
|
|
||||||
for ((i=1; i<=number_of_operations; i++)); do
|
|
||||||
# If we haven't met the multiplication/division minimum and we're running out of operations
|
|
||||||
if [[ $mult_div_count -lt $min_mult_div && $(($number_of_operations - $i + 1)) -le $(($min_mult_div - $mult_div_count)) ]]; then
|
|
||||||
# Force a multiplication or division
|
|
||||||
op=${mult_div_operations[$((RANDOM % 2))]}
|
|
||||||
mult_div_count=$((mult_div_count + 1))
|
|
||||||
# If we've met minimum mult/div requirement, use any operation
|
|
||||||
elif [[ $mult_div_count -ge $min_mult_div ]]; then
|
|
||||||
op=${operations[$((RANDOM % 4))]}
|
|
||||||
# Count if we randomly selected another mult/div operation
|
|
||||||
[[ $op == "*" || $op == "/" ]] && ((mult_div_count++))
|
|
||||||
# Otherwise randomly choose a mult/div or add/sub with preference for mult/div
|
|
||||||
else
|
|
||||||
# 70% chance for mult/div until minimum is met
|
|
||||||
if [[ $((RANDOM % 10)) -lt 7 ]]; then
|
|
||||||
op=${mult_div_operations[$((RANDOM % 2))]}
|
|
||||||
mult_div_count=$((mult_div_count + 1))
|
|
||||||
else
|
|
||||||
op=${add_sub_operations[$((RANDOM % 2))]}
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
words_count=80
|
||||||
|
# Load ${words_count} random words
|
||||||
|
mapfile -t selected_words < <(shuf -n $words_count "$words_file")
|
||||||
|
|
||||||
# Generate the next operand based on the operation
|
# Convert all words to uppercase
|
||||||
case $op in
|
for i in "${!selected_words[@]}"; do
|
||||||
'+')
|
selected_words[$i]=$(echo "${selected_words[$i]}" | tr '[:lower:]' '[:upper:]')
|
||||||
next_num=$((RANDOM % 50 + 5))
|
|
||||||
;;
|
|
||||||
'-')
|
|
||||||
next_num=$((RANDOM % 50 + 5))
|
|
||||||
;;
|
|
||||||
'*')
|
|
||||||
next_num=$((RANDOM % 9 + 2)) # Smaller numbers for multiplication
|
|
||||||
;;
|
|
||||||
'/')
|
|
||||||
# For division, ensure it's clean (no remainder)
|
|
||||||
next_num=$((RANDOM % 5 + 2))
|
|
||||||
temp_value=$((next_num * (RANDOM % 10 + 1)))
|
|
||||||
current_value=$temp_value
|
|
||||||
problem="$current_value"
|
|
||||||
i=1 # Reset counter to ensure we still get the right number of operations
|
|
||||||
mult_div_count=0 # Reset the counter since we're starting over
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
problem="$problem $op $next_num"
|
|
||||||
|
|
||||||
# Update current value for next iteration
|
|
||||||
case $op in
|
|
||||||
'+') current_value=$((current_value + next_num)) ;;
|
|
||||||
'-') current_value=$((current_value - next_num)) ;;
|
|
||||||
'*') current_value=$((current_value * next_num)) ;;
|
|
||||||
'/') current_value=$((current_value / next_num)) ;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Calculate solution using bash's evaluation
|
echo -e "${CYAN}Here are ${words_count} random words. Remember them:${NC}"
|
||||||
solution=$(eval "echo \$(($problem))")
|
|
||||||
|
|
||||||
echo -e "${YELLOW}To confirm installation, please solve this math problem:${NC}"
|
# Display the words in a 5x4 grid (5 rows, 4 columns)
|
||||||
echo -e "${CYAN}$problem = ?${NC}"
|
for (( i=0; i<words_count; i++ )); do
|
||||||
|
printf "${BLUE}%-15s${NC}" "${selected_words[$i]}"
|
||||||
|
if (( (i+1) % 4 == 0 )); then
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo -e "${YELLOW}Enter your answer:${NC}"
|
# Select a random word to scramble (already in uppercase)
|
||||||
|
target_index=$((RANDOM % ${words_count}))
|
||||||
|
target_word="${selected_words[$target_index]}"
|
||||||
|
|
||||||
|
# Scramble the word
|
||||||
|
scrambled_word=$(echo "$target_word" | fold -w1 | shuf | tr -d '\n')
|
||||||
|
|
||||||
|
# Ensure scrambled word is different from original
|
||||||
|
if [[ "$scrambled_word" == "$target_word" ]]; then
|
||||||
|
# Use simple reversal as fallback
|
||||||
|
scrambled_word=$(echo "$target_word" | rev)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}One of those words has been scrambled to:${NC} ${CYAN}$scrambled_word${NC}"
|
||||||
|
echo -e "${YELLOW}Unscramble the word to proceed with installation:${NC}"
|
||||||
read -r user_input
|
read -r user_input
|
||||||
|
|
||||||
# Trim whitespaces from user input
|
# Convert user input to uppercase and trim whitespaces
|
||||||
user_input=$(echo $user_input | xargs)
|
user_input=$(echo "$user_input" | tr '[:lower:]' '[:upper:]' | xargs)
|
||||||
|
|
||||||
if [[ "$user_input" == "$solution" ]]; then
|
if [[ "$user_input" == "$target_word" ]]; then
|
||||||
echo -e "${GREEN}Correct! Proceeding with installation...${NC}"
|
echo -e "${GREEN}Correct! Proceeding with installation...${NC}"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
echo -e "${RED}Incorrect answer. Installation aborted. The correct answer was $solution.${NC}"
|
echo -e "${RED}Incorrect answer. Installation aborted. The correct word was '$target_word'.${NC}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -193,7 +145,7 @@ if [[ "$1" == "--help-wrapper" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if trying to install restricted packages
|
# Check if trying to install steam
|
||||||
if check_for_steam "$@"; then
|
if check_for_steam "$@"; then
|
||||||
prompt_for_math_solution
|
prompt_for_math_solution
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
@ -204,20 +156,14 @@ fi
|
|||||||
# Display operation
|
# Display operation
|
||||||
display_operation "$1"
|
display_operation "$1"
|
||||||
|
|
||||||
# Determine which binary to use
|
# Echo the command that's about to be executed
|
||||||
if [[ "$IS_PACMAN_ORIG" == true ]]; then
|
|
||||||
echo -e "${GREEN}Executing via pacman.orig:${NC} $PACMAN_ORIG_BIN $@"
|
|
||||||
EXEC_BIN="$PACMAN_ORIG_BIN"
|
|
||||||
else
|
|
||||||
echo -e "${GREEN}Executing:${NC} $PACMAN_BIN $@"
|
echo -e "${GREEN}Executing:${NC} $PACMAN_BIN $@"
|
||||||
EXEC_BIN="$PACMAN_BIN"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Record start time for statistics
|
# Record start time for statistics
|
||||||
start_time=$(date +%s)
|
start_time=$(date +%s)
|
||||||
|
|
||||||
# Execute the real pacman command
|
# Execute the real pacman command
|
||||||
"$EXEC_BIN" "$@"
|
"$PACMAN_BIN" "$@"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
# Record end time for statistics
|
# Record end time for statistics
|
||||||
|
|||||||
21953
scripts/words.txt
Normal file
21953
scripts/words.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user