Remove bashisms

This commit is contained in:
Chris Titus 2024-09-18 12:53:47 -05:00
parent 3f6209e7f6
commit 60d4d4b380
6 changed files with 68 additions and 54 deletions

View File

@ -5,6 +5,7 @@
RC='\033[0m' RC='\033[0m'
RED='\033[31m' RED='\033[31m'
YELLOW='\033[33m' YELLOW='\033[33m'
CYAN='\033[36m'
GREEN='\033[32m' GREEN='\033[32m'
command_exists() { command_exists() {

View File

@ -68,8 +68,8 @@ setup_samba() {
if [ -f "$SAMBA_CONFIG" ]; then if [ -f "$SAMBA_CONFIG" ]; then
printf "%b\n" "${YELLOW}Samba configuration file already exists in $SAMBA_CONFIG.${RC}" printf "%b\n" "${YELLOW}Samba configuration file already exists in $SAMBA_CONFIG.${RC}"
echo "Do you want to modify the existing Samba configuration? (yes/no): " printf "Do you want to modify the existing Samba configuration? (yes/no): "
read MODIFY_SAMBA read -r MODIFY_SAMBA
if [ "$MODIFY_SAMBA" = "yes" ]; then if [ "$MODIFY_SAMBA" = "yes" ]; then
"$ESCALATION_TOOL" "$EDITOR" "$SAMBA_CONFIG" "$ESCALATION_TOOL" "$EDITOR" "$SAMBA_CONFIG"
fi fi
@ -77,7 +77,7 @@ setup_samba() {
printf "%b\n" "${YELLOW}No existing Samba configuration found. Setting up a new one...${RC}" printf "%b\n" "${YELLOW}No existing Samba configuration found. Setting up a new one...${RC}"
# Prompt user for shared directory path # Prompt user for shared directory path
echo "Enter the path for the Samba share (default: /srv/samba/share): " printf "Enter the path for the Samba share (default: /srv/samba/share): "
read -r SHARED_DIR read -r SHARED_DIR
SHARED_DIR=${SHARED_DIR:-/srv/samba/share} SHARED_DIR=${SHARED_DIR:-/srv/samba/share}
@ -157,19 +157,19 @@ configure_firewall() {
} }
setup_ssh_samba(){ setup_ssh_samba(){
echo "Samba and SSH Setup Script" printf "Samba and SSH Setup Script\n"
echo "----------------------------" printf "----------------------------\n"
clear clear
# Display menu # Display menu
echo "Select an option:" printf "Select an option:\n"
echo "1. Setup SSH" printf "1. Setup SSH\n"
echo "2. Setup Samba" printf "2. Setup Samba\n"
echo "3. Configure Firewall" printf "3. Configure Firewall\n"
echo "4. Setup All" printf "4. Setup All\n"
echo "5. Exit" printf "5. Exit\n"
echo "Enter your choice [1-5]: " printf "Enter your choice [1-5]: "
read CHOICE read CHOICE
case "$CHOICE" in case "$CHOICE" in

View File

@ -52,9 +52,9 @@ fetch_arch_older_isos() {
COUNTER=$((COUNTER + 1)) COUNTER=$((COUNTER + 1))
done done
echo "" # New line after the last row printf "\n" # New line after the last row
printf "Select an Arch Linux version (1-%d): " "$((COUNTER - 1))"
read -p "Select an Arch Linux version (1-$((COUNTER - 1))): " ARCH_OPTION read -r ARCH_OPTION
ARCH_DIR=$(echo "$ARCH_VERSIONS" | sed -n "${ARCH_OPTION}p") ARCH_DIR=$(echo "$ARCH_VERSIONS" | sed -n "${ARCH_OPTION}p")
ARCH_URL="${ARCH_BASE_URL}${ARCH_DIR}/archlinux-${ARCH_DIR}-x86_64.iso" ARCH_URL="${ARCH_BASE_URL}${ARCH_DIR}/archlinux-${ARCH_DIR}-x86_64.iso"
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}" printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
@ -70,17 +70,19 @@ fetch_debian_latest_iso() {
# Function to ask whether to use local or online ISO # Function to ask whether to use local or online ISO
choose_iso_source() { choose_iso_source() {
printf "%b\n" "${YELLOW} Do you want to use a local ISO or download online? ${RC}" printf "%b\n" "${YELLOW} Do you want to use a local ISO or download online? ${RC}"
echo "1) Download online" printf "1) Download online\n"
echo "2) Use local ISO" printf "2) Use local ISO\n"
echo "" printf "\n"
read -p "Select option (1-2): " ISO_SOURCE_OPTION printf "Select option (1-2): "
read -r ISO_SOURCE_OPTION
case $ISO_SOURCE_OPTION in case $ISO_SOURCE_OPTION in
1) 1)
fetch_iso_urls # Call the function to fetch online ISO URLs fetch_iso_urls # Call the function to fetch online ISO URLs
;; ;;
2) 2)
read -p "Enter the path to the already downloaded ISO file: " ISO_PATH printf "Enter the path to the already downloaded ISO file: "
read -r ISO_PATH
if [ ! -f "$ISO_PATH" ]; then if [ ! -f "$ISO_PATH" ]; then
printf "%b\n" "${RED} ISO file not found: $ISO_PATH ${RC}" printf "%b\n" "${RED} ISO file not found: $ISO_PATH ${RC}"
exit 1 exit 1

View File

@ -79,8 +79,9 @@ get_unique_resolutions() {
# Function to prompt for confirmation # Function to prompt for confirmation
confirm_action() { confirm_action() {
action="$1" action="$1"
echo "$action" printf "%b\n" "${CYAN}$action${RC}"
read -p "Are you sure? (y/n): " confirm printf "%b" "${CYAN}Are you sure? (y/n): ${RC}"
read -r confirm
if echo "$confirm" | grep -qE '^[Yy]$'; then if echo "$confirm" | grep -qE '^[Yy]$'; then
return 0 return 0
else else

View File

@ -75,7 +75,8 @@ apply_or_remove_auto_cpufreq() {
printf "%b\n" "${YELLOW}Do you want to apply the auto-cpufreq tweak or remove it?${RC}" printf "%b\n" "${YELLOW}Do you want to apply the auto-cpufreq tweak or remove it?${RC}"
printf "%b\n" "${YELLOW}1) Apply tweak${RC}" printf "%b\n" "${YELLOW}1) Apply tweak${RC}"
printf "%b\n" "${YELLOW}2) Remove tweak${RC}" printf "%b\n" "${YELLOW}2) Remove tweak${RC}"
read -rp "Enter your choice [1/2]: " choice printf "%b" "Enter your choice [1/2]: "
read -r choice
case $choice in case $choice in
1) 1)

View File

@ -24,34 +24,36 @@ install_timeshift() {
# Function to display the menu # Function to display the menu
display_menu() { display_menu() {
clear clear
echo "Timeshift CLI Automation" printf "%b\n" "${CYAN}Timeshift CLI Automation${RC}"
echo "-------------------------" printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
echo "1) List Snapshots" printf "%b\n" "${CYAN}1) List Snapshots${RC}"
echo "2) List Devices" printf "%b\n" "${CYAN}2) List Devices${RC}"
echo "3) Create Snapshot" printf "%b\n" "${CYAN}3) Create Snapshot${RC}"
echo "4) Restore Snapshot" printf "%b\n" "${CYAN}4) Restore Snapshot${RC}"
echo "5) Delete Snapshot" printf "%b\n" "${CYAN}5) Delete Snapshot${RC}"
echo "6) Delete All Snapshots" printf "%b\n" "${CYAN}6) Delete All Snapshots${RC}"
echo "7) Exit" printf "%b\n" "${CYAN}7) Exit${RC}"
echo "" printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
} }
# Function to list snapshots # Function to list snapshots
list_snapshots() { list_snapshots() {
echo "Listing snapshots..." printf "%b\n" "${CYAN}Listing snapshots...${RC}"
$ESCALATION_TOOL timeshift --list-snapshots $ESCALATION_TOOL timeshift --list-snapshots
} }
# Function to list devices # Function to list devices
list_devices() { list_devices() {
echo "Listing available devices..." printf "%b\n" "${CYAN}Listing available devices...${RC}"
$ESCALATION_TOOL timeshift --list-devices $ESCALATION_TOOL timeshift --list-devices
} }
# Function to create a new snapshot # Function to create a new snapshot
create_snapshot() { create_snapshot() {
read -p "Enter a comment for the snapshot (optional): " COMMENT printf "%b" "${CYAN}Enter a comment for the snapshot (optional): ${RC}"
read -p "Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): " TAG read -r COMMENT
printf "%b" "${CYAN}Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): ${RC}"
read -r TAG
if [ -z "$COMMENT" ] && [ -z "$TAG" ]; then if [ -z "$COMMENT" ] && [ -z "$TAG" ]; then
echo "Creating snapshot with no comment or tag..." echo "Creating snapshot with no comment or tag..."
@ -75,21 +77,25 @@ create_snapshot() {
restore_snapshot() { restore_snapshot() {
list_snapshots list_snapshots
read -p "Enter the snapshot name you want to restore: " SNAPSHOT printf "%b" "${CYAN}Enter the snapshot name you want to restore: ${RC}"
read -p "Enter the target device (e.g., /dev/sda1): " TARGET_DEVICE read -r SNAPSHOT
read -p "Do you want to skip GRUB reinstall? (yes/no): " SKIP_GRUB printf "%b" "${CYAN}Enter the target device (e.g., /dev/sda1): ${RC}"
read -r TARGET_DEVICE
printf "%b" "${CYAN}Do you want to skip GRUB reinstall? (yes/no): ${RC}"
read -r SKIP_GRUB
if [ "$SKIP_GRUB" = "yes" ]; then if [ "$SKIP_GRUB" = "yes" ]; then
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --skip-grub --yes $ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --skip-grub --yes
else else
read -p "Enter GRUB device (e.g., /dev/sda): " GRUB_DEVICE printf "%b" "${CYAN}Enter GRUB device (e.g., /dev/sda): ${RC}"
read -r GRUB_DEVICE
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --grub-device "$GRUB_DEVICE" --yes $ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --grub-device "$GRUB_DEVICE" --yes
fi fi
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Snapshot restored successfully." printf "%b\n" "${GREEN}Snapshot restored successfully.${RC}"
else else
echo "Snapshot restore failed." printf "%b\n" "${RED}Snapshot restore failed.${RC}"
fi fi
} }
@ -97,22 +103,24 @@ restore_snapshot() {
delete_snapshot() { delete_snapshot() {
list_snapshots list_snapshots
read -p "Enter the snapshot name you want to delete: " SNAPSHOT printf "%b" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
read -r SNAPSHOT
echo "Deleting snapshot $SNAPSHOT..." printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
$ESCALATION_TOOL timeshift --delete --snapshot "$SNAPSHOT" --yes $ESCALATION_TOOL timeshift --delete --snapshot "$SNAPSHOT" --yes
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Snapshot deleted successfully." printf "%b\n" "${GREEN}Snapshot deleted successfully.${RC}"
else else
echo "Snapshot deletion failed." printf "%b\n" "${RED}Snapshot deletion failed.${RC}"
fi fi
} }
# Function to delete all snapshots # Function to delete all snapshots
delete_all_snapshots() { delete_all_snapshots() {
echo "WARNING: This will delete all snapshots!" printf "%b\n" "${RED}WARNING: This will delete all snapshots!${RC}"
read -p "Are you sure? (yes/no): " CONFIRMATION printf "%b" "${CYAN}Are you sure? (yes/no): ${RC}"
read -r CONFIRMATION
if [ "$CONFIRMATION" = "yes" ]; then if [ "$CONFIRMATION" = "yes" ]; then
echo "Deleting all snapshots..." echo "Deleting all snapshots..."
@ -130,7 +138,8 @@ delete_all_snapshots() {
main_menu() { main_menu() {
while true; do while true; do
display_menu display_menu
read -p "Select an option (1-7): " OPTION printf "%b" "${CYAN}Select an option (1-7): ${RC}"
read -r OPTION
case $OPTION in case $OPTION in
1) list_snapshots ;; 1) list_snapshots ;;
@ -139,11 +148,11 @@ while true; do
4) restore_snapshot ;; 4) restore_snapshot ;;
5) delete_snapshot ;; 5) delete_snapshot ;;
6) delete_all_snapshots ;; 6) delete_all_snapshots ;;
7) echo "Exiting..."; exit 0 ;; 7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
*) echo "Invalid option. Please try again." ;; *) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
esac esac
printf "%b" "${CYAN}Press Enter to continue...${RC}"
read -p "Press Enter to continue..." read -r dummy
done done
} }