Merge pull request #282 from nnyyxxxx/testing-6

Remove every bashism
This commit is contained in:
Chris Titus 2024-09-15 18:47:26 -05:00 committed by GitHub
commit 43740a48c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 378 additions and 422 deletions

View File

@ -1,4 +1,5 @@
#!/bin/sh -e #!/bin/sh -e
. ../common-script.sh . ../common-script.sh
makeDWM() { makeDWM() {
@ -114,7 +115,7 @@ picom_animations() {
fi fi
# Install the built binary # 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" echo "Failed to install the built binary"
return 1 return 1
fi fi
@ -192,8 +193,8 @@ setupDisplayManager() {
echo "Setting up Display Manager" echo "Setting up Display Manager"
currentdm="none" currentdm="none"
for dm in gdm sddm lightdm; do for dm in gdm sddm lightdm; do
if systemctl is-active --quiet $dm.service; then if systemctl is-active --quiet "$dm.service"; then
currentdm=$dm currentdm="$dm"
break break
fi fi
done done
@ -203,13 +204,13 @@ setupDisplayManager() {
echo "No display manager found, installing $DM" echo "No display manager found, installing $DM"
case "$PACKAGER" in case "$PACKAGER" in
pacman) pacman)
$ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm $DM $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm "$DM"
;; ;;
apt) apt)
$ESCALATION_TOOL "$PACKAGER" install -y $DM $ESCALATION_TOOL "$PACKAGER" install -y "$DM"
;; ;;
dnf) dnf)
$ESCALATION_TOOL "$PACKAGER" install -y $DM $ESCALATION_TOOL "$PACKAGER" install -y "$DM"
;; ;;
*) *)
echo "Unsupported package manager: $PACKAGER" echo "Unsupported package manager: $PACKAGER"
@ -217,78 +218,48 @@ setupDisplayManager() {
;; ;;
esac esac
echo "$DM installed successfully" echo "$DM installed successfully"
systemctl enable $DM systemctl enable "$DM"
# Clear the screen
clear
# Prompt user for auto-login # Prompt user for auto-login
echo "Do you want to enable auto-login?" # Using printf instead of echo -n as It's more posix-compliant.
echo "Use arrow keys or j/k to navigate, Enter to select" printf "Do you want to enable auto-login? (Y/n) "
options=("Yes" "No") read -r answer
selected=0 case "$answer" in
[Yy]*)
# Function to print menu
print_menu() {
for i in "${!options[@]}"; do
if [ $i -eq $selected ]; then
echo "> ${options[$i]}"
else
echo " ${options[$i]}"
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" echo "Configuring SDDM for autologin"
SDDM_CONF="/etc/sddm.conf" SDDM_CONF="/etc/sddm.conf"
if [ ! -f "$SDDM_CONF" ]; then if [ ! -f "$SDDM_CONF" ]; then
echo "[Autologin]" | sudo tee -a "$SDDM_CONF" echo "[Autologin]" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "User=$USER" | sudo tee -a "$SDDM_CONF" echo "User=$USER" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "Session=dwm" | sudo tee -a "$SDDM_CONF" echo "Session=dwm" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
else else
sudo sed -i '/^\[Autologin\]/d' "$SDDM_CONF" $ESCALATION_TOOL sed -i '/^\[Autologin\]/d' "$SDDM_CONF"
sudo sed -i '/^User=/d' "$SDDM_CONF" $ESCALATION_TOOL sed -i '/^User=/d' "$SDDM_CONF"
sudo sed -i '/^Session=/d' "$SDDM_CONF" $ESCALATION_TOOL sed -i '/^Session=/d' "$SDDM_CONF"
echo "[Autologin]" | sudo tee -a "$SDDM_CONF" echo "[Autologin]" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "User=$USER" | sudo tee -a "$SDDM_CONF" echo "User=$USER" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "Session=dwm" | sudo tee -a "$SDDM_CONF" echo "Session=dwm" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
fi fi
echo "Checking if autologin group exists" echo "Checking if autologin group exists"
if ! getent group autologin > /dev/null; then if ! getent group autologin > /dev/null; then
echo "Creating autologin group" echo "Creating autologin group"
sudo groupadd autologin $ESCALATION_TOOL groupadd autologin
else else
echo "Autologin group already exists" echo "Autologin group already exists"
fi fi
echo "Adding user with UID 1000 to autologin group" echo "Adding user with UID 1000 to autologin group"
USER_UID_1000=$(getent passwd 1000 | cut -d: -f1) USER_UID_1000=$(getent passwd 1000 | cut -d: -f1)
if [ -n "$USER_UID_1000" ]; then if [ -n "$USER_UID_1000" ]; then
sudo usermod -aG autologin "$USER_UID_1000" $ESCALATION_TOOL usermod -aG autologin "$USER_UID_1000"
echo "User $USER_UID_1000 added to autologin group" echo "User $USER_UID_1000 added to autologin group"
else else
echo "No user with UID 1000 found - Auto login not possible" echo "No user with UID 1000 found - Auto login not possible"
fi fi
else ;;
*)
echo "Auto-login configuration skipped" echo "Auto-login configuration skipped"
fi ;;
esac
fi fi

View File

@ -54,7 +54,7 @@ checkEscalationTool() {
fi fi
done 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 exit 1
fi fi
} }
@ -82,7 +82,7 @@ checkPackageManager() {
done done
if [ -z "${PACKAGER}" ]; then 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 exit 1
fi fi
} }

View File

