mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 15:03:01 +02:00
feat: make the installation challenge harder
This commit is contained in:
parent
bcf59dc9dc
commit
84346b8ff9
29
scripts/convert_words.sh
Executable file
29
scripts/convert_words.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if input and output files are provided
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: $0 input_file.txt output_file.txt"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the input file exists
|
||||
if [ ! -f "$1" ]; then
|
||||
echo "Error: File '$1' not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Store output file name
|
||||
output_file="$2"
|
||||
|
||||
# Clear output file at the beginning
|
||||
> "$output_file"
|
||||
|
||||
# Process file using a pipeline of specialized tools
|
||||
# 1. tr - remove non-alphabetic chars except newlines
|
||||
# 2. tr - convert to uppercase
|
||||
# 3. grep - filter by length (5-8 characters)
|
||||
# 4. sort - sort the words alphabetically
|
||||
# 5. uniq - remove duplicates
|
||||
tr -cd 'a-zA-Z\n' < "$1" | tr '[:lower:]' '[:upper:]' | grep -x '.\{5,8\}' | sort | uniq > "$output_file"
|
||||
|
||||
echo "Processing complete. Results saved to '$output_file'"
|
||||
@ -57,55 +57,4 @@ sed -i 's|PACMAN_BIN="\/usr\/bin\/pacman"|PACMAN_BIN="\/usr\/bin\/pacman.orig"|g
|
||||
echo -e "${BLUE}Creating symbolic link...${NC}"
|
||||
ln -sf "$WRAPPER_DEST" /usr/bin/pacman
|
||||
echo -e "${GREEN}Installation complete!${NC}"
|
||||
echo -e "Pacman is now wrapped. The original pacman is available at ${CYAN}/usr/bin/pacman.orig${NC}"
|
||||
|
||||
# Create uninstaller
|
||||
echo -e "${BLUE}Creating uninstaller...${NC}"
|
||||
cat > "${INSTALL_DIR}/uninstall_pacman_wrapper.sh" << EOF
|
||||
#!/bin/bash
|
||||
# Uninstall script for pacman wrapper
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
if [ "\$EUID" -ne 0 ]; then
|
||||
echo -e "\${RED}Please run as root\${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\${BLUE}Uninstalling pacman wrapper...\${NC}"
|
||||
|
||||
# Remove alias if exists
|
||||
if [ -f /etc/profile.d/pacman-wrapper.sh ]; then
|
||||
echo -e "\${YELLOW}Removing alias file...\${NC}"
|
||||
rm /etc/profile.d/pacman-wrapper.sh
|
||||
fi
|
||||
|
||||
# Restore original pacman if needed
|
||||
if [ -L /usr/bin/pacman ] && [ -f /usr/bin/pacman.orig ]; then
|
||||
echo -e "\${YELLOW}Restoring original pacman...\${NC}"
|
||||
rm /usr/bin/pacman
|
||||
cp /usr/bin/pacman.orig /usr/bin/pacman
|
||||
fi
|
||||
|
||||
# Remove wrapper
|
||||
if [ -f "${WRAPPER_DEST}" ]; then
|
||||
echo -e "\${YELLOW}Removing wrapper script...\${NC}"
|
||||
rm "${WRAPPER_DEST}"
|
||||
fi
|
||||
|
||||
echo -e "\${GREEN}Pacman wrapper has been uninstalled.\${NC}"
|
||||
echo -e "\${YELLOW}Note:\${NC} You may need to log out and log back in for changes to take effect."
|
||||
|
||||
# Self-destruct
|
||||
rm "\$0"
|
||||
EOF
|
||||
|
||||
chmod +x "${INSTALL_DIR}/uninstall_pacman_wrapper.sh"
|
||||
|
||||
echo -e "${CYAN}To uninstall, run: ${BOLD}sudo ${INSTALL_DIR}/uninstall_pacman_wrapper.sh${NC}"
|
||||
echo -e "${GREEN}Thank you for installing the pacman wrapper!${NC}"
|
||||
echo -e "Pacman is now wrapped. The original pacman is available at ${CYAN}/usr/bin/pacman.orig${NC}"
|
||||
@ -77,7 +77,7 @@ function prompt_for_math_solution() {
|
||||
echo -e "${YELLOW}WARNING: You are trying to install a restricted package.${NC}"
|
||||
echo -e "${YELLOW}Challenge will begin shortly...${NC}"
|
||||
|
||||
# Sleep for random 5-10 seconds
|
||||
# Sleep for random 20-40 seconds
|
||||
sleep_duration=$((RANDOM % 20 + 20))
|
||||
sleep $sleep_duration
|
||||
|
||||
@ -90,9 +90,20 @@ function prompt_for_math_solution() {
|
||||
echo -e "${RED}Error: words.txt file not found at $words_file${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Filter words by length (5-8 characters) and load random words
|
||||
words_count=160
|
||||
# Load ${words_count} random words
|
||||
mapfile -t selected_words < <(shuf -n $words_count "$words_file")
|
||||
mapfile -t selected_words < <(grep -E '^[a-zA-Z]{5,8}$' "$words_file" | shuf -n $words_count)
|
||||
|
||||
# If we couldn't get enough words of the right length
|
||||
if [[ ${#selected_words[@]} -lt $words_count ]]; then
|
||||
echo -e "${RED}Warning: Could only find ${#selected_words[@]} words of the required length.${NC}"
|
||||
words_count=${#selected_words[@]}
|
||||
if [[ $words_count -eq 0 ]]; then
|
||||
echo -e "${RED}Error: No words of length 5-8 found in $words_file${NC}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Convert all words to uppercase
|
||||
for i in "${!selected_words[@]}"; do
|
||||
@ -101,7 +112,7 @@ function prompt_for_math_solution() {
|
||||
|
||||
echo -e "${CYAN}Here are ${words_count} random words. Remember them:${NC}"
|
||||
|
||||
# Display the words in a 5x4 grid (5 rows, 4 columns)
|
||||
# Display the words in a grid (4 columns)
|
||||
for (( i=0; i<words_count; i++ )); do
|
||||
printf "${BLUE}%-15s${NC}" "${selected_words[$i]}"
|
||||
if (( (i+1) % 4 == 0 )); then
|
||||
|
||||
195791
scripts/words.txt
195791
scripts/words.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user