diff --git a/src/commands/utils/bluetooth-control.sh b/src/commands/utils/bluetooth-control.sh index e5e02fc6..ddb97c65 100644 --- a/src/commands/utils/bluetooth-control.sh +++ b/src/commands/utils/bluetooth-control.sh @@ -1,4 +1,33 @@ -#!/bin/bash +#!/bin/sh -e + +. ../common-script.sh + +# Function to check bluetoothctl is installed +setupBluetooth() { + echo "Install bluetoothctl if not already installed..." + if ! command_exists bluetoothctl; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL "${PACKAGER}" -S --noconfirm bluez-utils + ;; + *) + $ESCALATION_TOOL "${PACKAGER}" install -y bluez + ;; + esac + else + echo "Bluetoothctl is already installed." + fi + + # Check if bluetooth service is running + if ! systemctl is-active --quiet bluetooth; then + echo "Bluetooth service is not running. Starting it now..." + $ESCALATION_TOOL systemctl start bluetooth + + if systemctl is-active --quiet bluetooth; then + echo "bluetooth service started successfully." + fi + fi +} # Function to display colored text colored_echo() { @@ -128,4 +157,6 @@ remove_device() { } # Initialize +checkEnv +setupBluetooth main_menu diff --git a/src/commands/utils/monitor-control/auto_detect_displays.sh b/src/commands/utils/monitor-control/auto_detect_displays.sh index a86ddfc1..86fcdcd9 100755 --- a/src/commands/utils/monitor-control/auto_detect_displays.sh +++ b/src/commands/utils/monitor-control/auto_detect_displays.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to auto-detect displays and set common resolution auto_detect_displays() { diff --git a/src/commands/utils/monitor-control/change_orientation.sh b/src/commands/utils/monitor-control/change_orientation.sh index 93927149..4ec802d4 100755 --- a/src/commands/utils/monitor-control/change_orientation.sh +++ b/src/commands/utils/monitor-control/change_orientation.sh @@ -1,10 +1,11 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to change monitor orientation change_orientation() { monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" clear echo -e "${BLUE}=========================================${RESET}" diff --git a/src/commands/utils/monitor-control/disable_monitor.sh b/src/commands/utils/monitor-control/disable_monitor.sh index f999d408..b455848b 100755 --- a/src/commands/utils/monitor-control/disable_monitor.sh +++ b/src/commands/utils/monitor-control/disable_monitor.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh RESET='\033[0m' BOLD='\033[1m' @@ -12,7 +13,7 @@ CYAN='\033[36m' # Function to disable a monitor disable_monitor() { monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" clear echo -e "${BLUE}=========================================${RESET}" diff --git a/src/commands/utils/monitor-control/duplicate_displays.sh b/src/commands/utils/monitor-control/duplicate_displays.sh index 4332a0f9..c5cdf01e 100755 --- a/src/commands/utils/monitor-control/duplicate_displays.sh +++ b/src/commands/utils/monitor-control/duplicate_displays.sh @@ -1,15 +1,16 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.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 + echo "Duplicating $monitor to $primary" + execute_command "xrandr --output $monitor --same-as $primary" + fi + done } duplicate_displays diff --git a/src/commands/utils/monitor-control/enable_monitor.sh b/src/commands/utils/monitor-control/enable_monitor.sh index bf770053..3525771f 100755 --- a/src/commands/utils/monitor-control/enable_monitor.sh +++ b/src/commands/utils/monitor-control/enable_monitor.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh RESET='\033[0m' BOLD='\033[1m' @@ -12,7 +13,7 @@ CYAN='\033[36m' # Function to enable a monitor enable_monitor() { monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" clear echo -e "${BLUE}=========================================${RESET}" diff --git a/src/commands/utils/monitor-control/extend_displays.sh b/src/commands/utils/monitor-control/extend_displays.sh index d93b2eb3..4e215bfa 100755 --- a/src/commands/utils/monitor-control/extend_displays.sh +++ b/src/commands/utils/monitor-control/extend_displays.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to extend displays extend_displays() { diff --git a/src/commands/utils/monitor-control/manage_arrangement.sh b/src/commands/utils/monitor-control/manage_arrangement.sh index 305e5210..19049814 100755 --- a/src/commands/utils/monitor-control/manage_arrangement.sh +++ b/src/commands/utils/monitor-control/manage_arrangement.sh @@ -1,10 +1,11 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to manage monitor arrangement manage_arrangement() { monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" clear echo -e "${BLUE}=========================================${RESET}" diff --git a/src/commands/utils/monitor-control/reset_scaling.sh b/src/commands/utils/monitor-control/reset_scaling.sh index 3a80e856..81308065 100755 --- a/src/commands/utils/monitor-control/reset_scaling.sh +++ b/src/commands/utils/monitor-control/reset_scaling.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to reset scaling back to 1 (native resolution) for all monitors reset_scaling() { @@ -8,7 +9,7 @@ reset_scaling() { echo -e "${BLUE}=========================================${RESET}" monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" for monitor in "${monitor_array[@]}"; do echo -e "${CYAN}Resetting scaling for $monitor to 1x1 (native resolution)${RESET}" diff --git a/src/commands/utils/monitor-control/scale_monitor.sh b/src/commands/utils/monitor-control/scale_monitor.sh index eb680187..708e1fb3 100755 --- a/src/commands/utils/monitor-control/scale_monitor.sh +++ b/src/commands/utils/monitor-control/scale_monitor.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to scale smaller monitors to the highest resolution of a bigger monitor scale_monitors() { @@ -8,7 +9,7 @@ scale_monitors() { echo -e "${BLUE}=========================================${RESET}" monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" # Get the highest resolution among all monitors max_width=0 diff --git a/src/commands/utils/monitor-control/set_primary_monitor.sh b/src/commands/utils/monitor-control/set_primary_monitor.sh index f10c8d34..752dc784 100755 --- a/src/commands/utils/monitor-control/set_primary_monitor.sh +++ b/src/commands/utils/monitor-control/set_primary_monitor.sh @@ -1,10 +1,11 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh # Function to set a monitor as primary set_primary_monitor() { monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" clear echo -e "${BLUE}=========================================${RESET}" diff --git a/src/commands/utils/monitor-control/set_resolutions.sh b/src/commands/utils/monitor-control/set_resolutions.sh index 3f0e0fcd..2f3cb6a7 100755 --- a/src/commands/utils/monitor-control/set_resolutions.sh +++ b/src/commands/utils/monitor-control/set_resolutions.sh @@ -1,5 +1,6 @@ -#!/bin/bash -source ./utility_functions.sh +#!/bin/sh -e + +. ./utility_functions.sh RESET='\033[0m' BOLD='\033[1m' @@ -12,7 +13,7 @@ CYAN='\033[36m' # Function to set resolutions set_resolutions() { monitor_list=$(detect_connected_monitors) - IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list" + IFS=$'\n' read -r -a monitor_array <<<"$monitor_list" while true; do clear diff --git a/src/commands/utils/monitor-control/utility_functions.sh b/src/commands/utils/monitor-control/utility_functions.sh index 9ef00ed2..bb480390 100755 --- a/src/commands/utils/monitor-control/utility_functions.sh +++ b/src/commands/utils/monitor-control/utility_functions.sh @@ -1,4 +1,39 @@ -#!/bin/bash +#!/bin/sh -e + +. ../../common-script.sh + +# Function to check bluetoothctl 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 + ;; + 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() { @@ -47,3 +82,6 @@ confirm_action() { return 1 fi } + +checkEnv +setup_xrandr \ No newline at end of file diff --git a/src/commands/utils/tab_data.toml b/src/commands/utils/tab_data.toml index 209a4015..67ba893f 100644 --- a/src/commands/utils/tab_data.toml +++ b/src/commands/utils/tab_data.toml @@ -25,10 +25,6 @@ matches = true data = { environment = "DISPLAY" } values = [":0", ":1", ":2", ":3", ":4", ":5", ":6", ":7", ":8", ":9"] -[[data.entries]] -name = "Set Resolution" -script = "monitor-control/set_resolutions.sh" - [[data.entries]] name = "Duplicate Displays" script = "monitor-control/duplicate_displays.sh" diff --git a/src/commands/utils/wifi-control.sh b/src/commands/utils/wifi-control.sh index 1f80804d..739b127d 100644 --- a/src/commands/utils/wifi-control.sh +++ b/src/commands/utils/wifi-control.sh @@ -1,5 +1,36 @@ -@@ -0,0 +1,168 @@ -#!/bin/bash +#!/bin/sh -e + +. ../common-script.sh + +# Function to check if NetworkManager is installed +setupNetworkManager() { + echo "Install NetworkManger if not already installed..." + if ! command_exists nmcli; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL "${PACKAGER}" -S --noconfirm networkmanager + ;; + dnf) + $ESCALATION_TOOL "${PACKAGER}" install -y NetworkManager-1 + ;; + *) + $ESCALATION_TOOL "${PACKAGER}" install -y network-manager + ;; + esac + else + echo "NetworkManager is already installed." + fi + + # Check if NetworkManager service is running + if ! systemctl is-active --quiet NetworkManager; then + echo "NetworkManager service is not running. Starting it now..." + $ESCALATION_TOOL systemctl start NetworkManager + + if systemctl is-active --quiet NetworkManager; then + echo "NetworkManager service started successfully." + fi + fi +} # Function to display colored text colored_echo() { @@ -166,4 +197,6 @@ remove_network() { } # Initialize +checkEnv +setupNetworkManager main_menu