generated from nhcarrigan/template
149 lines
3.7 KiB
Bash
Executable File
149 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
# Get all directories except hidden ones and mail
|
|
all_dirs=()
|
|
while IFS= read -r dir; do
|
|
dir_name=$(basename "$dir")
|
|
if [[ "$dir_name" != "mail" ]]; then
|
|
all_dirs+=("$dir_name")
|
|
fi
|
|
done < <(find . -maxdepth 1 -type d | grep -v "^\.$" | grep -v "^\./\." | sort)
|
|
|
|
# Arrays to track selections
|
|
selected_dirs=()
|
|
selected_status=()
|
|
|
|
# Initialize all as unselected
|
|
for i in "${!all_dirs[@]}"; do
|
|
selected_status[$i]=false
|
|
done
|
|
|
|
# Function to display menu
|
|
display_menu() {
|
|
clear
|
|
echo "==============================================="
|
|
echo " Select Directories to Sync (Space to toggle)"
|
|
echo "==============================================="
|
|
echo
|
|
|
|
for i in "${!all_dirs[@]}"; do
|
|
if [[ "${selected_status[$i]}" == "true" ]]; then
|
|
echo " [✓] ${all_dirs[$i]}"
|
|
else
|
|
echo " [ ] ${all_dirs[$i]}"
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "-----------------------------------------------"
|
|
echo " SPACE: Toggle selection | ENTER: Confirm"
|
|
echo " q: Quit without syncing"
|
|
echo "-----------------------------------------------"
|
|
}
|
|
|
|
# Interactive selection
|
|
current=0
|
|
while true; do
|
|
display_menu
|
|
|
|
# Highlight current option
|
|
tput cup $((current + 4)) 0
|
|
if [[ "${selected_status[$current]}" == "true" ]]; then
|
|
echo -e "\e[7m [✓] ${all_dirs[$current]}\e[0m"
|
|
else
|
|
echo -e "\e[7m [ ] ${all_dirs[$current]}\e[0m"
|
|
fi
|
|
|
|
# Read user input
|
|
IFS= read -r -s -n1 key
|
|
|
|
# Handle different key inputs
|
|
if [[ $key == $'\x1b' ]]; then
|
|
# Escape sequence - read more characters
|
|
read -r -s -n2 -t 0.1 rest
|
|
key="${key}${rest}"
|
|
|
|
case "$key" in
|
|
$'\x1b[A'|$'\x1bOA') # Up arrow
|
|
((current--))
|
|
if [[ $current -lt 0 ]]; then
|
|
current=$((${#all_dirs[@]} - 1))
|
|
fi
|
|
;;
|
|
$'\x1b[B'|$'\x1bOB') # Down arrow
|
|
((current++))
|
|
if [[ $current -ge ${#all_dirs[@]} ]]; then
|
|
current=0
|
|
fi
|
|
;;
|
|
esac
|
|
elif [[ $key == $'\x20' ]]; then
|
|
# Space key (hex 20)
|
|
if [[ "${selected_status[$current]}" == "true" ]]; then
|
|
selected_status[$current]=false
|
|
else
|
|
selected_status[$current]=true
|
|
fi
|
|
elif [[ $key == $'\x0a' || $key == $'\x0d' || -z "$key" ]]; then
|
|
# Enter key (newline or carriage return) or empty
|
|
break
|
|
elif [[ $key == "q" || $key == "Q" ]]; then
|
|
# Quit
|
|
echo
|
|
echo "Sync cancelled."
|
|
exit 0
|
|
fi
|
|
done
|
|
|
|
# Collect selected directories
|
|
for i in "${!all_dirs[@]}"; do
|
|
if [[ "${selected_status[$i]}" == "true" ]]; then
|
|
selected_dirs+=("${all_dirs[$i]}")
|
|
fi
|
|
done
|
|
|
|
# Clear screen and show summary
|
|
clear
|
|
echo "==============================================="
|
|
echo " Ready to Sync"
|
|
echo "==============================================="
|
|
echo
|
|
|
|
if [[ ${#selected_dirs[@]} -eq 0 ]]; then
|
|
echo "No directories selected for sync."
|
|
echo
|
|
exit 0
|
|
fi
|
|
|
|
echo "Selected directories:"
|
|
for dir in "${selected_dirs[@]}"; do
|
|
echo " • $dir"
|
|
done
|
|
|
|
echo
|
|
read -p "Proceed with sync? (y/N) " -n 1 -r
|
|
echo
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Sync cancelled."
|
|
exit 0
|
|
fi
|
|
|
|
echo
|
|
echo "Starting sync..."
|
|
echo "==============================================="
|
|
|
|
# Perform sync
|
|
for dir in "${selected_dirs[@]}"; do
|
|
echo
|
|
echo "Syncing $dir..."
|
|
rsync -av "$dir" prod:/home/naomi
|
|
echo "✓ Synced $dir"
|
|
done
|
|
|
|
echo
|
|
echo "==============================================="
|
|
echo "Sync completed!"
|
|
echo
|
|
echo "Note: mail/index.html must be manually synced to"
|
|
echo "mail:/home/user-data/www/default by a user with sudo access." |