@ -19,7 +19,7 @@ installPkg() {
} }
configureUFW() { 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" echo "Disabling UFW"
$ESCALATION_TOOL ufw disable $ESCALATION_TOOL ufw disable
@ -40,7 +40,7 @@ configureUFW() {
$ESCALATION_TOOL ufw default allow outgoing $ESCALATION_TOOL ufw default allow outgoing
$ESCALATION_TOOL ufw enable $ESCALATION_TOOL ufw enable
echo -e "${GREEN}Enabled Firewall with Baselines!${RC}" printf "%b\n" "${GREEN}Enabled Firewall with Baselines!${RC}"
} }
checkEnv checkEnv

View File

@ -5,7 +5,7 @@
installDepend() { installDepend() {
## Check for dependencies. ## Check for dependencies.
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq' 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 case $PACKAGER in
pacman) pacman)
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then

View File

@ -4,7 +4,7 @@
installDepend() { installDepend() {
## Check for dependencies. ## Check for dependencies.
echo -e "${YELLOW}Installing dependencies...${RC}" printf "%b\n" "${YELLOW}Installing dependencies...${RC}"
if [ "$PACKAGER" = "pacman" ]; then if [ "$PACKAGER" = "pacman" ]; then
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
echo "[multilib]" | $ESCALATION_TOOL tee -a /etc/pacman.conf echo "[multilib]" | $ESCALATION_TOOL tee -a /etc/pacman.conf

View File

@ -3,7 +3,7 @@
. ../common-script.sh . ../common-script.sh
install_theme_tools() { 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 case $PACKAGER in
apt-get) apt-get)
$ESCALATION_TOOL apt-get update $ESCALATION_TOOL apt-get update
@ -21,14 +21,14 @@ install_theme_tools() {
$ESCALATION_TOOL pacman -S --needed --noconfirm qt6ct kvantum $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 exit 1
;; ;;
esac esac
} }
configure_qt6ct() { configure_qt6ct() {
printf "${YELLOW}Configuring qt6ct...${RC}\n" printf "%b\n" "${YELLOW}Configuring qt6ct...${RC}\n"
mkdir -p "$HOME/.config/qt6ct" mkdir -p "$HOME/.config/qt6ct"
cat <<EOF > "$HOME/.config/qt6ct/qt6ct.conf" cat <<EOF > "$HOME/.config/qt6ct/qt6ct.conf"
[Appearance] [Appearance]
@ -36,26 +36,26 @@ style=kvantum
color_scheme=default color_scheme=default
icon_theme=breeze icon_theme=breeze
EOF EOF
printf "${GREEN}qt6ct configured successfully.${RC}\n" printf "%b\n" "${GREEN}qt6ct configured successfully.${RC}\n"
# Add QT_QPA_PLATFORMTHEME to /etc/environment # Add QT_QPA_PLATFORMTHEME to /etc/environment
if ! grep -q "QT_QPA_PLATFORMTHEME=qt6ct" /etc/environment; then 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 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 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 fi
} }
configure_kvantum() { configure_kvantum() {
printf "${YELLOW}Configuring Kvantum...${RC}\n" printf "%b\n" "${YELLOW}Configuring Kvantum...${RC}\n"
mkdir -p "$HOME/.config/Kvantum" mkdir -p "$HOME/.config/Kvantum"
cat <<EOF > "$HOME/.config/Kvantum/kvantum.kvconfig" cat <<EOF > "$HOME/.config/Kvantum/kvantum.kvconfig"
[General] [General]
theme=Breeze theme=Breeze
EOF EOF
printf "${GREEN}Kvantum configured successfully.${RC}\n" printf "%b\n" "${GREEN}Kvantum configured successfully.${RC}\n"
} }
checkEnv checkEnv

View File

@ -1,6 +1,6 @@
#!/bin/sh -e #!/bin/sh -e
. "$(dirname "$0")/../../common-script.sh" . ../../common-script.sh
installDepend() { installDepend() {
case $PACKAGER in case $PACKAGER in

View File

@ -1,6 +1,6 @@
#!/bin/sh -e #!/bin/sh -e
. "$(dirname "$0")/../../common-script.sh" . ../../common-script.sh
installDepend() { installDepend() {
case $PACKAGER in case $PACKAGER in

View File

@ -1,13 +1,13 @@
#!/bin/sh -e #!/bin/sh -e
. "$(dirname "$0")/../../common-script.sh" . ../../common-script.sh
# https://rpmfusion.org/Configuration # https://rpmfusion.org/Configuration
installRPMFusion() { installRPMFusion() {
case $PACKAGER in case $PACKAGER in
dnf) 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..." 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" 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 $ESCALATION_TOOL "$PACKAGER" config-manager --enable fedora-cisco-openh264

View File

@ -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} $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 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 $ESCALATION_TOOL cp /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
fi fi
;; ;;
@ -28,7 +28,7 @@ fastUpdate() {
apt-get|nala) apt-get|nala)
$ESCALATION_TOOL apt-get update $ESCALATION_TOOL apt-get update
if ! command_exists nala; then 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 fi
if [ "${PACKAGER}" = "nala" ]; then if [ "${PACKAGER}" = "nala" ]; then
@ -54,14 +54,14 @@ fastUpdate() {
$ESCALATION_TOOL ${PACKAGER} -Syu $ESCALATION_TOOL ${PACKAGER} -Syu
;; ;;
*) *)
echo -e "${RED}Unsupported package manager: $PACKAGER${RC}" printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
exit 1 exit 1
;; ;;
esac esac
} }
updateSystem() { updateSystem() {
echo -e "${GREEN}Updating system${RC}" printf "%b\n" "${GREEN}Updating system${RC}"
case ${PACKAGER} in case ${PACKAGER} in
nala|apt-get) nala|apt-get)
$ESCALATION_TOOL "${PACKAGER}" update -y $ESCALATION_TOOL "${PACKAGER}" update -y
@ -83,7 +83,7 @@ updateSystem() {
$ESCALATION_TOOL ${PACKAGER} -Syu $ESCALATION_TOOL ${PACKAGER} -Syu
;; ;;
*) *)
echo -e "${RED}Unsupported package manager: ${PACKAGER}${RC}" printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
exit 1 exit 1
;; ;;
esac esac

