mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-12-23 20:09:44 +00:00
commit
43740a48c1
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
. ../common-script.sh
|
||||
|
||||
makeDWM() {
|
||||
|
@ -114,7 +115,7 @@ picom_animations() {
|
|||
fi
|
||||
|
||||
# Install the built binary
|
||||
if ! sudo ninja -C build install; then
|
||||
if ! $ESCALATION_TOOL ninja -C build install; then
|
||||
echo "Failed to install the built binary"
|
||||
return 1
|
||||
fi
|
||||
|
@ -192,8 +193,8 @@ setupDisplayManager() {
|
|||
echo "Setting up Display Manager"
|
||||
currentdm="none"
|
||||
for dm in gdm sddm lightdm; do
|
||||
if systemctl is-active --quiet $dm.service; then
|
||||
currentdm=$dm
|
||||
if systemctl is-active --quiet "$dm.service"; then
|
||||
currentdm="$dm"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -203,13 +204,13 @@ setupDisplayManager() {
|
|||
echo "No display manager found, installing $DM"
|
||||
case "$PACKAGER" in
|
||||
pacman)
|
||||
$ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm $DM
|
||||
$ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm "$DM"
|
||||
;;
|
||||
apt)
|
||||
$ESCALATION_TOOL "$PACKAGER" install -y $DM
|
||||
$ESCALATION_TOOL "$PACKAGER" install -y "$DM"
|
||||
;;
|
||||
dnf)
|
||||
$ESCALATION_TOOL "$PACKAGER" install -y $DM
|
||||
$ESCALATION_TOOL "$PACKAGER" install -y "$DM"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported package manager: $PACKAGER"
|
||||
|
@ -217,78 +218,48 @@ setupDisplayManager() {
|
|||
;;
|
||||
esac
|
||||
echo "$DM installed successfully"
|
||||
systemctl enable $DM
|
||||
|
||||
# Clear the screen
|
||||
clear
|
||||
systemctl enable "$DM"
|
||||
|
||||
# Prompt user for auto-login
|
||||
echo "Do you want to enable auto-login?"
|
||||
echo "Use arrow keys or j/k to navigate, Enter to select"
|
||||
options=("Yes" "No")
|
||||
selected=0
|
||||
|
||||
# Function to print menu
|
||||
print_menu() {
|
||||
for i in "${!options[@]}"; do
|
||||
if [ $i -eq $selected ]; then
|
||||
echo "> ${options[$i]}"
|
||||
# Using printf instead of echo -n as It's more posix-compliant.
|
||||
printf "Do you want to enable auto-login? (Y/n) "
|
||||
read -r answer
|
||||
case "$answer" in
|
||||
[Yy]*)
|
||||
echo "Configuring SDDM for autologin"
|
||||
SDDM_CONF="/etc/sddm.conf"
|
||||
if [ ! -f "$SDDM_CONF" ]; then
|
||||
echo "[Autologin]" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
|
||||
echo "User=$USER" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
|
||||
echo "Session=dwm" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
|
||||
else
|
||||
echo " ${options[$i]}"
|
||||
$ESCALATION_TOOL sed -i '/^\[Autologin\]/d' "$SDDM_CONF"
|
||||
$ESCALATION_TOOL sed -i '/^User=/d' "$SDDM_CONF"
|
||||
$ESCALATION_TOOL sed -i '/^Session=/d' "$SDDM_CONF"
|
||||
echo "[Autologin]" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
|
||||
echo "User=$USER" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
|
||||
echo "Session=dwm" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Handle user input
|
||||
while true; do
|
||||
print_menu
|
||||
read -rsn1 key
|
||||
case "$key" in
|
||||
$'\x1B') # ESC sequence for arrow keys
|
||||
read -rsn2 key
|
||||
case "$key" in
|
||||
'[A' | 'k') ((selected > 0)) && ((selected--));; # Up arrow or k
|
||||
'[B' | 'j') ((selected < ${#options[@]}-1)) && ((selected++));; # Down arrow or j
|
||||
esac
|
||||
;;
|
||||
'') break;; # Enter key
|
||||
esac
|
||||
clear
|
||||
done
|
||||
|
||||
if [ "${options[$selected]}" = "Yes" ]; then
|
||||
echo "Configuring SDDM for autologin"
|
||||
SDDM_CONF="/etc/sddm.conf"
|
||||
if [ ! -f "$SDDM_CONF" ]; then
|
||||
echo "[Autologin]" | sudo tee -a "$SDDM_CONF"
|
||||
echo "User=$USER" | sudo tee -a "$SDDM_CONF"
|
||||
echo "Session=dwm" | sudo tee -a "$SDDM_CONF"
|
||||
else
|
||||
sudo sed -i '/^\[Autologin\]/d' "$SDDM_CONF"
|
||||
sudo sed -i '/^User=/d' "$SDDM_CONF"
|
||||
sudo sed -i '/^Session=/d' "$SDDM_CONF"
|
||||
echo "[Autologin]" | sudo tee -a "$SDDM_CONF"
|
||||
echo "User=$USER" | sudo tee -a "$SDDM_CONF"
|
||||
echo "Session=dwm" | sudo tee -a "$SDDM_CONF"
|
||||
fi
|
||||
echo "Checking if autologin group exists"
|
||||
if ! getent group autologin > /dev/null; then
|
||||
echo "Creating autologin group"
|
||||
sudo groupadd autologin
|
||||
else
|
||||
echo "Autologin group already exists"
|
||||
fi
|
||||
echo "Adding user with UID 1000 to autologin group"
|
||||
USER_UID_1000=$(getent passwd 1000 | cut -d: -f1)
|
||||
if [ -n "$USER_UID_1000" ]; then
|
||||
sudo usermod -aG autologin "$USER_UID_1000"
|
||||
echo "User $USER_UID_1000 added to autologin group"
|
||||
else
|
||||
echo "No user with UID 1000 found - Auto login not possible"
|
||||
fi
|
||||
else
|
||||
echo "Auto-login configuration skipped"
|
||||
fi
|
||||
echo "Checking if autologin group exists"
|
||||
if ! getent group autologin > /dev/null; then
|
||||
echo "Creating autologin group"
|
||||
$ESCALATION_TOOL groupadd autologin
|
||||
else
|
||||
echo "Autologin group already exists"
|
||||
fi
|
||||
echo "Adding user with UID 1000 to autologin group"
|
||||
USER_UID_1000=$(getent passwd 1000 | cut -d: -f1)
|
||||
if [ -n "$USER_UID_1000" ]; then
|
||||
$ESCALATION_TOOL usermod -aG autologin "$USER_UID_1000"
|
||||
echo "User $USER_UID_1000 added to autologin group"
|
||||
else
|
||||
echo "No user with UID 1000 found - Auto login not possible"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Auto-login configuration skipped"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
|
@ -302,4 +273,4 @@ setupDWM
|
|||
makeDWM
|
||||
install_nerd_font
|
||||
clone_config_folders
|
||||
configure_backgrounds
|
||||
configure_backgrounds
|
|
@ -54,7 +54,7 @@ checkEscalationTool() {
|
|||
fi
|
||||
done
|
||||
|
||||
echo -e "${RED}Can't find a supported escalation tool${RC}"
|
||||
printf "%b\n" "${RED}Can't find a supported escalation tool${RC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ checkPackageManager() {
|
|||
done
|
||||
|
||||
if [ -z "${PACKAGER}" ]; then
|
||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
||||
printf "%b\n" "${RED}Can't find a supported package manager${RC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ installPkg() {
|
|||
}
|
||||
|
||||
configureUFW() {
|
||||
echo -e "${GREEN}Using Chris Titus Recommended Firewall Rules${RC}"
|
||||
printf "%b\n" "${GREEN}Using Chris Titus Recommended Firewall Rules${RC}"
|
||||
|
||||
echo "Disabling UFW"
|
||||
$ESCALATION_TOOL ufw disable
|
||||
|
@ -40,7 +40,7 @@ configureUFW() {
|
|||
$ESCALATION_TOOL ufw default allow outgoing
|
||||
|
||||
$ESCALATION_TOOL ufw enable
|
||||
echo -e "${GREEN}Enabled Firewall with Baselines!${RC}"
|
||||
printf "%b\n" "${GREEN}Enabled Firewall with Baselines!${RC}"
|
||||
}
|
||||
|
||||
checkEnv
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
installDepend() {
|
||||
## Check for dependencies.
|
||||
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
|
||||
echo -e "${YELLOW}Installing dependencies...${RC}"
|
||||
printf "%b\n" "${YELLOW}Installing dependencies...${RC}"
|
||||
case $PACKAGER in
|
||||
pacman)
|
||||
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
installDepend() {
|
||||
## Check for dependencies.
|
||||
echo -e "${YELLOW}Installing dependencies...${RC}"
|
||||
printf "%b\n" "${YELLOW}Installing dependencies...${RC}"
|
||||
if [ "$PACKAGER" = "pacman" ]; then
|
||||
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
|
||||
echo "[multilib]" | $ESCALATION_TOOL tee -a /etc/pacman.conf
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
. ../common-script.sh
|
||||
|
||||
install_theme_tools() {
|
||||
printf "${YELLOW}Installing theme tools (qt6ct and kvantum)...${RC}\n"
|
||||
printf "%b\n" "${YELLOW}Installing theme tools (qt6ct and kvantum)...${RC}\n"
|
||||
case $PACKAGER in
|
||||
apt-get)
|
||||
$ESCALATION_TOOL apt-get update
|
||||
|
@ -21,14 +21,14 @@ install_theme_tools() {
|
|||
$ESCALATION_TOOL pacman -S --needed --noconfirm qt6ct kvantum
|
||||
;;
|
||||
*)
|
||||
printf "${RED}Unsupported package manager. Please install qt6ct and kvantum manually.${RC}\n"
|
||||
printf "%b\n" "${RED}Unsupported package manager. Please install qt6ct and kvantum manually.${RC}\n"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
configure_qt6ct() {
|
||||
printf "${YELLOW}Configuring qt6ct...${RC}\n"
|
||||
printf "%b\n" "${YELLOW}Configuring qt6ct...${RC}\n"
|
||||
mkdir -p "$HOME/.config/qt6ct"
|
||||
cat <<EOF > "$HOME/.config/qt6ct/qt6ct.conf"
|
||||
[Appearance]
|
||||
|
@ -36,26 +36,26 @@ style=kvantum
|
|||
color_scheme=default
|
||||
icon_theme=breeze
|
||||
EOF
|
||||
printf "${GREEN}qt6ct configured successfully.${RC}\n"
|
||||
printf "%b\n" "${GREEN}qt6ct configured successfully.${RC}\n"
|
||||
|
||||
# Add QT_QPA_PLATFORMTHEME to /etc/environment
|
||||
if ! grep -q "QT_QPA_PLATFORMTHEME=qt6ct" /etc/environment; then
|
||||
printf "${YELLOW}Adding QT_QPA_PLATFORMTHEME to /etc/environment...${RC}\n"
|
||||
printf "%b\n" "${YELLOW}Adding QT_QPA_PLATFORMTHEME to /etc/environment...${RC}\n"
|
||||
echo "QT_QPA_PLATFORMTHEME=qt6ct" | $ESCALATION_TOOL tee -a /etc/environment > /dev/null
|
||||
printf "${GREEN}QT_QPA_PLATFORMTHEME added to /etc/environment.${RC}\n"
|
||||
printf "%b\n" "${GREEN}QT_QPA_PLATFORMTHEME added to /etc/environment.${RC}\n"
|
||||
else
|
||||
printf "${GREEN}QT_QPA_PLATFORMTHEME already set in /etc/environment.${RC}\n"
|
||||
printf "%b\n" "${GREEN}QT_QPA_PLATFORMTHEME already set in /etc/environment.${RC}\n"
|
||||
fi
|
||||
}
|
||||
|
||||
configure_kvantum() {
|
||||
printf "${YELLOW}Configuring Kvantum...${RC}\n"
|
||||
printf "%b\n" "${YELLOW}Configuring Kvantum...${RC}\n"
|
||||
mkdir -p "$HOME/.config/Kvantum"
|
||||
cat <<EOF > "$HOME/.config/Kvantum/kvantum.kvconfig"
|
||||
[General]
|
||||
theme=Breeze
|
||||
EOF
|
||||
printf "${GREEN}Kvantum configured successfully.${RC}\n"
|
||||
printf "%b\n" "${GREEN}Kvantum configured successfully.${RC}\n"
|
||||
}
|
||||
|
||||
checkEnv
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
. "$(dirname "$0")/../../common-script.sh"
|
||||
. ../../common-script.sh
|
||||
|
||||
installDepend() {
|
||||
case $PACKAGER in
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
. "$(dirname "$0")/../../common-script.sh"
|
||||
. ../../common-script.sh
|
||||
|
||||
installDepend() {
|
||||
case $PACKAGER in
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
. "$(dirname "$0")/../../common-script.sh"
|
||||
. ../../common-script.sh
|
||||
|
||||
# https://rpmfusion.org/Configuration
|
||||
|
||||
installRPMFusion() {
|
||||
case $PACKAGER in
|
||||
dnf)
|
||||
if [[ ! -e /etc/yum.repos.d/rpmfusion-free.repo || ! -e /etc/yum.repos.d/rpmfusion-nonfree.repo ]]; then
|
||||
if [ ! -e /etc/yum.repos.d/rpmfusion-free.repo ] || [ ! -e /etc/yum.repos.d/rpmfusion-nonfree.repo ]; then
|
||||
echo "Installing RPM Fusion..."
|
||||
$ESCALATION_TOOL "$PACKAGER" install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
|
||||
$ESCALATION_TOOL "$PACKAGER" config-manager --enable fedora-cisco-openh264
|
||||
|
|
|
@ -20,7 +20,7 @@ fastUpdate() {
|
|||
|
||||
$ESCALATION_TOOL rate-mirrors --top-mirrors-number-to-retest=5 --disable-comments --save /etc/pacman.d/mirrorlist --allow-root ${dtype_local}
|
||||
if [ $? -ne 0 ] || [ ! -s /etc/pacman.d/mirrorlist ]; then
|
||||
echo -e "${RED}Rate-mirrors failed, restoring backup.${RC}"
|
||||
printf "%b\n" "${RED}Rate-mirrors failed, restoring backup.${RC}"
|
||||
$ESCALATION_TOOL cp /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
|
||||
fi
|
||||
;;
|
||||
|
@ -28,7 +28,7 @@ fastUpdate() {
|
|||
apt-get|nala)
|
||||
$ESCALATION_TOOL apt-get update
|
||||
if ! command_exists nala; then
|
||||
$ESCALATION_TOOL apt-get install -y nala || { echo -e "${YELLOW}Falling back to apt-get${RC}"; PACKAGER="apt-get"; }
|
||||
$ESCALATION_TOOL apt-get install -y nala || { printf "%b\n" "${YELLOW}Falling back to apt-get${RC}"; PACKAGER="apt-get"; }
|
||||
fi
|
||||
|
||||
if [ "${PACKAGER}" = "nala" ]; then
|
||||
|
@ -54,14 +54,14 @@ fastUpdate() {
|
|||
$ESCALATION_TOOL ${PACKAGER} -Syu
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Unsupported package manager: $PACKAGER${RC}"
|
||||
printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
updateSystem() {
|
||||
echo -e "${GREEN}Updating system${RC}"
|
||||
printf "%b\n" "${GREEN}Updating system${RC}"
|
||||
case ${PACKAGER} in
|
||||
nala|apt-get)
|
||||
$ESCALATION_TOOL "${PACKAGER}" update -y
|
||||
|
@ -83,7 +83,7 @@ updateSystem() {
|
|||
$ESCALATION_TOOL ${PACKAGER} -Syu
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Unsupported package manager: ${PACKAGER}${RC}"
|
||||
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
. ../common-script.sh
|
||||
|
||||
# Function to check bluetoothctl is installed
|
||||
# Function to check Bluez is installed
|
||||
setupBluetooth() {
|
||||
echo "Install bluetoothctl if not already installed..."
|
||||
printf "%b\n" "${YELLOW}Installing Bluez...${RC}"
|
||||
if ! command_exists bluetoothctl; then
|
||||
case ${PACKAGER} in
|
||||
pacman)
|
||||
|
@ -15,39 +15,26 @@ setupBluetooth() {
|
|||
;;
|
||||
esac
|
||||
else
|
||||
echo "Bluetoothctl is already installed."
|
||||
printf "%b\n" "${GREEN}Bluez is already installed.${RC}"
|
||||
fi
|
||||
|
||||
# Check if bluetooth service is running
|
||||
if ! systemctl is-active --quiet bluetooth; then
|
||||
echo "Bluetooth service is not running. Starting it now..."
|
||||
printf "%b\n" "${YELLOW}Bluetooth service is not running. Starting it now...${RC}"
|
||||
$ESCALATION_TOOL systemctl start bluetooth
|
||||
|
||||
if systemctl is-active --quiet bluetooth; then
|
||||
echo "bluetooth service started successfully."
|
||||
printf "%b\n" "${GREEN}Bluetooth service started successfully.${RC}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display colored text
|
||||
colored_echo() {
|
||||
local color=$1
|
||||
local text=$2
|
||||
case $color in
|
||||
red) echo -e "\033[31m$text\033[0m" ;;
|
||||
green) echo -e "\033[32m$text\033[0m" ;;
|
||||
yellow) echo -e "\033[33m$text\033[0m" ;;
|
||||
blue) echo -e "\033[34m$text\033[0m" ;;
|
||||
*) echo "$text" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to display the main menu
|
||||
main_menu() {
|
||||
while true; do
|
||||
clear
|
||||
colored_echo blue "Bluetooth Manager"
|
||||
colored_echo blue "================="
|
||||
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"
|
||||
|
@ -55,7 +42,7 @@ main_menu() {
|
|||
echo "5. Remove a device"
|
||||
echo "0. Exit"
|
||||
echo -n "Choose an option: "
|
||||
read -e choice
|
||||
read choice
|
||||
|
||||
case $choice in
|
||||
1) scan_devices ;;
|
||||
|
@ -64,7 +51,7 @@ main_menu() {
|
|||
4) disconnect_device ;;
|
||||
5) remove_device ;;
|
||||
0) exit 0 ;;
|
||||
*) colored_echo red "Invalid option. Please try again." ;;
|
||||
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
@ -72,13 +59,13 @@ main_menu() {
|
|||
# Function to scan for devices
|
||||
scan_devices() {
|
||||
clear
|
||||
colored_echo yellow "Scanning for devices..."
|
||||
printf "%b\n" "${YELLOW}Scanning for devices...${RC}"
|
||||
bluetoothctl --timeout 10 scan on
|
||||
devices=$(bluetoothctl devices)
|
||||
if [ -z "$devices" ]; then
|
||||
colored_echo red "No devices found."
|
||||
printf "%b\n" "${RED}No devices found.${RC}"
|
||||
else
|
||||
colored_echo green "Devices found:"
|
||||
printf "%b\n" "${GREEN}Devices found:${RC}"
|
||||
echo "$devices"
|
||||
fi
|
||||
echo "Press any key to return to the main menu..."
|
||||
|
@ -87,49 +74,51 @@ scan_devices() {
|
|||
|
||||
# Function to prompt for MAC address using numbers
|
||||
prompt_for_mac() {
|
||||
local action=$1
|
||||
local command=$2
|
||||
local prompt_msg=$3
|
||||
local success_msg=$4
|
||||
local failure_msg=$5
|
||||
action=$1
|
||||
command=$2
|
||||
prompt_msg=$3
|
||||
success_msg=$4
|
||||
failure_msg=$5
|
||||
|
||||
while true; do
|
||||
clear
|
||||
devices=$(bluetoothctl devices)
|
||||
if [ -z "$devices" ]; then
|
||||
colored_echo red "No devices available. Please scan for devices first."
|
||||
printf "%b\n" "${RED}No devices available. Please scan for devices first.${RC}"
|
||||
echo "Press any key to return to the main menu..."
|
||||
read -n 1
|
||||
return
|
||||
fi
|
||||
|
||||
# Display devices with numbers
|
||||
IFS=$'\n' read -r -a device_list <<<"$devices"
|
||||
for i in "${!device_list[@]}"; do
|
||||
echo "$((i+1)). ${device_list[$i]}"
|
||||
device_list=$(echo "$devices" | tr '\n' '\n')
|
||||
i=1
|
||||
echo "$device_list" | while IFS= read -r device; do
|
||||
echo "$i. $device"
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo "0. Exit to main menu"
|
||||
echo -n "$prompt_msg"
|
||||
read -e choice
|
||||
read choice
|
||||
|
||||
# Validate the choice
|
||||
if [[ $choice =~ ^[0-9]+$ ]] && [ "$choice" -le "${#device_list[@]}" ] && [ "$choice" -gt 0 ]; then
|
||||
device=${device_list[$((choice-1))]}
|
||||
if echo "$choice" | grep -qE '^[0-9]+$' && [ "$choice" -le "$((i - 1))" ] && [ "$choice" -gt 0 ]; then
|
||||
device=$(echo "$device_list" | sed -n "${choice}p")
|
||||
mac=$(echo "$device" | awk '{print $2}')
|
||||
if bluetoothctl info "$mac" > /dev/null 2>&1; then
|
||||
bluetoothctl $command "$mac" && {
|
||||
colored_echo green "$success_msg"
|
||||
printf "%b\n" "${GREEN}$success_msg${RC}"
|
||||
break
|
||||
} || {
|
||||
colored_echo red "$failure_msg"
|
||||
printf "%b\n" "${RED}$failure_msg${RC}"
|
||||
}
|
||||
else
|
||||
colored_echo red "Invalid MAC address. Please try again."
|
||||
printf "%b\n" "${RED}Invalid MAC address. Please try again.${RC}"
|
||||
fi
|
||||
elif [ "$choice" -eq 0 ]; then
|
||||
return
|
||||
else
|
||||
colored_echo red "Invalid choice. Please try again."
|
||||
printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
|
||||
fi
|
||||
done
|
||||
echo "Press any key to return to the main menu..."
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to auto-detect displays and set common resolution
|
||||
auto_detect_displays() {
|
||||
if confirm_action "Auto-detect displays and set common resolution?"; then
|
||||
|
@ -13,11 +15,19 @@ auto_detect_displays() {
|
|||
|
||||
for monitor in $monitors; do
|
||||
resolutions=$(get_unique_resolutions "$monitor")
|
||||
common_resolutions=$(comm -12 <(echo "$common_resolutions") <(echo "$resolutions"))
|
||||
temp_common_resolutions=$(mktemp)
|
||||
temp_resolutions=$(mktemp)
|
||||
|
||||
echo "$common_resolutions" > "$temp_common_resolutions"
|
||||
echo "$resolutions" > "$temp_resolutions"
|
||||
|
||||
common_resolutions=$(comm -12 "$temp_common_resolutions" "$temp_resolutions")
|
||||
|
||||
rm -f "$temp_common_resolutions" "$temp_resolutions"
|
||||
done
|
||||
|
||||
if [ -z "$common_resolutions" ]; then
|
||||
dialog --msgbox "No common resolution found among connected monitors." 10 60
|
||||
echo "No common resolution found among connected monitors."
|
||||
return
|
||||
fi
|
||||
|
||||
|
|
|
@ -2,38 +2,42 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to change monitor orientation
|
||||
change_orientation() {
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Change Monitor Orientation${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose a monitor to configure:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Change Monitor Orientation${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW}Choose a monitor to configure:${RC}"
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
read -p "Enter the number of the monitor: " monitor_choice
|
||||
|
||||
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection.${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
monitor_name="${monitor_array[monitor_choice - 1]}"
|
||||
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Set Orientation for $monitor_name${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose orientation:${RESET}"
|
||||
echo -e "1. ${CYAN}Normal${RESET}"
|
||||
echo -e "2. ${CYAN}Left${RESET}"
|
||||
echo -e "3. ${CYAN}Right${RESET}"
|
||||
echo -e "4. ${CYAN}Inverted${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Set Orientation for $monitor_name${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW}Choose orientation:${RC}"
|
||||
printf "%b\n" "1. ${GREEN}Normal${RC}"
|
||||
printf "%b\n" "2. ${GREEN}Left${RC}"
|
||||
printf "%b\n" "3. ${GREEN}Right${RC}"
|
||||
printf "%b\n" "4. ${GREEN}Inverted${RC}"
|
||||
|
||||
read -p "Enter the number of the orientation: " orientation_choice
|
||||
|
||||
|
@ -42,15 +46,15 @@ change_orientation() {
|
|||
2) orientation="left" ;;
|
||||
3) orientation="right" ;;
|
||||
4) orientation="inverted" ;;
|
||||
*) echo -e "${RED}Invalid selection.${RESET}"; return ;;
|
||||
*) printf "%b\n" "${RED}Invalid selection.${RC}"; return ;;
|
||||
esac
|
||||
|
||||
if confirm_action "Change orientation of ${CYAN}$monitor_name${RESET} to ${CYAN}$orientation${RESET}?"; then
|
||||
echo -e "${GREEN}Changing orientation of $monitor_name to $orientation${RESET}"
|
||||
if confirm_action "Change orientation of $monitor_name to $orientation?"; then
|
||||
printf "%b\n" "${GREEN}Changing orientation of $monitor_name to $orientation${RC}"
|
||||
execute_command "xrandr --output $monitor_name --rotate $orientation"
|
||||
echo -e "${GREEN}Orientation changed successfully.${RESET}"
|
||||
printf "%b\n" "${GREEN}Orientation changed successfully.${RC}"
|
||||
else
|
||||
echo -e "${RED}Action canceled.${RESET}"
|
||||
printf "%b\n" "${RED}Action canceled.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -2,54 +2,50 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
RESET='\033[0m'
|
||||
BOLD='\033[1m'
|
||||
RED='\033[31m'
|
||||
GREEN='\033[32m'
|
||||
YELLOW='\033[33m'
|
||||
BLUE='\033[34m'
|
||||
CYAN='\033[36m'
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to disable a monitor
|
||||
disable_monitor() {
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Disable Monitor${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose a monitor to disable:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Disable Monitor${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "Choose a monitor to disable:"
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
read -p "Enter the number of the monitor: " monitor_choice
|
||||
|
||||
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection.${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
monitor_name="${monitor_array[monitor_choice - 1]}"
|
||||
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
||||
|
||||
echo -e "${RED}Warning: Disabling the monitor will turn it off and may affect your display setup.${RESET}"
|
||||
printf "%b\n" "${RED}Warning: Disabling the monitor will turn it off and may affect your display setup.${RC}"
|
||||
|
||||
if confirm_action "Do you really want to disable ${CYAN}$monitor_name${RESET}?"; then
|
||||
echo -e "${GREEN}Disabling $monitor_name${RESET}"
|
||||
if confirm_action "Do you really want to disable ${GREEN}$monitor_name${RC}?"; then
|
||||
printf "%b\n" "${GREEN}Disabling $monitor_name${RC}"
|
||||
execute_command "xrandr --output $monitor_name --off"
|
||||
echo -e "${GREEN}Monitor $monitor_name disabled successfully.${RESET}"
|
||||
printf "%b\n" "${GREEN}Monitor $monitor_name disabled successfully.${RC}"
|
||||
else
|
||||
echo -e "${RED}Action canceled.${RESET}"
|
||||
printf "%b\n" "${RED}Action canceled.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to prompt for confirmation
|
||||
confirm_action() {
|
||||
local action="$1"
|
||||
echo -e "${BOLD}${YELLOW}$action${RESET}"
|
||||
action="$1"
|
||||
printf "%b\n" "${YELLOW}$action${RC}"
|
||||
read -p "Are you sure? (y/n): " confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
if echo "$confirm" | grep -qE '^[Yy]$'; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to duplicate displays
|
||||
duplicate_displays() {
|
||||
primary=$(detect_connected_monitors | head -n 1)
|
||||
for monitor in $(detect_connected_monitors | tail -n +2); do
|
||||
if confirm_action "Duplicate $monitor to $primary?"; then
|
||||
echo "Duplicating $monitor to $primary"
|
||||
execute_command "xrandr --output $monitor --same-as $primary"
|
||||
fi
|
||||
done
|
||||
primary=$(detect_connected_monitors | head -n 1)
|
||||
for monitor in $(detect_connected_monitors | tail -n +2); do
|
||||
if confirm_action "Duplicate $monitor to $primary?"; then
|
||||
printf "%b\n" "${GREEN}Duplicating $monitor to $primary${RC}"
|
||||
execute_command "xrandr --output $monitor --same-as $primary"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
duplicate_displays
|
||||
|
|
|
@ -2,55 +2,40 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
RESET='\033[0m'
|
||||
BOLD='\033[1m'
|
||||
RED='\033[31m'
|
||||
GREEN='\033[32m'
|
||||
YELLOW='\033[33m'
|
||||
BLUE='\033[34m'
|
||||
CYAN='\033[36m'
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to enable a monitor
|
||||
enable_monitor() {
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Enable Monitor${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose a monitor to enable:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Enable Monitor${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW}Choose a monitor to enable:${RC}"
|
||||
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
read -p "Enter the number of the monitor: " monitor_choice
|
||||
|
||||
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection.${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
monitor_name="${monitor_array[monitor_choice - 1]}"
|
||||
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
||||
|
||||
if confirm_action "Enable ${CYAN}$monitor_name${RESET}?"; then
|
||||
echo -e "${GREEN}Enabling $monitor_name${RESET}"
|
||||
if confirm_action "Enable $monitor_name?"; then
|
||||
printf "%b\n" "${GREEN}Enabling $monitor_name${RC}"
|
||||
execute_command "xrandr --output $monitor_name --auto"
|
||||
echo -e "${GREEN}Monitor $monitor_name enabled successfully.${RESET}"
|
||||
printf "%b\n" "${GREEN}Monitor $monitor_name enabled successfully.${RC}"
|
||||
else
|
||||
echo -e "${RED}Action canceled.${RESET}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to prompt for confirmation
|
||||
confirm_action() {
|
||||
local action="$1"
|
||||
echo -e "${BOLD}${YELLOW}$action${RESET}"
|
||||
read -p "Are you sure? (y/n): " confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
printf "%b\n" "${RED}Action canceled.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,22 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to extend displays
|
||||
extend_displays() {
|
||||
monitors=($(detect_connected_monitors))
|
||||
for ((i=1; i<${#monitors[@]}; i++)); do
|
||||
if confirm_action "Extend ${monitors[$i]} to the right of ${monitors[$((i-1))]}?"; then
|
||||
echo "Extending ${monitors[$i]} to the right of ${monitors[$((i-1))]}"
|
||||
execute_command "xrandr --output ${monitors[$i]} --right-of ${monitors[$((i-1))]}"
|
||||
monitors=$(detect_connected_monitors)
|
||||
monitor_array=$(echo "$monitors" | tr '\n' ' ')
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
if [ "$i" -gt 1 ]; then
|
||||
prev_monitor=$(echo "$monitor_array" | cut -d' ' -f$((i-1)))
|
||||
if confirm_action "Extend $monitor to the right of $prev_monitor?"; then
|
||||
printf "%b\n" "${GREEN}Extending $monitor to the right of $prev_monitor${RC}"
|
||||
execute_command "xrandr --output $monitor --right-of $prev_monitor"
|
||||
fi
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
@ -2,35 +2,39 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to manage monitor arrangement
|
||||
manage_arrangement() {
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Manage Monitor Arrangement${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose the monitor to arrange:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Manage Monitor Arrangement${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW}Choose the monitor to arrange:${RC}"
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
read -p "Enter the number of the monitor to arrange: " monitor_choice
|
||||
|
||||
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection.${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
monitor_name="${monitor_array[monitor_choice - 1]}"
|
||||
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
||||
|
||||
clear
|
||||
echo -e "${YELLOW}Choose position relative to other monitors:${RESET}"
|
||||
echo -e "1. ${CYAN}Left of${RESET}"
|
||||
echo -e "2. ${CYAN}Right of${RESET}"
|
||||
echo -e "3. ${CYAN}Above${RESET}"
|
||||
echo -e "4. ${CYAN}Below${RESET}"
|
||||
printf "%b\n" "${YELLOW}Choose position relative to other monitors:${RC}"
|
||||
printf "%b\n" "1. ${YELLOW}Left of${RC}"
|
||||
printf "%b\n" "2. ${YELLOW}Right of${RC}"
|
||||
printf "%b\n" "3. ${YELLOW}Above${RC}"
|
||||
printf "%b\n" "4. ${YELLOW}Below${RC}"
|
||||
|
||||
read -p "Enter the number of the position: " position_choice
|
||||
|
||||
|
@ -39,31 +43,31 @@ manage_arrangement() {
|
|||
2) position="--right-of" ;;
|
||||
3) position="--above" ;;
|
||||
4) position="--below" ;;
|
||||
*) echo -e "${RED}Invalid selection.${RESET}"; return ;;
|
||||
*) printf "%b\n" "${RED}Invalid selection.${RC}"; return ;;
|
||||
esac
|
||||
|
||||
echo -e "${YELLOW}Choose the reference monitor:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
if [[ "${monitor_array[i]}" != "$monitor_name" ]]; then
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}Choose the reference monitor:${RC}"
|
||||
for i in $monitor_array; do
|
||||
if [ "$i" != "$monitor_name" ]; then
|
||||
printf "%b\n" "$((i + 1)). ${YELLOW}$i${RC}"
|
||||
fi
|
||||
done
|
||||
|
||||
read -p "Enter the number of the reference monitor: " ref_choice
|
||||
|
||||
if ! [[ "$ref_choice" =~ ^[0-9]+$ ]] || (( ref_choice < 1 )) || (( ref_choice > ${#monitor_array[@]} )) || (( ref_choice == monitor_choice )); then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
if ! echo "$ref_choice" | grep -qE '^[0-9]+$' || [ "$ref_choice" -lt 1 ] || [ "$ref_choice" -gt "$((i - 1))" ] || [ "$ref_choice" -eq "$monitor_choice" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection.${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
ref_monitor="${monitor_array[ref_choice - 1]}"
|
||||
ref_monitor=$(echo "$monitor_array" | cut -d' ' -f"$ref_choice")
|
||||
|
||||
if confirm_action "Arrange ${CYAN}$monitor_name${RESET} ${position} ${CYAN}$ref_monitor${RESET}?"; then
|
||||
echo -e "${GREEN}Arranging $monitor_name ${position} $ref_monitor${RESET}"
|
||||
if confirm_action "Arrange ${YELLOW}$monitor_name${RC} ${position} ${YELLOW}$ref_monitor${RC}?"; then
|
||||
printf "%b\n" "${GREEN}Arranging $monitor_name ${position} $ref_monitor${RC}"
|
||||
execute_command "xrandr --output $monitor_name $position $ref_monitor"
|
||||
echo -e "${GREEN}Arrangement updated successfully.${RESET}"
|
||||
printf "%b\n" "${GREEN}Arrangement updated successfully.${RC}"
|
||||
else
|
||||
echo -e "${RED}Action canceled.${RESET}"
|
||||
printf "%b\n" "${RED}Action canceled.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -2,22 +2,24 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
# Function to reset scaling back to 1 (native resolution) for all monitors
|
||||
reset_scaling() {
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Reset Monitor Scaling to Native Resolution${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to Reset scaling back to 1 (native resolution) for all monitors
|
||||
Reset_scaling() {
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Reset Monitor Scaling to Native Resolution${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
for monitor in "${monitor_array[@]}"; do
|
||||
echo -e "${CYAN}Resetting scaling for $monitor to 1x1 (native resolution)${RESET}"
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "${CYAN}Resetting scaling for $monitor to 1x1 (native resolution)${RC}"
|
||||
execute_command "xrandr --output $monitor --scale 1x1"
|
||||
done
|
||||
|
||||
echo -e "${GREEN}All monitor scalings have been reset to 1x1.${RESET}"
|
||||
printf "%b\n" "${GREEN}All monitor scalings have been Reset to 1x1.${RC}"
|
||||
}
|
||||
|
||||
# Call the reset_scaling function
|
||||
reset_scaling
|
||||
# Call the Reset_scaling function
|
||||
Reset_scaling
|
||||
|
|
|
@ -2,42 +2,42 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to scale smaller monitors to the highest resolution of a bigger monitor
|
||||
scale_monitors() {
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Scale Monitors to Highest Resolution${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Scale Monitors to Highest Resolution${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
# Get the highest resolution among all monitors
|
||||
max_width=0
|
||||
max_height=0
|
||||
|
||||
for monitor in "${monitor_array[@]}"; do
|
||||
for monitor in $monitor_array; do
|
||||
res=$(xrandr | grep -A1 "^$monitor connected" | tail -1 | awk '{print $1}')
|
||||
width=$(echo $res | awk -Fx '{print $1}')
|
||||
height=$(echo $res | awk -Fx '{print $2}')
|
||||
width=$(echo "$res" | awk -Fx '{print $1}')
|
||||
height=$(echo "$res" | awk -Fx '{print $2}')
|
||||
|
||||
if (( width > max_width )); then
|
||||
if [ "$width" -gt "$max_width" ]; then
|
||||
max_width=$width
|
||||
fi
|
||||
|
||||
if (( height > max_height )); then
|
||||
if [ "$height" -gt "$max_height" ]; then
|
||||
max_height=$height
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "${CYAN}Highest resolution found: ${max_width}x${max_height}${RESET}"
|
||||
printf "%b\n" "${YELLOW}Highest resolution found: ${max_width}x${max_height}${RC}"
|
||||
|
||||
# Scale all monitors to the maximum resolution
|
||||
for monitor in "${monitor_array[@]}"; do
|
||||
echo -e "${CYAN}Scaling $monitor to ${max_width}x${max_height}${RESET}"
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "${YELLOW}Scaling $monitor to ${max_width}x${max_height}${RC}"
|
||||
execute_command "xrandr --output $monitor --scale-from ${max_width}x${max_height}"
|
||||
done
|
||||
|
||||
echo -e "${GREEN}Scaling complete. All monitors are now scaled to ${max_width}x${max_height}.${RESET}"
|
||||
printf "%b\n" "${GREEN}Scaling complete. All monitors are now scaled to ${max_width}x${max_height}.${RC}"
|
||||
}
|
||||
|
||||
# Call the scale_monitors function
|
||||
|
|
|
@ -2,35 +2,39 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to set a monitor as primary
|
||||
set_primary_monitor() {
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Set Primary Monitor${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose a monitor to set as primary:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Set Primary Monitor${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW}Choose a monitor to set as primary:${RC}"
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
read -p "Enter the number of the monitor: " monitor_choice
|
||||
|
||||
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection.${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
monitor_name="${monitor_array[monitor_choice - 1]}"
|
||||
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
||||
|
||||
if confirm_action "Set ${CYAN}$monitor_name${RESET} as the primary monitor?"; then
|
||||
echo -e "${GREEN}Setting $monitor_name as primary monitor${RESET}"
|
||||
if confirm_action "Set $monitor_name as the primary monitor?"; then
|
||||
printf "%b\n" "${GREEN}Setting $monitor_name as primary monitor${RC}"
|
||||
execute_command "xrandr --output $monitor_name --primary"
|
||||
echo -e "${GREEN}Monitor $monitor_name set as primary successfully.${RESET}"
|
||||
printf "%b\n" "${GREEN}Monitor $monitor_name set as primary successfully.${RC}"
|
||||
else
|
||||
echo -e "${RED}Action canceled.${RESET}"
|
||||
printf "%b\n" "${RED}Action canceled.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -2,73 +2,68 @@
|
|||
|
||||
. ./utility_functions.sh
|
||||
|
||||
RESET='\033[0m'
|
||||
BOLD='\033[1m'
|
||||
RED='\033[31m'
|
||||
GREEN='\033[32m'
|
||||
YELLOW='\033[33m'
|
||||
BLUE='\033[34m'
|
||||
CYAN='\033[36m'
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to set resolutions
|
||||
set_resolutions() {
|
||||
monitor_list=$(detect_connected_monitors)
|
||||
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"
|
||||
|
||||
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
||||
|
||||
while true; do
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Monitor Configuration${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose a monitor to configure:${RESET}"
|
||||
for i in "${!monitor_array[@]}"; do
|
||||
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Monitor Configuration${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
|
||||
printf "%b\n" "${YELLOW}Choose a monitor to configure:${RC}"
|
||||
i=1
|
||||
for monitor in $monitor_array; do
|
||||
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
read -p "Enter the choice (or 'q' to quit): " monitor_choice
|
||||
|
||||
if [[ "$monitor_choice" == "q" ]]; then
|
||||
echo -e "${RED}Exiting...${RESET}"
|
||||
if [ "$monitor_choice" = "q" ]; then
|
||||
printf "%b\n" "${RED}Exiting...${RC}"
|
||||
return
|
||||
fi
|
||||
|
||||
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then
|
||||
echo -e "${RED}Invalid selection. Please try again.${RESET}"
|
||||
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
|
||||
read -p "Press [Enter] to continue..."
|
||||
continue
|
||||
fi
|
||||
|
||||
monitor_name="${monitor_array[monitor_choice - 1]}"
|
||||
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
||||
resolutions=$(get_unique_resolutions "$monitor_name" | sort -rn -t'x' -k1,1 -k2,2)
|
||||
|
||||
# Create a temporary file with resolutions and indices
|
||||
temp_res_file=$(mktemp)
|
||||
echo "$resolutions" | awk '{print NR " " $0}' > "$temp_res_file"
|
||||
|
||||
# Read the resolutions into an associative array
|
||||
declare -A resolution_map
|
||||
while read -r index resolution; do
|
||||
resolution_map[$index]="$resolution"
|
||||
i=1
|
||||
while read -r resolution; do
|
||||
resolution_map[$i]="$resolution"
|
||||
i=$((i + 1))
|
||||
done < "$temp_res_file"
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${BLUE} Resolution Configuration for ${CYAN}$monitor_name${RESET}"
|
||||
echo -e "${BLUE}=========================================${RESET}"
|
||||
echo -e "${YELLOW}Choose resolution for $monitor_name:${RESET}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
printf "%b\n" "${YELLOW} Resolution Configuration for ${YELLOW}$monitor_name${RC}"
|
||||
printf "%b\n" "${YELLOW}=========================================${RC}"
|
||||
awk '{print $1 ". " $2}' "$temp_res_file"
|
||||
|
||||
while true; do
|
||||
read -p "Enter the choice (or 'q' to quit): " resolution_choice
|
||||
|
||||
if [[ "$resolution_choice" == "q" ]]; then
|
||||
echo -e "${RED}Exiting...${RESET}"
|
||||
if [ "$resolution_choice" = "q" ]; then
|
||||
printf "%b\n" "${RED}Exiting...${RC}"
|
||||
rm "$temp_res_file"
|
||||
return
|
||||
fi
|
||||
|
||||
if ! [[ "$resolution_choice" =~ ^[0-9]+$ ]] || (( resolution_choice < 1 )) || (( resolution_choice > ${#resolution_map[@]} )); then
|
||||
echo -e "${RED}Invalid selection. Please try again.${RESET}"
|
||||
if ! echo "$resolution_choice" | grep -qE '^[0-9]+$' || [ "$resolution_choice" -lt 1 ] || [ "$resolution_choice" -gt "$((i - 1))" ]; then
|
||||
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
|
||||
continue
|
||||
fi
|
||||
|
||||
|
@ -76,16 +71,15 @@ set_resolutions() {
|
|||
selected_resolution=${resolution_map[$resolution_choice]}
|
||||
|
||||
read -p "Set resolution for $monitor_name to $selected_resolution? (y/n): " confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo -e "${GREEN}Setting resolution for $monitor_name to $selected_resolution${RESET}"
|
||||
if echo "$confirm" | grep -qE '^[Yy]$'; then
|
||||
printf "%b\n" "${GREEN}Setting resolution for $monitor_name to $selected_resolution${RC}"
|
||||
execute_command "xrandr --output $monitor_name --mode $selected_resolution"
|
||||
break
|
||||
else
|
||||
echo -e "${RED}Action canceled. Please choose a different resolution.${RESET}"
|
||||
printf "%b\n" "${RED}Action canceled. Please choose a different resolution.${RC}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Clean up the temporary file
|
||||
rm "$temp_res_file"
|
||||
done
|
||||
}
|
||||
|
|
|
@ -2,42 +2,29 @@
|
|||
|
||||
. ../../common-script.sh
|
||||
|
||||
# Function to check bluetoothctl is installed
|
||||
# Function to check xrandr is installed
|
||||
setup_xrandr() {
|
||||
echo "Install xrandr if not already installed..."
|
||||
if ! command_exists xrandr; then
|
||||
case ${PACKAGER} in
|
||||
pacman)
|
||||
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm xorg-xrandr
|
||||
;;
|
||||
apt-get)
|
||||
$ESCALATION_TOOL "${PACKAGER}" install -y x11-xserver-utils
|
||||
;;
|
||||
*)
|
||||
$ESCALATION_TOOL "${PACKAGER}" install -y xorg-x11-server-utils
|
||||
;;
|
||||
pacman)
|
||||
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm xorg-xrandr
|
||||
;;
|
||||
apt-get)
|
||||
$ESCALATION_TOOL "${PACKAGER}" install -y x11-xserver-utils
|
||||
;;
|
||||
*)
|
||||
$ESCALATION_TOOL "${PACKAGER}" install -y xorg-x11-server-utils
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "xrandr is already installed."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display colored text
|
||||
colored_echo() {
|
||||
local color=$1
|
||||
local text=$2
|
||||
case $color in
|
||||
red) echo -e "\033[31m$text\033[0m" ;;
|
||||
green) echo -e "\033[32m$text\033[0m" ;;
|
||||
yellow) echo -e "\033[33m$text\033[0m" ;;
|
||||
blue) echo -e "\033[34m$text\033[0m" ;;
|
||||
*) echo "$text" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to execute xrandr commands and handle errors
|
||||
execute_command() {
|
||||
local command="$1"
|
||||
command="$1"
|
||||
echo "Executing: $command"
|
||||
eval "$command" 2>&1 | tee /tmp/xrandr.log | tail -n 20
|
||||
if [ $? -ne 0 ]; then
|
||||
|
@ -53,7 +40,7 @@ detect_connected_monitors() {
|
|||
|
||||
# Function to get resolutions for a monitor
|
||||
get_unique_resolutions() {
|
||||
local monitor="$1"
|
||||
monitor="$1"
|
||||
xrandr_output=$(xrandr)
|
||||
# Get available resolutions from xrandr without line limit
|
||||
available_resolutions=$(echo "$xrandr_output" | sed -n "/$monitor connected/,/^[^ ]/p" | grep -oP '\d+x\d+' | sort -u)
|
||||
|
@ -61,22 +48,34 @@ get_unique_resolutions() {
|
|||
# Define standard resolutions
|
||||
standard_resolutions="1920x1080 1280x720 1600x900 2560x1440 3840x2160"
|
||||
|
||||
temp_file=$(mktemp)
|
||||
echo "$available_resolutions" > "$temp_file"
|
||||
|
||||
# Filter standard resolutions to include only those available for the monitor
|
||||
filtered_standard_resolutions=$(echo "$standard_resolutions" | tr ' ' '\n' | grep -xF -f <(echo "$available_resolutions"))
|
||||
filtered_standard_resolutions=$(echo "$standard_resolutions" | tr ' ' '\n' | grep -xF -f "$temp_file")
|
||||
|
||||
rm "$temp_file"
|
||||
|
||||
available_res_file=$(mktemp)
|
||||
filtered_standard_res_file=$(mktemp)
|
||||
echo "$available_resolutions" | sort > "$available_res_file"
|
||||
echo "$filtered_standard_resolutions" | sort > "$filtered_standard_res_file"
|
||||
|
||||
# Get remaining available resolutions (excluding standard ones)
|
||||
remaining_resolutions=$(comm -23 <(echo "$available_resolutions" | sort) <(echo "$filtered_standard_resolutions" | sort))
|
||||
remaining_resolutions=$(comm -23 "$available_res_file" "$filtered_standard_res_file")
|
||||
|
||||
rm "$available_res_file" "$filtered_standard_res_file"
|
||||
|
||||
# Combine filtered standard resolutions and remaining resolutions, and limit to 10 results
|
||||
echo -e "$filtered_standard_resolutions\n$remaining_resolutions" | head -n 10
|
||||
printf "%b\n" "$filtered_standard_resolutions\n$remaining_resolutions" | head -n 10
|
||||
}
|
||||
|
||||
# Function to prompt for confirmation
|
||||
confirm_action() {
|
||||
local action="$1"
|
||||
action="$1"
|
||||
echo "$action"
|
||||
read -p "Are you sure? (y/n): " confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
if echo "$confirm" | grep -qE '^[Yy]$'; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# Function to check if NetworkManager is installed
|
||||
setupNetworkManager() {
|
||||
echo "Install NetworkManger if not already installed..."
|
||||
printf "%b\n" "${YELLOW}Installing NetworkManager...${RC}"
|
||||
if ! command_exists nmcli; then
|
||||
case ${PACKAGER} in
|
||||
pacman)
|
||||
|
@ -18,39 +18,26 @@ setupNetworkManager() {
|
|||
;;
|
||||
esac
|
||||
else
|
||||
echo "NetworkManager is already installed."
|
||||
printf "%b\n" "${YELLOW}NetworkManager is already installed.${RC}"
|
||||
fi
|
||||
|
||||
# Check if NetworkManager service is running
|
||||
if ! systemctl is-active --quiet NetworkManager; then
|
||||
echo "NetworkManager service is not running. Starting it now..."
|
||||
printf "%b\n" "${YELLOW}NetworkManager service is not running. Starting it now...${RC}"
|
||||
$ESCALATION_TOOL systemctl start NetworkManager
|
||||
|
||||
if systemctl is-active --quiet NetworkManager; then
|
||||
echo "NetworkManager service started successfully."
|
||||
printf "%b\n" "${GREEN}NetworkManager service started successfully.${RC}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display colored text
|
||||
colored_echo() {
|
||||
local color=$1
|
||||
local text=$2
|
||||
case $color in
|
||||
red) echo -e "\033[31m$text\033[0m" ;;
|
||||
green) echo -e "\033[32m$text\033[0m" ;;
|
||||
yellow) echo -e "\033[33m$text\033[0m" ;;
|
||||
blue) echo -e "\033[34m$text\033[0m" ;;
|
||||
*) echo "$text" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to display the main menu
|
||||
main_menu() {
|
||||
while true; do
|
||||
clear
|
||||
colored_echo blue "WiFi Manager"
|
||||
colored_echo blue "============"
|
||||
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"
|
||||
|
@ -59,7 +46,7 @@ main_menu() {
|
|||
echo "6. Remove a WiFi connection"
|
||||
echo "0. Exit"
|
||||
echo -n "Choose an option: "
|
||||
read -e choice
|
||||
read choice
|
||||
|
||||
case $choice in
|
||||
1) wifi_on ;;
|
||||
|
@ -69,7 +56,7 @@ main_menu() {
|
|||
5) disconnect_network ;;
|
||||
6) remove_network ;;
|
||||
0) exit 0 ;;
|
||||
*) colored_echo red "Invalid option. Please try again." ;;
|
||||
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
@ -77,12 +64,12 @@ main_menu() {
|
|||
# Function to scan for WiFi networks
|
||||
scan_networks() {
|
||||
clear
|
||||
colored_echo yellow "Scanning for WiFi networks..."
|
||||
printf "%b\n" "${YELLOW}Scanning for WiFi networks...${RC}"
|
||||
networks=$(nmcli -t -f SSID,BSSID,SIGNAL dev wifi list | head -n 10)
|
||||
if [ -z "$networks" ]; then
|
||||
colored_echo red "No networks found."
|
||||
printf "%b\n" "${RED}No networks found.${RC}"
|
||||
else
|
||||
colored_echo green "Top 10 Networks found:"
|
||||
printf "%b\n" "${GREEN}Top 10 Networks found:${RC}"
|
||||
echo "$networks" | sed 's/\\//g' | awk -F: '{printf("%d. SSID: %-25s \n", NR, $1)}'
|
||||
fi
|
||||
echo "Press any key to return to the main menu..."
|
||||
|
@ -92,11 +79,11 @@ scan_networks() {
|
|||
# Function to turn WiFi on
|
||||
wifi_on() {
|
||||
clear
|
||||
colored_echo yellow "Turning WiFi on..."
|
||||
printf "%b\n" "${YELLOW}Turning WiFi on...${RC}"
|
||||
nmcli radio wifi on && {
|
||||
colored_echo green "WiFi is now turned on."
|
||||
printf "%b\n" "${GREEN}WiFi is now turned on.${RC}"
|
||||
} || {
|
||||
colored_echo red "Failed to turn on WiFi."
|
||||
printf "%b\n" "${RED}Failed to turn on WiFi.${RC}"
|
||||
}
|
||||
echo "Press any key to return to the main menu..."
|
||||
read -n 1
|
||||
|
@ -105,11 +92,11 @@ wifi_on() {
|
|||
# Function to turn WiFi off
|
||||
wifi_off() {
|
||||
clear
|
||||
colored_echo yellow "Turning WiFi off..."
|
||||
printf "%b\n" "${YELLOW}Turning WiFi off...${RC}"
|
||||
nmcli radio wifi off && {
|
||||
colored_echo green "WiFi is now turned off."
|
||||
printf "%b\n" "${GREEN}WiFi is now turned off.${RC}"
|
||||
} || {
|
||||
colored_echo red "Failed to turn off WiFi."
|
||||
printf "%b\n" "${RED}Failed to turn off WiFi.${RC}"
|
||||
}
|
||||
echo "Press any key to return to the main menu..."
|
||||
read -n 1
|
||||
|
@ -117,64 +104,65 @@ wifi_off() {
|
|||
|
||||
# Function to prompt for WiFi network selection
|
||||
prompt_for_network() {
|
||||
local action=$1
|
||||
local prompt_msg=$2
|
||||
local success_msg=$3
|
||||
local failure_msg=$4
|
||||
action=$1
|
||||
prompt_msg=$2
|
||||
success_msg=$3
|
||||
failure_msg=$4
|
||||
|
||||
while true; do
|
||||
clear
|
||||
networks=$(nmcli -t -f SSID dev wifi list | head -n 10)
|
||||
if [ -z "$networks" ]; then
|
||||
colored_echo red "No networks available. Please scan for networks first."
|
||||
printf "%b\n" "${RED}No networks available. Please scan for networks first.${RC}"
|
||||
echo "Press any key to return to the main menu..."
|
||||
read -n 1
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
# Display networks with numbers
|
||||
IFS=$'\n' read -r -a network_list <<<"$networks"
|
||||
for i in "${!network_list[@]}"; do
|
||||
ssid=$(echo "${network_list[$i]}" | awk -F: '{print $1}')
|
||||
echo "$((i+1)). SSID: $ssid"
|
||||
i=1
|
||||
echo "$networks" | while IFS= read -r network; do
|
||||
ssid=$(echo "$network" | awk -F: '{print $1}')
|
||||
echo "$i. SSID: $ssid"
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo "0. Exit to main menu"
|
||||
echo -n "$prompt_msg"
|
||||
read -e choice
|
||||
read choice
|
||||
|
||||
# Validate the choice
|
||||
if [[ $choice =~ ^[0-9]+$ ]] && [ "$choice" -le "${#network_list[@]}" ] && [ "$choice" -gt 0 ]; then
|
||||
network=${network_list[$((choice-1))]}
|
||||
if echo "$choice" | grep -qE '^[0-9]+$' && [ "$choice" -le "$((i - 1))" ] && [ "$choice" -gt 0 ]; then
|
||||
network=$(echo "$networks" | sed -n "${choice}p")
|
||||
ssid=$(echo "$network" | awk -F: '{print $1}')
|
||||
if [ "$action" == "connect" ]; then
|
||||
if [ "$action" = "connect" ]; then
|
||||
echo -n "Enter password for SSID $ssid: "
|
||||
read -s password
|
||||
echo
|
||||
nmcli dev wifi connect "$ssid" password "$password" && {
|
||||
colored_echo green "$success_msg"
|
||||
printf "%b\n" "${GREEN}$success_msg${RC}"
|
||||
break
|
||||
} || {
|
||||
colored_echo red "$failure_msg"
|
||||
printf "%b\n" "${RED}$failure_msg${RC}"
|
||||
}
|
||||
elif [ "$action" == "disconnect" ]; then
|
||||
elif [ "$action" = "disconnect" ]; then
|
||||
nmcli connection down "$ssid" && {
|
||||
colored_echo green "$success_msg"
|
||||
printf "%b\n" "${GREEN}$success_msg${RC}"
|
||||
break
|
||||
} || {
|
||||
colored_echo red "$failure_msg"
|
||||
printf "%b\n" "${RED}$failure_msg${RC}"
|
||||
}
|
||||
elif [ "$action" == "remove" ]; then
|
||||
elif [ "$action" = "remove" ]; then
|
||||
nmcli connection delete "$ssid" && {
|
||||
colored_echo green "$success_msg"
|
||||
printf "%b\n" "${GREEN}$success_msg${RC}"
|
||||
break
|
||||
} || {
|
||||
colored_echo red "$failure_msg"
|
||||
printf "%b\n" "${RED}$failure_msg${RC}"
|
||||
}
|
||||
fi
|
||||
elif [ "$choice" -eq 0 ]; then
|
||||
return
|
||||
else
|
||||
colored_echo red "Invalid choice. Please try again."
|
||||
printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
|
||||
fi
|
||||
done
|
||||
echo "Press any key to return to the main menu..."
|
||||
|
|
Loading…
Reference in New Issue
Block a user