mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-12-23 20:09:44 +00:00
Replace echos with printf (utils) (#479)
Co-authored-by: nnyyxxxx <nnyyxxxx@users.noreply.github.com> Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
parent
cca4fd1ced
commit
969c83dda6
|
@ -4,18 +4,18 @@
|
|||
|
||||
# Function to list common session options
|
||||
list_sessions() {
|
||||
echo "Select the session:"
|
||||
echo "1) GNOME (gnome.desktop)"
|
||||
echo "2) KDE Plasma (plasma.desktop)"
|
||||
echo "3) XFCE (xfce.desktop)"
|
||||
echo "4) LXDE (LXDE.desktop)"
|
||||
echo "5) LXQt (lxqt.desktop)"
|
||||
echo "6) Cinnamon (cinnamon.desktop)"
|
||||
echo "7) MATE (mate.desktop)"
|
||||
echo "8) Openbox (openbox.desktop)"
|
||||
echo "9) i3 (i3.desktop)"
|
||||
echo "10) Custom session"
|
||||
echo "Enter your choice [1-10]: "
|
||||
printf "Select the session:\n"
|
||||
printf "1) GNOME (gnome.desktop)\n"
|
||||
printf "2) KDE Plasma (plasma.desktop)\n"
|
||||
printf "3) XFCE (xfce.desktop)\n"
|
||||
printf "4) LXDE (LXDE.desktop)\n"
|
||||
printf "5) LXQt (lxqt.desktop)\n"
|
||||
printf "6) Cinnamon (cinnamon.desktop)\n"
|
||||
printf "7) MATE (mate.desktop)\n"
|
||||
printf "8) Openbox (openbox.desktop)\n"
|
||||
printf "9) i3 (i3.desktop)\n"
|
||||
printf "10) Custom session\n"
|
||||
printf "Enter your choice [1-10]: "
|
||||
read session_choice
|
||||
|
||||
case "$session_choice" in
|
||||
|
@ -29,116 +29,116 @@ list_sessions() {
|
|||
8) session="openbox.desktop" ;;
|
||||
9) session="i3.desktop" ;;
|
||||
10)
|
||||
echo "Enter custom session name (e.g., mysession.desktop): "
|
||||
printf "Enter custom session name (e.g., mysession.desktop): "
|
||||
read -r session ;;
|
||||
*)
|
||||
echo "Invalid option selected."
|
||||
printf "Invalid option selected.\n"
|
||||
exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to configure LightDM
|
||||
configure_lightdm() {
|
||||
echo "Configuring LightDM for autologin..."
|
||||
printf "Configuring LightDM for autologin...\n"
|
||||
|
||||
echo "Enter username for LightDM autologin: "
|
||||
printf "Enter username for LightDM autologin: "
|
||||
read -r user
|
||||
|
||||
$ESCALATION_TOOL "echo '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||
$ESCALATION_TOOL "echo 'autologin-user=$user' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||
$ESCALATION_TOOL "echo 'autologin-user-timeout=0' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||
$ESCALATION_TOOL "printf '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||
$ESCALATION_TOOL "printf 'autologin-user=$user' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||
$ESCALATION_TOOL "printf 'autologin-user-timeout=0' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||
|
||||
echo "LightDM has been configured for autologin."
|
||||
printf "LightDM has been configured for autologin.\n"
|
||||
}
|
||||
|
||||
# Function to remove LightDM autologin
|
||||
remove_lightdm_autologin() {
|
||||
echo "Removing LightDM autologin configuration..."
|
||||
printf "Removing LightDM autologin configuration...\n"
|
||||
$ESCALATION_TOOL rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf
|
||||
echo "LightDM autologin configuration has been removed."
|
||||
printf "LightDM autologin configuration has been removed.\n"
|
||||
}
|
||||
|
||||
# Function to configure GDM
|
||||
configure_gdm() {
|
||||
echo "Configuring GDM for autologin..."
|
||||
printf "Configuring GDM for autologin...\n"
|
||||
|
||||
echo "Enter username for GDM autologin: "
|
||||
printf "Enter username for GDM autologin: "
|
||||
read -r user
|
||||
|
||||
$ESCALATION_TOOL "echo '[daemon]' > /etc/gdm/custom.conf"
|
||||
$ESCALATION_TOOL "echo 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
|
||||
$ESCALATION_TOOL "echo 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
|
||||
$ESCALATION_TOOL "printf '[daemon]' > /etc/gdm/custom.conf"
|
||||
$ESCALATION_TOOL "printf 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
|
||||
$ESCALATION_TOOL "printf 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
|
||||
|
||||
echo "GDM has been configured for autologin."
|
||||
printf "GDM has been configured for autologin.\n"
|
||||
}
|
||||
|
||||
# Function to remove GDM autologin
|
||||
remove_gdm_autologin() {
|
||||
echo "Removing GDM autologin configuration..."
|
||||
printf "Removing GDM autologin configuration...\n"
|
||||
$ESCALATION_TOOL sed -i '/AutomaticLoginEnable/d' /etc/gdm/custom.conf
|
||||
$ESCALATION_TOOL sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||
echo "GDM autologin configuration has been removed."
|
||||
printf "GDM autologin configuration has been removed.\n"
|
||||
}
|
||||
|
||||
# Function to configure SDDM
|
||||
configure_sddm() {
|
||||
echo "Configuring SDDM for autologin..."
|
||||
printf "Configuring SDDM for autologin...\n"
|
||||
|
||||
echo "Enter username for SDDM autologin: "
|
||||
printf "Enter username for SDDM autologin: "
|
||||
read -r user
|
||||
list_sessions # Show session options
|
||||
|
||||
$ESCALATION_TOOL "echo '[Autologin]' > /etc/sddm.conf"
|
||||
$ESCALATION_TOOL "echo 'User=$user' >> /etc/sddm.conf"
|
||||
$ESCALATION_TOOL "echo 'Session=$session' >> /etc/sddm.conf"
|
||||
$ESCALATION_TOOL "printf '[Autologin]' > /etc/sddm.conf"
|
||||
$ESCALATION_TOOL "printf 'User=$user' >> /etc/sddm.conf"
|
||||
$ESCALATION_TOOL "printf 'Session=$session' >> /etc/sddm.conf"
|
||||
|
||||
echo "SDDM has been configured for autologin."
|
||||
printf "SDDM has been configured for autologin.\n"
|
||||
}
|
||||
|
||||
# Function to remove SDDM autologin
|
||||
remove_sddm_autologin() {
|
||||
echo "Removing SDDM autologin configuration..."
|
||||
printf "Removing SDDM autologin configuration...\n"
|
||||
$ESCALATION_TOOL sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf
|
||||
echo "SDDM autologin configuration has been removed."
|
||||
printf "SDDM autologin configuration has been removed.\n"
|
||||
}
|
||||
|
||||
# Function to configure LXDM
|
||||
configure_lxdm() {
|
||||
echo "Configuring LXDM for autologin..."
|
||||
printf "Configuring LXDM for autologin...\n"
|
||||
|
||||
echo "Enter username for LXDM autologin: "
|
||||
printf "Enter username for LXDM autologin: "
|
||||
read -r user
|
||||
list_sessions # Show session options
|
||||
|
||||
$ESCALATION_TOOL sed -i "s/^#.*autologin=.*$/autologin=${user}/" /etc/lxdm/lxdm.conf
|
||||
$ESCALATION_TOOL sed -i "s|^#.*session=.*$|session=/usr/bin/${session}|; s|^session=.*$|session=/usr/bin/${session}|" /etc/lxdm/lxdm.conf
|
||||
|
||||
echo "LXDM has been configured for autologin."
|
||||
printf "LXDM has been configured for autologin.\n"
|
||||
}
|
||||
|
||||
# Function to remove LXDM autologin
|
||||
remove_lxdm_autologin() {
|
||||
echo "Removing LXDM autologin configuration..."
|
||||
printf "Removing LXDM autologin configuration...\n"
|
||||
$ESCALATION_TOOL sed -i "s/^autologin=.*$/#autologin=/" /etc/lxdm/lxdm.conf
|
||||
$ESCALATION_TOOL sed -i "s/^session=.*$/#session=/" /etc/lxdm/lxdm.conf
|
||||
echo "LXDM autologin configuration has been removed."
|
||||
printf "LXDM autologin configuration has been removed.\n"
|
||||
}
|
||||
|
||||
# Function to configure or remove autologin based on user choice
|
||||
configure_or_remove_autologin() {
|
||||
echo "Do you want to add or remove autologin?"
|
||||
echo "1) Add autologin"
|
||||
echo "2) Remove autologin"
|
||||
echo "Enter your choice [1-2]: "
|
||||
printf "Do you want to add or remove autologin?\n"
|
||||
printf "1) Add autologin\n"
|
||||
printf "2) Remove autologin\n"
|
||||
printf "Enter your choice [1-2]: "
|
||||
read action_choice
|
||||
|
||||
if [ "$action_choice" = "1" ]; then
|
||||
echo "Choose the display manager to configure:"
|
||||
echo "1) LightDM"
|
||||
echo "2) GDM"
|
||||
echo "3) SDDM"
|
||||
echo "4) LXDM"
|
||||
echo "Enter your choice [1-4]: "
|
||||
printf "Choose the display manager to configure:\n"
|
||||
printf "1) LightDM\n"
|
||||
printf "2) GDM\n"
|
||||
printf "3) SDDM\n"
|
||||
printf "4) LXDM\n"
|
||||
printf "Enter your choice [1-4]: "
|
||||
read choice
|
||||
|
||||
case "$choice" in
|
||||
|
@ -146,15 +146,15 @@ configure_or_remove_autologin() {
|
|||
2) configure_gdm ;;
|
||||
3) configure_sddm ;;
|
||||
4) configure_lxdm ;;
|
||||
*) echo "Invalid option selected." ;;
|
||||
*) printf "Invalid option selected.\n" ;;
|
||||
esac
|
||||
elif [ "$action_choice" = "2" ]; then
|
||||
echo "Choose the display manager to remove autologin:"
|
||||
echo "1) LightDM"
|
||||
echo "2) GDM"
|
||||
echo "3) SDDM"
|
||||
echo "4) LXDM"
|
||||
echo "Enter your choice [1-4]: "
|
||||
printf "Choose the display manager to remove autologin:\n"
|
||||
printf "1) LightDM\n"
|
||||
printf "2) GDM\n"
|
||||
printf "3) SDDM\n"
|
||||
printf "4) LXDM\n"
|
||||
printf "Enter your choice [1-4]: "
|
||||
read choice
|
||||
|
||||
case "$choice" in
|
||||
|
@ -162,18 +162,17 @@ configure_or_remove_autologin() {
|
|||
2) remove_gdm_autologin ;;
|
||||
3) remove_sddm_autologin ;;
|
||||
4) remove_lxdm_autologin ;;
|
||||
*) echo "Invalid option selected." ;;
|
||||
*) printf "Invalid option selected.\n" ;;
|
||||
esac
|
||||
else
|
||||
echo "Invalid choice. Exiting..."
|
||||
printf "Invalid choice. Exiting...\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Action completed. Exiting..."
|
||||
printf "Action completed. Exiting...\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
checkEnv
|
||||
checkEscalationTool
|
||||
configure_or_remove_autologin
|
||||
|
|
|
@ -35,13 +35,13 @@ main_menu() {
|
|||
clear
|
||||
printf "%b\n" "${YELLOW}Bluetooth Manager${RC}"
|
||||
printf "%b\n" "${YELLOW}=================${RC}"
|
||||
echo "1. Scan for devices"
|
||||
echo "2. Pair with a device"
|
||||
echo "3. Connect to a device"
|
||||
echo "4. Disconnect from a device"
|
||||
echo "5. Remove a device"
|
||||
echo "0. Exit"
|
||||
echo -n "Choose an option: "
|
||||
printf "1. Scan for devices\n"
|
||||
printf "2. Pair with a device\n"
|
||||
printf "3. Connect to a device\n"
|
||||
printf "4. Disconnect from a device\n"
|
||||
printf "5. Remove a device\n"
|
||||
printf "0. Exit\n"
|
||||
printf -n "Choose an option: "
|
||||
read choice
|
||||
|
||||
case $choice in
|
||||
|
@ -66,7 +66,7 @@ scan_devices() {
|
|||
printf "%b\n" "${RED}No devices found.${RC}"
|
||||
else
|
||||
printf "%b\n" "${GREEN}Devices found:${RC}"
|
||||
echo "$devices"
|
||||
printf "%s\n" "$devices"
|
||||
fi
|
||||
printf "Press any key to return to the main menu..."
|
||||
read -r dummy
|
||||
|
@ -94,11 +94,11 @@ prompt_for_mac() {
|
|||
device_list=$(echo "$devices" | tr '\n' '\n')
|
||||
i=1
|
||||
echo "$device_list" | while IFS= read -r device; do
|
||||
echo "$i. $device"
|
||||
printf "%d. %s\n" "$i" "$device"
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo "0. Exit to main menu"
|
||||
echo -n "$prompt_msg"
|
||||
printf "0. Exit to main menu\n"
|
||||
printf "%s\n" "$prompt_msg"
|
||||
read choice
|
||||
|
||||
# Validate the choice
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
# Function to display usage instructions
|
||||
usage() {
|
||||
printf "%b\n" "${RED} Usage: $0 ${RC}"
|
||||
echo "No arguments needed. The script will prompt for ISO path and USB device."
|
||||
printf "No arguments needed. The script will prompt for ISO path and USB device.\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Function to display all available block devices
|
||||
list_devices() {
|
||||
printf "%b\n" "${YELLOW} Available devices and partitions: ${RC}"
|
||||
echo ""
|
||||
printf "\n"
|
||||
$ESCALATION_TOOL lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
|
||||
echo ""
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
# Function to fetch the latest Arch Linux ISO
|
||||
|
@ -47,7 +47,7 @@ fetch_arch_older_isos() {
|
|||
printf "%-5s${YELLOW}%-15s ${RC}" "$COUNTER)" "$VERSION"
|
||||
|
||||
if [ $(( COUNTER % ROW_ITEMS )) -eq 0 ]; then
|
||||
echo "" # New line after every 6 versions
|
||||
printf "\n" # New line after every 6 versions
|
||||
fi
|
||||
|
||||
COUNTER=$((COUNTER + 1))
|
||||
|
@ -60,7 +60,6 @@ fetch_arch_older_isos() {
|
|||
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
|
||||
}
|
||||
|
||||
|
||||
# Function to fetch the latest Debian Linux ISO
|
||||
fetch_debian_latest_iso() {
|
||||
DEBIAN_URL=$(curl -s https://www.debian.org/distrib/netinst | grep -oP '(?<=href=")[^"]+debian-[0-9.]+-amd64-netinst.iso(?=")' | head -1)
|
||||
|
@ -99,10 +98,10 @@ choose_iso_source() {
|
|||
fetch_iso_urls() {
|
||||
clear
|
||||
printf "%b\n" "${YELLOW}Available ISOs for download:${RC}"
|
||||
echo "1) Arch Linux (latest)"
|
||||
echo "2) Arch Linux (older versions)"
|
||||
echo "3) Debian Linux (latest)"
|
||||
echo ""
|
||||
printf "1) Arch Linux (latest)\n"
|
||||
printf "2) Arch Linux (older versions)\n"
|
||||
printf "3) Debian Linux (latest)\n"
|
||||
printf "\n"
|
||||
printf "Select the ISO you want to download (1-3): "
|
||||
read -r ISO_OPTION
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# Create a script to toggle numlock
|
||||
|
||||
create_file() {
|
||||
echo "Creating script..."
|
||||
printf "Creating script...\n"
|
||||
"$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
|
@ -23,7 +23,7 @@ EOF
|
|||
|
||||
# Create a systemd service to run the script on boot
|
||||
create_service() {
|
||||
echo "Creating service..."
|
||||
printf "Creating service...\n"
|
||||
"$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF'
|
||||
[Unit]
|
||||
Description=numlock
|
||||
|
@ -52,11 +52,10 @@ numlockSetup() {
|
|||
read -r confirm
|
||||
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
|
||||
"$ESCALATION_TOOL" systemctl enable numlock.service --quiet
|
||||
echo "Numlock will be enabled on boot"
|
||||
printf "Numlock will be enabled on boot\n"
|
||||
else
|
||||
"$ESCALATION_TOOL" systemctl disable numlock.service --quiet
|
||||
echo "Numlock will not be enabled on boot"
|
||||
|
||||
printf "Numlock will not be enabled on boot\n"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ installollama() {
|
|||
clear
|
||||
printf "%b\n" "${YELLOW}Checking if ollama is already installed...${RC}"
|
||||
|
||||
# Check if ollama is already installed
|
||||
if command_exists ollama; then
|
||||
printf "%b\n" "${GREEN}ollama is already installed.${RC}"
|
||||
else
|
||||
|
@ -32,7 +31,6 @@ show_model_info() {
|
|||
ollama show "$model_name"
|
||||
}
|
||||
|
||||
# Function to display available models
|
||||
display_models() {
|
||||
clear
|
||||
printf "%b\n" "${RED}Available Models${RC}"
|
||||
|
@ -58,23 +56,23 @@ display_models() {
|
|||
select_model() {
|
||||
local choice="$1"
|
||||
case $choice in
|
||||
1) echo "llama3.1";;
|
||||
2) echo "llama3.1:70b";;
|
||||
3) echo "llama3.1:405b";;
|
||||
4) echo "phi3";;
|
||||
5) echo "phi3:medium";;
|
||||
6) echo "gemma2:2b";;
|
||||
7) echo "gemma2";;
|
||||
8) echo "gemma2:27b";;
|
||||
9) echo "mistral";;
|
||||
10) echo "moondream";;
|
||||
11) echo "neural-chat";;
|
||||
12) echo "starling-lm";;
|
||||
13) echo "codellama";;
|
||||
14) echo "llama2-uncensored";;
|
||||
15) echo "llava";;
|
||||
16) echo "solar";;
|
||||
*) echo "$choice";; # Treat any other input as a custom model name
|
||||
1) printf "%b\n" "llama3.1";;
|
||||
2) printf "%b\n" "llama3.1:70b";;
|
||||
3) printf "%b\n" "llama3.1:405b";;
|
||||
4) printf "%b\n" "phi3";;
|
||||
5) printf "%b\n" "phi3:medium";;
|
||||
6) printf "%b\n" "gemma2:2b";;
|
||||
7) printf "%b\n" "gemma2";;
|
||||
8) printf "%b\n" "gemma2:27b";;
|
||||
9) printf "%b\n" "mistral";;
|
||||
10) printf "%b\n" "moondream";;
|
||||
11) printf "%b\n" "neural-chat";;
|
||||
12) printf "%b\n" "starling-lm";;
|
||||
13) printf "%b\n" "codellama";;
|
||||
14) printf "%b\n" "llama2-uncensored";;
|
||||
15) printf "%b\n" "llava";;
|
||||
16) printf "%b\n" "solar";;
|
||||
*) printf "%b\n" "$choice";;
|
||||
esac
|
||||
}
|
||||
|
||||
|
@ -98,7 +96,6 @@ run_model() {
|
|||
|
||||
printf "%b\n" "${YELLOW}Running the model: $model...${RC}"
|
||||
ollama run "$model"
|
||||
|
||||
}
|
||||
|
||||
create_model() {
|
||||
|
@ -184,7 +181,7 @@ menu() {
|
|||
printf "5) Remove a model\n"
|
||||
printf "6) Exit\n"
|
||||
|
||||
printf "%b" "${YELLOW}Enter your choice (1-5): ${RC}"
|
||||
printf "%b\n" "${YELLOW}Enter your choice (1-5): ${RC}"
|
||||
read -r choice
|
||||
|
||||
case $choice in
|
||||
|
|
|
@ -9,72 +9,71 @@ SCRIPT_DIR="./services"
|
|||
# Function to show the main menu
|
||||
show_menu() {
|
||||
clear
|
||||
echo "============================"
|
||||
echo " Service Management Menu"
|
||||
echo "============================"
|
||||
echo "1. View all services"
|
||||
echo "2. View enabled services"
|
||||
echo "3. View disabled services"
|
||||
echo "4. Add a new service"
|
||||
echo "5. Remove a service"
|
||||
echo "6. Start a service"
|
||||
echo "7. Stop a service"
|
||||
echo "8. Enable a service"
|
||||
echo "9. Disable a service"
|
||||
echo "10. Create a service from external scripts"
|
||||
echo "11. Exit"
|
||||
echo "============================"
|
||||
printf "============================\n"
|
||||
printf " Service Management Menu\n"
|
||||
printf "============================\n"
|
||||
printf "1. View all services\n"
|
||||
printf "2. View enabled services\n"
|
||||
printf "3. View disabled services\n"
|
||||
printf "4. Add a new service\n"
|
||||
printf "5. Remove a service\n"
|
||||
printf "6. Start a service\n"
|
||||
printf "7. Stop a service\n"
|
||||
printf "8. Enable a service\n"
|
||||
printf "9. Disable a service\n"
|
||||
printf "10. Create a service from external scripts\n"
|
||||
printf "11. Exit\n"
|
||||
printf "============================\n"
|
||||
}
|
||||
|
||||
# Function to view all services
|
||||
view_all_services() {
|
||||
echo "Listing all services..."
|
||||
printf "Listing all services...\n"
|
||||
"$ESCALATION_TOOL" systemctl list-units --type=service --all --no-legend | awk '{print $1}' | sed 's/\.service//' | more
|
||||
}
|
||||
|
||||
# Function to view enabled services
|
||||
view_enabled_services() {
|
||||
echo "Listing enabled services..."
|
||||
printf "Listing enabled services...\n"
|
||||
"$ESCALATION_TOOL" systemctl list-unit-files --type=service --state=enabled --no-legend | awk '{print $1}' | sed 's/\.service//' | more
|
||||
}
|
||||
|
||||
# Function to view disabled services
|
||||
view_disabled_services() {
|
||||
echo "Listing disabled services..."
|
||||
printf "Listing disabled services...\n"
|
||||
"$ESCALATION_TOOL" systemctl list-unit-files --type=service --state=disabled --no-legend | awk '{print $1}' | sed 's/\.service//' | more
|
||||
}
|
||||
|
||||
# Function to view started services
|
||||
view_started_services() {
|
||||
echo "Listing started services:"
|
||||
printf "Listing started services:\n"
|
||||
"$ESCALATION_TOOL" systemctl list-units --type=service --state=running --no-pager | head -n -6 | awk 'NR>1 {print $1}' | more
|
||||
}
|
||||
|
||||
# Function to add a new service
|
||||
add_service() {
|
||||
while [ -z "$SERVICE_NAME" ]; do
|
||||
echo "Enter the name of the new service (e.g., my_service):"
|
||||
printf "Enter the name of the new service (e.g., my_service):\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
if "$ESCALATION_TOOL" systemctl list-units --type=service --all --no-legend | grep -q "$SERVICE_NAME.service"; then
|
||||
echo "Service already exists!"
|
||||
printf "Service already exists!\n"
|
||||
SERVICE_NAME=""
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Enter the description of the service:"
|
||||
printf "Enter the description of the service:\n"
|
||||
read -r SERVICE_DESCRIPTION
|
||||
|
||||
echo "Enter the command to execute the service (e.g., /usr/local/bin/my_service.sh):"
|
||||
printf "Enter the command to execute the service (e.g., /usr/local/bin/my_service.sh):\n"
|
||||
read -r EXEC_START
|
||||
|
||||
echo "Enter the user to run the service as (leave empty for default):"
|
||||
printf "Enter the user to run the service as (leave empty for default):\n"
|
||||
read -r SERVICE_USER
|
||||
|
||||
echo "Enter the working directory for the service (leave empty for default):"
|
||||
printf "Enter the working directory for the service (leave empty for default):\n"
|
||||
read -r WORKING_DIRECTORY
|
||||
|
||||
echo "Enter the restart policy (e.g., always, on-failure; leave empty for no restart):"
|
||||
printf "Enter the restart policy (e.g., always, on-failure; leave empty for no restart):\n"
|
||||
read -r RESTART_POLICY
|
||||
|
||||
# Create the service unit file
|
||||
|
@ -82,108 +81,107 @@ add_service() {
|
|||
|
||||
# Create the service file with conditionals for optional fields
|
||||
{
|
||||
echo "[Unit]"
|
||||
echo "Description=$SERVICE_DESCRIPTION"
|
||||
echo ""
|
||||
echo "[Service]"
|
||||
echo "ExecStart=$EXEC_START"
|
||||
[ -n "$SERVICE_USER" ] && echo "User=$SERVICE_USER"
|
||||
[ -n "$WORKING_DIRECTORY" ] && echo "WorkingDirectory=$WORKING_DIRECTORY"
|
||||
[ -n "$RESTART_POLICY" ] && echo "Restart=$RESTART_POLICY"
|
||||
echo ""
|
||||
echo "[Install]"
|
||||
echo "WantedBy=multi-user.target"
|
||||
} | "$ESCALATION_TOOL" tee "$SERVICE_FILE" > /dev/null
|
||||
printf "[Unit]\n"
|
||||
printf "Description=$SERVICE_DESCRIPTION\n"
|
||||
printf "\n"
|
||||
printf "[Service]\n"
|
||||
printf "ExecStart=$EXEC_START\n"
|
||||
[ -n "$SERVICE_USER" ] && printf "User=$SERVICE_USER\n"
|
||||
[ -n "$WORKING_DIRECTORY" ] && printf "WorkingDirectory=$WORKING_DIRECTORY\n"
|
||||
[ -n "$RESTART_POLICY" ] && printf "Restart=$RESTART_POLICY\n"
|
||||
printf "\n"
|
||||
printf "[Install]\n"
|
||||
printf "WantedBy=multi-user.target\n"
|
||||
} | $ESCALATION_TOOL tee "$SERVICE_FILE" > /dev/null
|
||||
|
||||
# Set permissions and reload systemd
|
||||
"$ESCALATION_TOOL" chmod 644 "$SERVICE_FILE"
|
||||
"$ESCALATION_TOOL" systemctl daemon-reload
|
||||
echo "Service $SERVICE_NAME has been created and is ready to be started."
|
||||
$ESCALATION_TOOL chmod 644 "$SERVICE_FILE"
|
||||
$ESCALATION_TOOL systemctl daemon-reload
|
||||
printf "Service $SERVICE_NAME has been created and is ready to be started.\n"
|
||||
|
||||
# Optionally, enable and start the service
|
||||
echo "Do you want to start and enable the service now? (y/n)"
|
||||
printf "Do you want to start and enable the service now? (y/n)\n"
|
||||
read -r START_ENABLE
|
||||
|
||||
if [ "$START_ENABLE" = "y" ]; then
|
||||
"$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"
|
||||
"$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"
|
||||
echo "Service $SERVICE_NAME has been started and enabled."
|
||||
printf "Service $SERVICE_NAME has been started and enabled.\n"
|
||||
else
|
||||
echo "Service $SERVICE_NAME has been created but not started."
|
||||
printf "Service $SERVICE_NAME has been created but not started.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to remove a service
|
||||
remove_service() {
|
||||
echo "Enter the name of the service to remove (e.g., my_service):"
|
||||
printf "Enter the name of the service to remove (e.g., my_service):\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
|
||||
|
||||
if [ -f "$SERVICE_FILE" ]; then
|
||||
echo "Stopping and disabling the service..."
|
||||
"$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"
|
||||
"$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"
|
||||
printf "Stopping and disabling the service...\n"
|
||||
$ESCALATION_TOOL systemctl stop "$SERVICE_NAME"
|
||||
$ESCALATION_TOOL systemctl disable "$SERVICE_NAME"
|
||||
|
||||
echo "Removing the service file..."
|
||||
"$ESCALATION_TOOL" rm -f "$SERVICE_FILE"
|
||||
"$ESCALATION_TOOL" systemctl daemon-reload
|
||||
|
||||
echo "Service $SERVICE_NAME has been removed."
|
||||
printf "Removing the service file...\n"
|
||||
$ESCALATION_TOOL rm -f "$SERVICE_FILE"
|
||||
$ESCALATION_TOOL systemctl daemon-reload
|
||||
printf "Service $SERVICE_NAME has been removed.\n"
|
||||
else
|
||||
echo "Service $SERVICE_NAME does not exist."
|
||||
printf "Service $SERVICE_NAME does not exist.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start a service
|
||||
start_service() {
|
||||
view_disabled_services
|
||||
echo "Enter the name of the service to start (e.g., my_service):"
|
||||
printf "Enter the name of the service to start (e.g., my_service):\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
if "$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"; then
|
||||
echo "Service $SERVICE_NAME has been started."
|
||||
if $ESCALATION_TOOL systemctl start "$SERVICE_NAME"; then
|
||||
printf "Service $SERVICE_NAME has been started.\n"
|
||||
else
|
||||
echo "Failed to start service: $SERVICE_NAME."
|
||||
printf "Failed to start service: $SERVICE_NAME.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to stop a service
|
||||
stop_service() {
|
||||
view_started_services
|
||||
echo "Enter the name of the service to stop (e.g., my_service):"
|
||||
printf "Enter the name of the service to stop (e.g., my_service):\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
if "$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"; then
|
||||
echo "Service $SERVICE_NAME has been stopped."
|
||||
if $ESCALATION_TOOL systemctl stop "$SERVICE_NAME"; then
|
||||
printf "Service $SERVICE_NAME has been stopped.\n"
|
||||
else
|
||||
echo "Failed to stop service: $SERVICE_NAME."
|
||||
printf "Failed to stop service: $SERVICE_NAME.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to enable a service
|
||||
enable_service() {
|
||||
view_disabled_services
|
||||
echo "Enter the name of the service to enable (e.g., my_service):"
|
||||
printf "Enter the name of the service to enable (e.g., my_service):\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
if "$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"; then
|
||||
echo "Service $SERVICE_NAME has been enabled."
|
||||
if $ESCALATION_TOOL systemctl enable "$SERVICE_NAME"; then
|
||||
printf "Service $SERVICE_NAME has been enabled.\n"
|
||||
else
|
||||
echo "Failed to enable service: $SERVICE_NAME."
|
||||
printf "Failed to enable service: $SERVICE_NAME.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to enable a service
|
||||
disable_service() {
|
||||
view_enabled_services
|
||||
echo "Enter the name of the service to disable (e.g., my_service):"
|
||||
printf "Enter the name of the service to disable (e.g., my_service):\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
if "$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"; then
|
||||
echo "Service $SERVICE_NAME has been enabled."
|
||||
if $ESCALATION_TOOL systemctl disable "$SERVICE_NAME"; then
|
||||
printf "Service $SERVICE_NAME has been enabled.\n"
|
||||
else
|
||||
echo "Failed to enable service: $SERVICE_NAME."
|
||||
printf "Failed to enable service: $SERVICE_NAME.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -191,24 +189,24 @@ disable_service() {
|
|||
create_service_from_external() {
|
||||
|
||||
# List all .service files in the SCRIPT_DIR
|
||||
echo "============================"
|
||||
echo "Listing available service files"
|
||||
echo "============================"
|
||||
printf "============================\n"
|
||||
printf "Listing available service files\n"
|
||||
printf "============================\n"
|
||||
for FILE in "$SCRIPT_DIR"/*.service; do
|
||||
echo "$(basename "$FILE")"
|
||||
printf "%s\n" "$(basename "$FILE")"
|
||||
done
|
||||
|
||||
echo "Enter the filename (without the .service extension) of the service to create:"
|
||||
printf "Enter the filename (without the .service extension) of the service to create:\n"
|
||||
read -r SERVICE_NAME
|
||||
|
||||
SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service"
|
||||
|
||||
if [ ! -f "$SERVICE_FILE" ]; then
|
||||
echo "Service file $SERVICE_FILE does not exist."
|
||||
printf "Service file $SERVICE_FILE does not exist.\n"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Enter the username to run the service as (leave empty for no specific user):"
|
||||
printf "Enter the username to run the service as (leave empty for no specific user):\n"
|
||||
read -r SERVICE_USER
|
||||
|
||||
# Create the systemd service file path
|
||||
|
@ -230,27 +228,27 @@ create_service_from_external() {
|
|||
"$ESCALATION_TOOL" cp "$SERVICE_FILE" "$SYSTEMD_SERVICE_FILE"
|
||||
|
||||
# Set permissions and reload systemd
|
||||
"$ESCALATION_TOOL" chmod 644 "$SYSTEMD_SERVICE_FILE"
|
||||
"$ESCALATION_TOOL" systemctl daemon-reload
|
||||
echo "Service $SERVICE_NAME has been created and is ready to be started."
|
||||
$ESCALATION_TOOL chmod 644 "$SYSTEMD_SERVICE_FILE"
|
||||
$ESCALATION_TOOL systemctl daemon-reload
|
||||
printf "Service $SERVICE_NAME has been created and is ready to be started.\n"
|
||||
|
||||
# Optionally, enable and start the service
|
||||
echo "Do you want to start and enable the service now? (y/n)"
|
||||
printf "Do you want to start and enable the service now? (y/n)\n"
|
||||
read -r START_ENABLE
|
||||
|
||||
if [ "$START_ENABLE" = "y" ]; then
|
||||
"$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"
|
||||
"$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"
|
||||
echo "Service $SERVICE_NAME has been started and enabled."
|
||||
$ESCALATION_TOOL systemctl start "$SERVICE_NAME"
|
||||
$ESCALATION_TOOL systemctl enable "$SERVICE_NAME"
|
||||
printf "Service $SERVICE_NAME has been started and enabled.\n"
|
||||
else
|
||||
echo "Service $SERVICE_NAME has been created but not started."
|
||||
printf "Service $SERVICE_NAME has been created but not started.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
while true; do
|
||||
show_menu
|
||||
echo "Enter your choice:"
|
||||
printf "Enter your choice:\n"
|
||||
read -r CHOICE
|
||||
|
||||
case $CHOICE in
|
||||
|
@ -264,11 +262,11 @@ main() {
|
|||
8) enable_service ;;
|
||||
9) disable_service ;;
|
||||
10) create_service_from_external ;;
|
||||
11) echo "Exiting..."; exit 0 ;;
|
||||
*) echo "Invalid choice. Please try again." ;;
|
||||
11) printf "Exiting...\n"; exit 0 ;;
|
||||
*) printf "Invalid choice. Please try again.\n" ;;
|
||||
esac
|
||||
|
||||
echo "Press [Enter] to continue..."
|
||||
printf "Press [Enter] to continue...\n"
|
||||
read -r dummy
|
||||
done
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ install_timeshift() {
|
|||
clear
|
||||
printf "%b\n" "${YELLOW}Checking if Timeshift is installed...${RC}"
|
||||
|
||||
if ! command_exists timeshift; then
|
||||
if ! command_exists timeshift; then
|
||||
case ${PACKAGER} in
|
||||
pacman)
|
||||
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm timeshift
|
||||
|
@ -17,7 +17,7 @@ install_timeshift() {
|
|||
;;
|
||||
esac
|
||||
else
|
||||
echo "Timeshift is already installed."
|
||||
printf "%b\n" "${GREEN}Timeshift is already installed.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ install_timeshift() {
|
|||
display_menu() {
|
||||
clear
|
||||
printf "%b\n" "${CYAN}Timeshift CLI Automation${RC}"
|
||||
printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
|
||||
printf "%b\n" "${CYAN}1) List Snapshots${RC}"
|
||||
printf "%b\n" "${CYAN}2) List Devices${RC}"
|
||||
printf "%b\n" "${CYAN}3) Create Snapshot${RC}"
|
||||
|
@ -33,7 +32,6 @@ display_menu() {
|
|||
printf "%b\n" "${CYAN}5) Delete Snapshot${RC}"
|
||||
printf "%b\n" "${CYAN}6) Delete All Snapshots${RC}"
|
||||
printf "%b\n" "${CYAN}7) Exit${RC}"
|
||||
printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
|
||||
}
|
||||
|
||||
# Function to list snapshots
|
||||
|
@ -50,26 +48,26 @@ list_devices() {
|
|||
|
||||
# Function to create a new snapshot
|
||||
create_snapshot() {
|
||||
printf "%b" "${CYAN}Enter a comment for the snapshot (optional): ${RC}"
|
||||
printf "%b\n" "${CYAN}Enter a comment for the snapshot (optional): ${RC}"
|
||||
read -r COMMENT
|
||||
printf "%b" "${CYAN}Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): ${RC}"
|
||||
printf "%b\n" "${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
|
||||
echo "Creating snapshot with no comment or tag..."
|
||||
printf "%b\n" "${CYAN}Creating snapshot with no comment or tag...${RC}"
|
||||
$ESCALATION_TOOL timeshift --create
|
||||
elif [ -z "$TAG" ]; then
|
||||
echo "Creating snapshot with no tag..."
|
||||
printf "%b\n" "${CYAN}Creating snapshot with no tag...${RC}"
|
||||
$ESCALATION_TOOL timeshift --create --comments "$COMMENT"
|
||||
else
|
||||
echo "Creating snapshot with tag: $TAG..."
|
||||
printf "%b\n" "${CYAN}Creating snapshot with tag: $TAG...${RC}"
|
||||
$ESCALATION_TOOL timeshift --create --comments "$COMMENT" --tags "$TAG"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Snapshot created successfully."
|
||||
printf "%b\n" "${GREEN}Snapshot created successfully.${RC}"
|
||||
else
|
||||
echo "Snapshot creation failed."
|
||||
printf "%b\n" "${RED}Snapshot creation failed.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -77,17 +75,17 @@ create_snapshot() {
|
|||
restore_snapshot() {
|
||||
list_snapshots
|
||||
|
||||
printf "%b" "${CYAN}Enter the snapshot name you want to restore: ${RC}"
|
||||
printf "%b\n" "${CYAN}Enter the snapshot name you want to restore: ${RC}"
|
||||
read -r SNAPSHOT
|
||||
printf "%b" "${CYAN}Enter the target device (e.g., /dev/sda1): ${RC}"
|
||||
printf "%b\n" "${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}"
|
||||
printf "%b\n" "${CYAN}Do you want to skip GRUB reinstall? (yes/no): ${RC}"
|
||||
read -r SKIP_GRUB
|
||||
|
||||
if [ "$SKIP_GRUB" = "yes" ]; then
|
||||
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --skip-grub --yes
|
||||
else
|
||||
printf "%b" "${CYAN}Enter GRUB device (e.g., /dev/sda): ${RC}"
|
||||
printf "%b\n" "${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
|
||||
fi
|
||||
|
@ -103,7 +101,7 @@ restore_snapshot() {
|
|||
delete_snapshot() {
|
||||
list_snapshots
|
||||
|
||||
printf "%b" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
|
||||
printf "%b\n" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
|
||||
read -r SNAPSHOT
|
||||
|
||||
printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
|
||||
|
@ -119,11 +117,11 @@ delete_snapshot() {
|
|||
# Function to delete all snapshots
|
||||
delete_all_snapshots() {
|
||||
printf "%b\n" "${RED}WARNING: This will delete all snapshots!${RC}"
|
||||
printf "%b" "${CYAN}Are you sure? (yes/no): ${RC}"
|
||||
printf "%b\n" "${CYAN}Are you sure? (yes/no): ${RC}"
|
||||
read -r CONFIRMATION
|
||||
|
||||
if [ "$CONFIRMATION" = "yes" ]; then
|
||||
echo "Deleting all snapshots..."
|
||||
printf "%b\n" "${CYAN}Deleting all snapshots...${RC}"
|
||||
$ESCALATION_TOOL timeshift --delete-all --yes
|
||||
if [ $? -eq 0 ]; then
|
||||
printf "%b\n" "${GREEN}All snapshots deleted successfully.${RC}"
|
||||
|
@ -136,24 +134,24 @@ delete_all_snapshots() {
|
|||
}
|
||||
|
||||
main_menu() {
|
||||
while true; do
|
||||
display_menu
|
||||
printf "%b" "${CYAN}Select an option (1-7): ${RC}"
|
||||
read -r OPTION
|
||||
while true; do
|
||||
display_menu
|
||||
printf "%b\n" "${CYAN}Select an option (1-7): ${RC}"
|
||||
read -r OPTION
|
||||
|
||||
case $OPTION in
|
||||
1) list_snapshots ;;
|
||||
2) list_devices ;;
|
||||
3) create_snapshot ;;
|
||||
4) restore_snapshot ;;
|
||||
5) delete_snapshot ;;
|
||||
6) delete_all_snapshots ;;
|
||||
7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
|
||||
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
||||
esac
|
||||
printf "%b" "${CYAN}Press Enter to continue...${RC}"
|
||||
read -r dummy
|
||||
done
|
||||
case $OPTION in
|
||||
1) list_snapshots ;;
|
||||
2) list_devices ;;
|
||||
3) create_snapshot ;;
|
||||
4) restore_snapshot ;;
|
||||
5) delete_snapshot ;;
|
||||
6) delete_all_snapshots ;;
|
||||
7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
|
||||
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
||||
esac
|
||||
printf "%b\n" "${CYAN}Press Enter to continue...${RC}"
|
||||
read -r dummy
|
||||
done
|
||||
}
|
||||
|
||||
checkEnv
|
||||
|
|
34
tabs/utils/wifi-control.sh
Normal file → Executable file
34
tabs/utils/wifi-control.sh
Normal file → Executable file
|
@ -38,14 +38,14 @@ main_menu() {
|
|||
clear
|
||||
printf "%b\n" "${YELLOW}WiFi Manager${RC}"
|
||||
printf "%b\n" "${YELLOW}============${RC}"
|
||||
echo "1. Turn WiFi On"
|
||||
echo "2. Turn WiFi Off"
|
||||
echo "3. Scan for WiFi networks"
|
||||
echo "4. Connect to a WiFi network"
|
||||
echo "5. Disconnect from a WiFi network"
|
||||
echo "6. Remove a WiFi connection"
|
||||
echo "0. Exit"
|
||||
echo -n "Choose an option: "
|
||||
printf "1. Turn WiFi On\n"
|
||||
printf "2. Turn WiFi Off\n"
|
||||
printf "3. Scan for WiFi networks\n"
|
||||
printf "4. Connect to a WiFi network\n"
|
||||
printf "5. Disconnect from a WiFi network\n"
|
||||
printf "6. Remove a WiFi connection\n"
|
||||
printf "0. Exit\n"
|
||||
printf "Choose an option: "
|
||||
read choice
|
||||
|
||||
case $choice in
|
||||
|
@ -72,7 +72,7 @@ scan_networks() {
|
|||
printf "%b\n" "${GREEN}Top 10 Networks found:${RC}"
|
||||
echo "$networks" | awk -F: '{printf("%d. SSID: %-25s \n", NR, $1)}'
|
||||
fi
|
||||
echo "Press any key to return to the main menu..."
|
||||
printf "Press any key to return to the main menu...\n"
|
||||
read -r dummy
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ wifi_on() {
|
|||
} || {
|
||||
printf "%b\n" "${RED}Failed to turn on WiFi.${RC}"
|
||||
}
|
||||
echo "Press any key to return to the main menu..."
|
||||
printf "Press any key to return to the main menu...\n"
|
||||
read -r dummy
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ wifi_off() {
|
|||
} || {
|
||||
printf "%b\n" "${RED}Failed to turn off WiFi.${RC}"
|
||||
}
|
||||
echo "Press any key to return to the main menu..."
|
||||
printf "Press any key to return to the main menu...\n"
|
||||
read -r dummy
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ prompt_for_network() {
|
|||
networks=$(nmcli -t -f SSID dev wifi list | awk -F: '!seen[$1]++' | grep -v '^$')
|
||||
if [ -z "$networks" ]; then
|
||||
printf "%b\n" "${RED}No networks available. Please scan for networks first.${RC}"
|
||||
echo "Press any key to return to the main menu..."
|
||||
printf "Press any key to return to the main menu...\n"
|
||||
read -r dummy
|
||||
rm -f "$temp_file"
|
||||
return
|
||||
|
@ -130,16 +130,16 @@ prompt_for_network() {
|
|||
i=$((i + 1))
|
||||
done < "$temp_file"
|
||||
|
||||
echo "0. Exit to main menu"
|
||||
echo -n "$prompt_msg"
|
||||
printf "0. Exit to main menu\n"
|
||||
printf "%s" "$prompt_msg"
|
||||
read choice
|
||||
|
||||
if [ "$choice" -ge 1 ] && [ "$choice" -lt "$i" ]; then
|
||||
ssid=$(sed -n "${choice}p" "$temp_file" | awk -F: '{print $1}')
|
||||
if [ "$action" = "connect" ]; then
|
||||
echo -n "Enter password for SSID $ssid: "
|
||||
printf "Enter password for SSID %s: " "$ssid"
|
||||
read password
|
||||
echo
|
||||
printf "\n"
|
||||
nmcli dev wifi connect "$ssid" password "$password" && {
|
||||
printf "%b\n" "${GREEN}$success_msg${RC}"
|
||||
} || {
|
||||
|
@ -150,7 +150,7 @@ prompt_for_network() {
|
|||
printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
|
||||
fi
|
||||
|
||||
echo "Press any key to return to the selection menu..."
|
||||
printf "Press any key to return to the selection menu...\n"
|
||||
read -r dummy
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user