Add utility functions for package checks

- Implement checks for xrandr, bluetoothctl, and nmcli
- Add installation of missing packages
- Include display server check (X11 vs Wayland)
- Warn users if running on Wayland
- Improve error handling and user feedback
This commit is contained in:
JEEVITHA KANNAN K S 2024-08-15 10:45:12 +05:30
parent 1748c3bae4
commit 7a2d654760
No known key found for this signature in database
GPG Key ID: 5904C34A2F7CE333
3 changed files with 125 additions and 0 deletions

View File

@ -1,5 +1,34 @@
#!/bin/sh -e #!/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)
sudo "${PACKAGER}" -S --noconfirm bluez-utils
;;
*)
sudo "${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..."
sudo systemctl start bluetooth
if systemctl is-active --quiet bluetooth; then
echo "bluetooth service started successfully."
fi
fi
}
# Function to display colored text # Function to display colored text
colored_echo() { colored_echo() {
local color=$1 local color=$1
@ -128,4 +157,6 @@ remove_device() {
} }
# Initialize # Initialize
checkEnv
setupBluetooth
main_menu main_menu

View File

@ -1,5 +1,61 @@
#!/bin/sh -e #!/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)
sudo "${PACKAGER}" -S --noconfirm xorg-xrandr
;;
apt-get)
sudo "${PACKAGER}" install -y x11-xserver-utils
;;
*)
sudo "${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 check the display server type
check_display_server() {
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
colored_echo "red" "You are using Wayland."
colored_echo "red" "This script is designed for X11. It may not work correctly on Wayland."
read -p "Do you want to continue anyway? (y/n): " response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Exiting script."
exit 1
fi
elif [ "$XDG_SESSION_TYPE" = "x11" ]; then
colored_echo "green" "You are using X11 (X-server)."
return 0
else
colored_echo "red" "Unable to determine the display server type."
exit 1
fi
}
# Function to execute xrandr commands and handle errors # Function to execute xrandr commands and handle errors
execute_command() { execute_command() {
local command="$1" local command="$1"
@ -34,3 +90,7 @@ confirm_action() {
return 1 return 1
fi fi
} }
checkEnv
setup_xrandr
check_display_server

View File

@ -1,5 +1,37 @@
#!/bin/sh -e #!/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)
sudo "${PACKAGER}" -S --noconfirm networkmanager
;;
dnf)
sudo "${PACKAGER}" install -y NetworkManager-1
;;
*)
sudo "${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..."
sudo systemctl start NetworkManager
if systemctl is-active --quiet NetworkManager; then
echo "NetworkManager service started successfully."
fi
fi
}
# Function to display colored text # Function to display colored text
colored_echo() { colored_echo() {
local color=$1 local color=$1
@ -165,4 +197,6 @@ remove_network() {
} }
# Initialize # Initialize
checkEnv
setupNetworkManager
main_menu main_menu