View File

@ -2,9 +2,9 @@
. ../common-script.sh . ../common-script.sh
# Function to check bluetoothctl is installed # Function to check Bluez is installed
setupBluetooth() { setupBluetooth() {
echo "Install bluetoothctl if not already installed..." printf "%b\n" "${YELLOW}Installing Bluez...${RC}"
if ! command_exists bluetoothctl; then if ! command_exists bluetoothctl; then
case ${PACKAGER} in case ${PACKAGER} in
pacman) pacman)
@ -15,39 +15,26 @@ setupBluetooth() {
;; ;;
esac esac
else else
echo "Bluetoothctl is already installed." printf "%b\n" "${GREEN}Bluez is already installed.${RC}"
fi fi
# Check if bluetooth service is running # Check if bluetooth service is running
if ! systemctl is-active --quiet bluetooth; then 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 $ESCALATION_TOOL systemctl start bluetooth
if systemctl is-active --quiet bluetooth; then if systemctl is-active --quiet bluetooth; then
echo "bluetooth service started successfully." printf "%b\n" "${GREEN}Bluetooth service started successfully.${RC}"
fi fi
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 # Function to display the main menu
main_menu() { main_menu() {
while true; do while true; do
clear clear
colored_echo blue "Bluetooth Manager" printf "%b\n" "${YELLOW}Bluetooth Manager${RC}"
colored_echo blue "=================" printf "%b\n" "${YELLOW}=================${RC}"
echo "1. Scan for devices" echo "1. Scan for devices"
echo "2. Pair with a device" echo "2. Pair with a device"
echo "3. Connect to a device" echo "3. Connect to a device"
@ -55,7 +42,7 @@ main_menu() {
echo "5. Remove a device" echo "5. Remove a device"
echo "0. Exit" echo "0. Exit"
echo -n "Choose an option: " echo -n "Choose an option: "
read -e choice read choice
case $choice in case $choice in
1) scan_devices ;; 1) scan_devices ;;
@ -64,7 +51,7 @@ main_menu() {
4) disconnect_device ;; 4) disconnect_device ;;
5) remove_device ;; 5) remove_device ;;
0) exit 0 ;; 0) exit 0 ;;
*) colored_echo red "Invalid option. Please try again." ;; *) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
esac esac
done done
} }
@ -72,13 +59,13 @@ main_menu() {
# Function to scan for devices # Function to scan for devices
scan_devices() { scan_devices() {
clear clear
colored_echo yellow "Scanning for devices..." printf "%b\n" "${YELLOW}Scanning for devices...${RC}"
bluetoothctl --timeout 10 scan on bluetoothctl --timeout 10 scan on
devices=$(bluetoothctl devices) devices=$(bluetoothctl devices)
if [ -z "$devices" ]; then if [ -z "$devices" ]; then
colored_echo red "No devices found." printf "%b\n" "${RED}No devices found.${RC}"
else else
colored_echo green "Devices found:" printf "%b\n" "${GREEN}Devices found:${RC}"
echo "$devices" echo "$devices"
fi fi
echo "Press any key to return to the main menu..." echo "Press any key to return to the main menu..."
@ -87,49 +74,51 @@ scan_devices() {
# Function to prompt for MAC address using numbers # Function to prompt for MAC address using numbers
prompt_for_mac() { prompt_for_mac() {
local action=$1 action=$1
local command=$2 command=$2
local prompt_msg=$3 prompt_msg=$3
local success_msg=$4 success_msg=$4
local failure_msg=$5 failure_msg=$5
while true; do while true; do
clear clear
devices=$(bluetoothctl devices) devices=$(bluetoothctl devices)
if [ -z "$devices" ]; then 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..." echo "Press any key to return to the main menu..."
read -n 1 read -n 1
return return
fi fi
# Display devices with numbers # Display devices with numbers
IFS=$'\n' read -r -a device_list <<<"$devices" device_list=$(echo "$devices" | tr '\n' '\n')
for i in "${!device_list[@]}"; do i=1
echo "$((i+1)). ${device_list[$i]}" echo "$device_list" | while IFS= read -r device; do
echo "$i. $device"
i=$((i + 1))
done done
echo "0. Exit to main menu" echo "0. Exit to main menu"
echo -n "$prompt_msg" echo -n "$prompt_msg"
read -e choice read choice
# Validate the choice # Validate the choice
if [[ $choice =~ ^[0-9]+$ ]] && [ "$choice" -le "${#device_list[@]}" ] && [ "$choice" -gt 0 ]; then if echo "$choice" | grep -qE '^[0-9]+$' && [ "$choice" -le "$((i - 1))" ] && [ "$choice" -gt 0 ]; then
device=${device_list[$((choice-1))]} device=$(echo "$device_list" | sed -n "${choice}p")
mac=$(echo "$device" | awk '{print $2}') mac=$(echo "$device" | awk '{print $2}')
if bluetoothctl info "$mac" > /dev/null 2>&1; then if bluetoothctl info "$mac" > /dev/null 2>&1; then
bluetoothctl $command "$mac" && { bluetoothctl $command "$mac" && {
colored_echo green "$success_msg" printf "%b\n" "${GREEN}$success_msg${RC}"
break break
} || { } || {
colored_echo red "$failure_msg" printf "%b\n" "${RED}$failure_msg${RC}"
} }
else else
colored_echo red "Invalid MAC address. Please try again." printf "%b\n" "${RED}Invalid MAC address. Please try again.${RC}"
fi fi
elif [ "$choice" -eq 0 ]; then elif [ "$choice" -eq 0 ]; then
return return
else else
colored_echo red "Invalid choice. Please try again." printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
fi fi
done done
echo "Press any key to return to the main menu..." echo "Press any key to return to the main menu..."

View File

@ -2,6 +2,8 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to auto-detect displays and set common resolution # Function to auto-detect displays and set common resolution
auto_detect_displays() { auto_detect_displays() {
if confirm_action "Auto-detect displays and set common resolution?"; then if confirm_action "Auto-detect displays and set common resolution?"; then
@ -13,11 +15,19 @@ auto_detect_displays() {
for monitor in $monitors; do for monitor in $monitors; do
resolutions=$(get_unique_resolutions "$monitor") 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 done
if [ -z "$common_resolutions" ]; then 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 return
fi fi

View File

@ -2,38 +2,42 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to change monitor orientation # Function to change monitor orientation
change_orientation() { change_orientation() {
monitor_list=$(detect_connected_monitors) monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Change Monitor Orientation${RESET}" printf "%b\n" "${YELLOW} Change Monitor Orientation${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose a monitor to configure:${RESET}" printf "%b\n" "${YELLOW}Choose a monitor to configure:${RC}"
for i in "${!monitor_array[@]}"; do i=1
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" for monitor in $monitor_array; do
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
i=$((i + 1))
done done
read -p "Enter the number of the monitor: " monitor_choice read -p "Enter the number of the monitor: " monitor_choice
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection.${RESET}" printf "%b\n" "${RED}Invalid selection.${RC}"
return return
fi fi
monitor_name="${monitor_array[monitor_choice - 1]}" monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Set Orientation for $monitor_name${RESET}" printf "%b\n" "${YELLOW} Set Orientation for $monitor_name${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose orientation:${RESET}" printf "%b\n" "${YELLOW}Choose orientation:${RC}"
echo -e "1. ${CYAN}Normal${RESET}" printf "%b\n" "1. ${GREEN}Normal${RC}"
echo -e "2. ${CYAN}Left${RESET}" printf "%b\n" "2. ${GREEN}Left${RC}"
echo -e "3. ${CYAN}Right${RESET}" printf "%b\n" "3. ${GREEN}Right${RC}"
echo -e "4. ${CYAN}Inverted${RESET}" printf "%b\n" "4. ${GREEN}Inverted${RC}"
read -p "Enter the number of the orientation: " orientation_choice read -p "Enter the number of the orientation: " orientation_choice
@ -42,15 +46,15 @@ change_orientation() {
2) orientation="left" ;; 2) orientation="left" ;;
3) orientation="right" ;; 3) orientation="right" ;;
4) orientation="inverted" ;; 4) orientation="inverted" ;;
*) echo -e "${RED}Invalid selection.${RESET}"; return ;; *) printf "%b\n" "${RED}Invalid selection.${RC}"; return ;;
esac esac
if confirm_action "Change orientation of ${CYAN}$monitor_name${RESET} to ${CYAN}$orientation${RESET}?"; then if confirm_action "Change orientation of $monitor_name to $orientation?"; then
echo -e "${GREEN}Changing orientation of $monitor_name to $orientation${RESET}" printf "%b\n" "${GREEN}Changing orientation of $monitor_name to $orientation${RC}"
execute_command "xrandr --output $monitor_name --rotate $orientation" execute_command "xrandr --output $monitor_name --rotate $orientation"
echo -e "${GREEN}Orientation changed successfully.${RESET}" printf "%b\n" "${GREEN}Orientation changed successfully.${RC}"
else else
echo -e "${RED}Action canceled.${RESET}" printf "%b\n" "${RED}Action canceled.${RC}"
fi fi
} }

View File

@ -2,54 +2,50 @@
. ./utility_functions.sh . ./utility_functions.sh
RESET='\033[0m' . ../../common-script.sh
BOLD='\033[1m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
CYAN='\033[36m'
# Function to disable a monitor # Function to disable a monitor
disable_monitor() { disable_monitor() {
monitor_list=$(detect_connected_monitors) monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Disable Monitor${RESET}" printf "%b\n" "${YELLOW} Disable Monitor${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose a monitor to disable:${RESET}" printf "%b\n" "Choose a monitor to disable:"
for i in "${!monitor_array[@]}"; do i=1
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" for monitor in $monitor_array; do
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
i=$((i + 1))
done done
read -p "Enter the number of the monitor: " monitor_choice read -p "Enter the number of the monitor: " monitor_choice
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection.${RESET}" printf "%b\n" "${RED}Invalid selection.${RC}"
return return
fi 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 if confirm_action "Do you really want to disable ${GREEN}$monitor_name${RC}?"; then
echo -e "${GREEN}Disabling $monitor_name${RESET}" printf "%b\n" "${GREEN}Disabling $monitor_name${RC}"
execute_command "xrandr --output $monitor_name --off" 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 else
echo -e "${RED}Action canceled.${RESET}" printf "%b\n" "${RED}Action canceled.${RC}"
fi fi
} }
# Function to prompt for confirmation # Function to prompt for confirmation
confirm_action() { confirm_action() {
local action="$1" action="$1"
echo -e "${BOLD}${YELLOW}$action${RESET}" printf "%b\n" "${YELLOW}$action${RC}"
read -p "Are you sure? (y/n): " confirm read -p "Are you sure? (y/n): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then if echo "$confirm" | grep -qE '^[Yy]$'; then
return 0 return 0
else else
return 1 return 1

View File

@ -2,12 +2,14 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to duplicate displays # Function to duplicate displays
duplicate_displays() { duplicate_displays() {
primary=$(detect_connected_monitors | head -n 1) primary=$(detect_connected_monitors | head -n 1)
for monitor in $(detect_connected_monitors | tail -n +2); do for monitor in $(detect_connected_monitors | tail -n +2); do
if confirm_action "Duplicate $monitor to $primary?"; then if confirm_action "Duplicate $monitor to $primary?"; then
echo "Duplicating $monitor to $primary" printf "%b\n" "${GREEN}Duplicating $monitor to $primary${RC}"
execute_command "xrandr --output $monitor --same-as $primary" execute_command "xrandr --output $monitor --same-as $primary"
fi fi
done done

View File

@ -2,55 +2,40 @@
. ./utility_functions.sh . ./utility_functions.sh
RESET='\033[0m' . ../../common-script.sh
BOLD='\033[1m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
CYAN='\033[36m'
# Function to enable a monitor # Function to enable a monitor
enable_monitor() { enable_monitor() {
monitor_list=$(detect_connected_monitors) monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Enable Monitor${RESET}" printf "%b\n" "${YELLOW} Enable Monitor${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose a monitor to enable:${RESET}" printf "%b\n" "${YELLOW}Choose a monitor to enable:${RC}"
for i in "${!monitor_array[@]}"; do
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" i=1
for monitor in $monitor_array; do
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
i=$((i + 1))
done done
read -p "Enter the number of the monitor: " monitor_choice read -p "Enter the number of the monitor: " monitor_choice
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection.${RESET}" printf "%b\n" "${RED}Invalid selection.${RC}"
return return
fi 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 if confirm_action "Enable $monitor_name?"; then
echo -e "${GREEN}Enabling $monitor_name${RESET}" printf "%b\n" "${GREEN}Enabling $monitor_name${RC}"
execute_command "xrandr --output $monitor_name --auto" 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 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}"
read -p "Are you sure? (y/n): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi fi
} }

View File

@ -2,14 +2,22 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to extend displays # Function to extend displays
extend_displays() { extend_displays() {
monitors=($(detect_connected_monitors)) monitors=$(detect_connected_monitors)
for ((i=1; i<${#monitors[@]}; i++)); do monitor_array=$(echo "$monitors" | tr '\n' ' ')
if confirm_action "Extend ${monitors[$i]} to the right of ${monitors[$((i-1))]}?"; then i=1
echo "Extending ${monitors[$i]} to the right of ${monitors[$((i-1))]}" for monitor in $monitor_array; do
execute_command "xrandr --output ${monitors[$i]} --right-of ${monitors[$((i-1))]}" 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
fi
i=$((i + 1))
done done
} }

View File

@ -2,35 +2,39 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to manage monitor arrangement # Function to manage monitor arrangement
manage_arrangement() { manage_arrangement() {
monitor_list=$(detect_connected_monitors) monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Manage Monitor Arrangement${RESET}" printf "%b\n" "${YELLOW} Manage Monitor Arrangement${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose the monitor to arrange:${RESET}" printf "%b\n" "${YELLOW}Choose the monitor to arrange:${RC}"
for i in "${!monitor_array[@]}"; do i=1
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" for monitor in $monitor_array; do
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
i=$((i + 1))
done done
read -p "Enter the number of the monitor to arrange: " monitor_choice 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 if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection.${RESET}" printf "%b\n" "${RED}Invalid selection.${RC}"
return return
fi fi
monitor_name="${monitor_array[monitor_choice - 1]}" monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
clear clear
echo -e "${YELLOW}Choose position relative to other monitors:${RESET}" printf "%b\n" "${YELLOW}Choose position relative to other monitors:${RC}"
echo -e "1. ${CYAN}Left of${RESET}" printf "%b\n" "1. ${YELLOW}Left of${RC}"
echo -e "2. ${CYAN}Right of${RESET}" printf "%b\n" "2. ${YELLOW}Right of${RC}"
echo -e "3. ${CYAN}Above${RESET}" printf "%b\n" "3. ${YELLOW}Above${RC}"
echo -e "4. ${CYAN}Below${RESET}" printf "%b\n" "4. ${YELLOW}Below${RC}"
read -p "Enter the number of the position: " position_choice read -p "Enter the number of the position: " position_choice
@ -39,31 +43,31 @@ manage_arrangement() {
2) position="--right-of" ;; 2) position="--right-of" ;;
3) position="--above" ;; 3) position="--above" ;;
4) position="--below" ;; 4) position="--below" ;;
*) echo -e "${RED}Invalid selection.${RESET}"; return ;; *) printf "%b\n" "${RED}Invalid selection.${RC}"; return ;;
esac esac
echo -e "${YELLOW}Choose the reference monitor:${RESET}" printf "%b\n" "${YELLOW}Choose the reference monitor:${RC}"
for i in "${!monitor_array[@]}"; do for i in $monitor_array; do
if [[ "${monitor_array[i]}" != "$monitor_name" ]]; then if [ "$i" != "$monitor_name" ]; then
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" printf "%b\n" "$((i + 1)). ${YELLOW}$i${RC}"
fi fi
done done
read -p "Enter the number of the reference monitor: " ref_choice 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 if ! echo "$ref_choice" | grep -qE '^[0-9]+$' || [ "$ref_choice" -lt 1 ] || [ "$ref_choice" -gt "$((i - 1))" ] || [ "$ref_choice" -eq "$monitor_choice" ]; then
echo -e "${RED}Invalid selection.${RESET}" printf "%b\n" "${RED}Invalid selection.${RC}"
return return
fi 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 if confirm_action "Arrange ${YELLOW}$monitor_name${RC} ${position} ${YELLOW}$ref_monitor${RC}?"; then
echo -e "${GREEN}Arranging $monitor_name ${position} $ref_monitor${RESET}" printf "%b\n" "${GREEN}Arranging $monitor_name ${position} $ref_monitor${RC}"
execute_command "xrandr --output $monitor_name $position $ref_monitor" 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 else
echo -e "${RED}Action canceled.${RESET}" printf "%b\n" "${RED}Action canceled.${RC}"
fi fi
} }

View File

@ -2,22 +2,24 @@
. ./utility_functions.sh . ./utility_functions.sh
# Function to reset scaling back to 1 (native resolution) for all monitors . ../../common-script.sh
reset_scaling() {
echo -e "${BLUE}=========================================${RESET}" # Function to Reset scaling back to 1 (native resolution) for all monitors
echo -e "${BLUE} Reset Monitor Scaling to Native Resolution${RESET}" Reset_scaling() {
echo -e "${BLUE}=========================================${RESET}" 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) 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 for monitor in $monitor_array; do
echo -e "${CYAN}Resetting scaling for $monitor to 1x1 (native resolution)${RESET}" printf "%b\n" "${CYAN}Resetting scaling for $monitor to 1x1 (native resolution)${RC}"
execute_command "xrandr --output $monitor --scale 1x1" execute_command "xrandr --output $monitor --scale 1x1"
done 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 # Call the Reset_scaling function
reset_scaling Reset_scaling

View File

@ -2,42 +2,42 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to scale smaller monitors to the highest resolution of a bigger monitor # Function to scale smaller monitors to the highest resolution of a bigger monitor
scale_monitors() { scale_monitors() {
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Scale Monitors to Highest Resolution${RESET}" printf "%b\n" "${YELLOW} Scale Monitors to Highest Resolution${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
monitor_list=$(detect_connected_monitors) 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_width=0
max_height=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}') res=$(xrandr | grep -A1 "^$monitor connected" | tail -1 | awk '{print $1}')
width=$(echo $res | awk -Fx '{print $1}') width=$(echo "$res" | awk -Fx '{print $1}')
height=$(echo $res | awk -Fx '{print $2}') height=$(echo "$res" | awk -Fx '{print $2}')
if (( width > max_width )); then if [ "$width" -gt "$max_width" ]; then
max_width=$width max_width=$width
fi fi
if (( height > max_height )); then if [ "$height" -gt "$max_height" ]; then
max_height=$height max_height=$height
fi fi
done 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
for monitor in "${monitor_array[@]}"; do printf "%b\n" "${YELLOW}Scaling $monitor to ${max_width}x${max_height}${RC}"
echo -e "${CYAN}Scaling $monitor to ${max_width}x${max_height}${RESET}"
execute_command "xrandr --output $monitor --scale-from ${max_width}x${max_height}" execute_command "xrandr --output $monitor --scale-from ${max_width}x${max_height}"
done 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 # Call the scale_monitors function

View File

@ -2,35 +2,39 @@
. ./utility_functions.sh . ./utility_functions.sh
. ../../common-script.sh
# Function to set a monitor as primary # Function to set a monitor as primary
set_primary_monitor() { set_primary_monitor() {
monitor_list=$(detect_connected_monitors) monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Set Primary Monitor${RESET}" printf "%b\n" "${YELLOW} Set Primary Monitor${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose a monitor to set as primary:${RESET}" printf "%b\n" "${YELLOW}Choose a monitor to set as primary:${RC}"
for i in "${!monitor_array[@]}"; do i=1
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" for monitor in $monitor_array; do
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
i=$((i + 1))
done done
read -p "Enter the number of the monitor: " monitor_choice read -p "Enter the number of the monitor: " monitor_choice
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection.${RESET}" printf "%b\n" "${RED}Invalid selection.${RC}"
return return
fi 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 if confirm_action "Set $monitor_name as the primary monitor?"; then
echo -e "${GREEN}Setting $monitor_name as primary monitor${RESET}" printf "%b\n" "${GREEN}Setting $monitor_name as primary monitor${RC}"
execute_command "xrandr --output $monitor_name --primary" 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 else
echo -e "${RED}Action canceled.${RESET}" printf "%b\n" "${RED}Action canceled.${RC}"
fi fi
} }

View File

@ -2,73 +2,68 @@
. ./utility_functions.sh . ./utility_functions.sh
RESET='\033[0m' . ../../common-script.sh
BOLD='\033[1m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
CYAN='\033[36m'
# Function to set resolutions # Function to set resolutions
set_resolutions() { set_resolutions() {
monitor_list=$(detect_connected_monitors) monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
while true; do while true; do
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Monitor Configuration${RESET}" printf "%b\n" "${YELLOW} Monitor Configuration${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose a monitor to configure:${RESET}"
for i in "${!monitor_array[@]}"; do printf "%b\n" "${YELLOW}Choose a monitor to configure:${RC}"
echo -e "$((i + 1)). ${CYAN}${monitor_array[i]}${RESET}" i=1
for monitor in $monitor_array; do
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
i=$((i + 1))
done done
read -p "Enter the choice (or 'q' to quit): " monitor_choice read -p "Enter the choice (or 'q' to quit): " monitor_choice
if [[ "$monitor_choice" == "q" ]]; then if [ "$monitor_choice" = "q" ]; then
echo -e "${RED}Exiting...${RESET}" printf "%b\n" "${RED}Exiting...${RC}"
return return
fi fi
if ! [[ "$monitor_choice" =~ ^[0-9]+$ ]] || (( monitor_choice < 1 )) || (( monitor_choice > ${#monitor_array[@]} )); then if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection. Please try again.${RESET}" printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
read -p "Press [Enter] to continue..." read -p "Press [Enter] to continue..."
continue continue
fi 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) 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) temp_res_file=$(mktemp)
echo "$resolutions" | awk '{print NR " " $0}' > "$temp_res_file" echo "$resolutions" | awk '{print NR " " $0}' > "$temp_res_file"
# Read the resolutions into an associative array i=1
declare -A resolution_map while read -r resolution; do
while read -r index resolution; do resolution_map[$i]="$resolution"
resolution_map[$index]="$resolution" i=$((i + 1))
done < "$temp_res_file" done < "$temp_res_file"
clear clear
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${BLUE} Resolution Configuration for ${CYAN}$monitor_name${RESET}" printf "%b\n" "${YELLOW} Resolution Configuration for ${YELLOW}$monitor_name${RC}"
echo -e "${BLUE}=========================================${RESET}" printf "%b\n" "${YELLOW}=========================================${RC}"
echo -e "${YELLOW}Choose resolution for $monitor_name:${RESET}"
awk '{print $1 ". " $2}' "$temp_res_file" awk '{print $1 ". " $2}' "$temp_res_file"
while true; do while true; do
read -p "Enter the choice (or 'q' to quit): " resolution_choice read -p "Enter the choice (or 'q' to quit): " resolution_choice
if [[ "$resolution_choice" == "q" ]]; then if [ "$resolution_choice" = "q" ]; then
echo -e "${RED}Exiting...${RESET}" printf "%b\n" "${RED}Exiting...${RC}"
rm "$temp_res_file" rm "$temp_res_file"
return return
fi fi
if ! [[ "$resolution_choice" =~ ^[0-9]+$ ]] || (( resolution_choice < 1 )) || (( resolution_choice > ${#resolution_map[@]} )); then if ! echo "$resolution_choice" | grep -qE '^[0-9]+$' || [ "$resolution_choice" -lt 1 ] || [ "$resolution_choice" -gt "$((i - 1))" ]; then
echo -e "${RED}Invalid selection. Please try again.${RESET}" printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
continue continue
fi fi
@ -76,16 +71,15 @@ set_resolutions() {
selected_resolution=${resolution_map[$resolution_choice]} selected_resolution=${resolution_map[$resolution_choice]}
read -p "Set resolution for $monitor_name to $selected_resolution? (y/n): " confirm read -p "Set resolution for $monitor_name to $selected_resolution? (y/n): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then if echo "$confirm" | grep -qE '^[Yy]$'; then
echo -e "${GREEN}Setting resolution for $monitor_name to $selected_resolution${RESET}" printf "%b\n" "${GREEN}Setting resolution for $monitor_name to $selected_resolution${RC}"
execute_command "xrandr --output $monitor_name --mode $selected_resolution" execute_command "xrandr --output $monitor_name --mode $selected_resolution"
break break
else 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 fi
done done
# Clean up the temporary file
rm "$temp_res_file" rm "$temp_res_file"
done done
} }

View File

@ -2,7 +2,7 @@
. ../../common-script.sh . ../../common-script.sh
# Function to check bluetoothctl is installed # Function to check xrandr is installed
setup_xrandr() { setup_xrandr() {
echo "Install xrandr if not already installed..." echo "Install xrandr if not already installed..."
if ! command_exists xrandr; then if ! command_exists xrandr; then
@ -22,22 +22,9 @@ setup_xrandr() {
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 execute xrandr commands and handle errors # Function to execute xrandr commands and handle errors
execute_command() { execute_command() {
local command="$1" command="$1"
echo "Executing: $command" echo "Executing: $command"
eval "$command" 2>&1 | tee /tmp/xrandr.log | tail -n 20 eval "$command" 2>&1 | tee /tmp/xrandr.log | tail -n 20
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -53,7 +40,7 @@ detect_connected_monitors() {
# Function to get resolutions for a monitor # Function to get resolutions for a monitor
get_unique_resolutions() { get_unique_resolutions() {
local monitor="$1" monitor="$1"
xrandr_output=$(xrandr) xrandr_output=$(xrandr)
# Get available resolutions from xrandr without line limit # 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) 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 # Define standard resolutions
standard_resolutions="1920x1080 1280x720 1600x900 2560x1440 3840x2160" 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 # 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) # 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 # 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 # Function to prompt for confirmation
confirm_action() { confirm_action() {
local action="$1" action="$1"
echo "$action" echo "$action"
read -p "Are you sure? (y/n): " confirm read -p "Are you sure? (y/n): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then if echo "$confirm" | grep -qE '^[Yy]$'; then
return 0 return 0
else else
return 1 return 1

View File

@ -4,7 +4,7 @@
# Function to check if NetworkManager is installed # Function to check if NetworkManager is installed
setupNetworkManager() { setupNetworkManager() {
echo "Install NetworkManger if not already installed..." printf "%b\n" "${YELLOW}Installing NetworkManager...${RC}"
if ! command_exists nmcli; then if ! command_exists nmcli; then
case ${PACKAGER} in case ${PACKAGER} in
pacman) pacman)
@ -18,39 +18,26 @@ setupNetworkManager() {
;; ;;
esac esac
else else
echo "NetworkManager is already installed." printf "%b\n" "${YELLOW}NetworkManager is already installed.${RC}"
fi fi
# Check if NetworkManager service is running # Check if NetworkManager service is running
if ! systemctl is-active --quiet NetworkManager; then 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 $ESCALATION_TOOL systemctl start NetworkManager
if systemctl is-active --quiet NetworkManager; then if systemctl is-active --quiet NetworkManager; then
echo "NetworkManager service started successfully." printf "%b\n" "${GREEN}NetworkManager service started successfully.${RC}"
fi fi
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 # Function to display the main menu
main_menu() { main_menu() {
while true; do while true; do
clear clear
colored_echo blue "WiFi Manager" printf "%b\n" "${YELLOW}WiFi Manager${RC}"
colored_echo blue "============" printf "%b\n" "${YELLOW}============${RC}"
echo "1. Turn WiFi On" echo "1. Turn WiFi On"
echo "2. Turn WiFi Off" echo "2. Turn WiFi Off"
echo "3. Scan for WiFi networks" echo "3. Scan for WiFi networks"
@ -59,7 +46,7 @@ main_menu() {
echo "6. Remove a WiFi connection" echo "6. Remove a WiFi connection"
echo "0. Exit" echo "0. Exit"
echo -n "Choose an option: " echo -n "Choose an option: "
read -e choice read choice
case $choice in case $choice in
1) wifi_on ;; 1) wifi_on ;;
@ -69,7 +56,7 @@ main_menu() {
5) disconnect_network ;; 5) disconnect_network ;;
6) remove_network ;; 6) remove_network ;;
0) exit 0 ;; 0) exit 0 ;;
*) colored_echo red "Invalid option. Please try again." ;; *) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
esac esac
done done
} }
@ -77,12 +64,12 @@ main_menu() {
# Function to scan for WiFi networks # Function to scan for WiFi networks
scan_networks() { scan_networks() {
clear 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) networks=$(nmcli -t -f SSID,BSSID,SIGNAL dev wifi list | head -n 10)
if [ -z "$networks" ]; then if [ -z "$networks" ]; then
colored_echo red "No networks found." printf "%b\n" "${RED}No networks found.${RC}"
else 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)}' echo "$networks" | sed 's/\\//g' | awk -F: '{printf("%d. SSID: %-25s \n", NR, $1)}'
fi fi
echo "Press any key to return to the main menu..." echo "Press any key to return to the main menu..."
@ -92,11 +79,11 @@ scan_networks() {
# Function to turn WiFi on # Function to turn WiFi on
wifi_on() { wifi_on() {
clear clear
colored_echo yellow "Turning WiFi on..." printf "%b\n" "${YELLOW}Turning WiFi on...${RC}"
nmcli radio wifi on && { 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..." echo "Press any key to return to the main menu..."
read -n 1 read -n 1
@ -105,11 +92,11 @@ wifi_on() {
# Function to turn WiFi off # Function to turn WiFi off
wifi_off() { wifi_off() {
clear clear
colored_echo yellow "Turning WiFi off..." printf "%b\n" "${YELLOW}Turning WiFi off...${RC}"
nmcli radio wifi off && { 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..." echo "Press any key to return to the main menu..."
read -n 1 read -n 1
@ -117,64 +104,65 @@ wifi_off() {
# Function to prompt for WiFi network selection # Function to prompt for WiFi network selection
prompt_for_network() { prompt_for_network() {
local action=$1 action=$1
local prompt_msg=$2 prompt_msg=$2
local success_msg=$3 success_msg=$3
local failure_msg=$4 failure_msg=$4
while true; do while true; do
clear clear
networks=$(nmcli -t -f SSID dev wifi list | head -n 10) networks=$(nmcli -t -f SSID dev wifi list | head -n 10)
if [ -z "$networks" ]; then 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..." echo "Press any key to return to the main menu..."
read -n 1 read -n 1
return return
fi fi
# Display networks with numbers # Display networks with numbers
IFS=$'\n' read -r -a network_list <<<"$networks" i=1
for i in "${!network_list[@]}"; do echo "$networks" | while IFS= read -r network; do
ssid=$(echo "${network_list[$i]}" | awk -F: '{print $1}') ssid=$(echo "$network" | awk -F: '{print $1}')
echo "$((i+1)). SSID: $ssid" echo "$i. SSID: $ssid"
i=$((i + 1))
done done
echo "0. Exit to main menu" echo "0. Exit to main menu"
echo -n "$prompt_msg" echo -n "$prompt_msg"
read -e choice read choice
# Validate the choice # Validate the choice
if [[ $choice =~ ^[0-9]+$ ]] && [ "$choice" -le "${#network_list[@]}" ] && [ "$choice" -gt 0 ]; then if echo "$choice" | grep -qE '^[0-9]+$' && [ "$choice" -le "$((i - 1))" ] && [ "$choice" -gt 0 ]; then
network=${network_list[$((choice-1))]} network=$(echo "$networks" | sed -n "${choice}p")
ssid=$(echo "$network" | awk -F: '{print $1}') ssid=$(echo "$network" | awk -F: '{print $1}')
if [ "$action" == "connect" ]; then if [ "$action" = "connect" ]; then
echo -n "Enter password for SSID $ssid: " echo -n "Enter password for SSID $ssid: "
read -s password read -s password
echo echo
nmcli dev wifi connect "$ssid" password "$password" && { nmcli dev wifi connect "$ssid" password "$password" && {
colored_echo green "$success_msg" printf "%b\n" "${GREEN}$success_msg${RC}"
break 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" && { nmcli connection down "$ssid" && {
colored_echo green "$success_msg" printf "%b\n" "${GREEN}$success_msg${RC}"
break 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" && { nmcli connection delete "$ssid" && {
colored_echo green "$success_msg" printf "%b\n" "${GREEN}$success_msg${RC}"
break break
} || { } || {
colored_echo red "$failure_msg" printf "%b\n" "${RED}$failure_msg${RC}"
} }
fi fi
elif [ "$choice" -eq 0 ]; then elif [ "$choice" -eq 0 ]; then
return return
else else
colored_echo red "Invalid choice. Please try again." printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
fi fi
done done
echo "Press any key to return to the main menu..." echo "Press any key to return to the main menu..."