Compare commits
2 Commits
10324f542b
...
b771739161
Author | SHA1 | Date | |
---|---|---|---|
b771739161 | |||
ad53165be2 |
64
.github/wiki/script-auto-config-linux.sh
vendored
64
.github/wiki/script-auto-config-linux.sh
vendored
@ -1,51 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Retrieve the username of the person who invoked sudo
|
||||
USER_BEHIND_SUDO=$(who am i | awk '{print $1}')
|
||||
|
||||
# Function to print colored text
|
||||
print_colored() {
|
||||
local color="$1"
|
||||
local text="$2"
|
||||
echo -e "${color}${text}\033[0m"
|
||||
}
|
||||
|
||||
# Define colors
|
||||
COLOR_RED="\033[0;31m"
|
||||
COLOR_GREEN="\033[0;32m"
|
||||
COLOR_YELLOW="\033[1;33m"
|
||||
COLOR_BLUE="\033[0;34m"
|
||||
|
||||
# Ask for HomeAssistant IP
|
||||
echo "Please enter your HomeAssistant IP address:"
|
||||
print_colored "$COLOR_BLUE" "Please enter your HomeAssistant local IP address (even if behind proxy, need LAN address):"
|
||||
read -r HOMEASSISTANT_IP
|
||||
|
||||
# Enable SSH Server
|
||||
echo "Enabling SSH Server..."
|
||||
print_colored "$COLOR_BLUE" "Enabling SSH Server..."
|
||||
if command -v systemctl &> /dev/null; then
|
||||
sudo systemctl enable --now sshd
|
||||
print_colored "$COLOR_GREEN" "SSH Server enabled successfully."
|
||||
else
|
||||
echo "Systemctl not found. Please enable SSH manually."
|
||||
print_colored "$COLOR_RED" "Systemctl not found. Please enable SSH manually."
|
||||
fi
|
||||
|
||||
# Configure sudoers
|
||||
echo "Configuring sudoers..."
|
||||
echo -e "\n# Allow your user to execute specific commands without a password (for EasyComputerManager/HA)" | sudo tee -a /etc/sudoers
|
||||
echo "$USER_BEHIND_SUDO ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/bin/systemctl, /usr/sbin/pm-suspend, /usr/bin/awk, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot" | sudo tee -a /etc/sudoers
|
||||
print_colored "$COLOR_BLUE" "Configuring sudoers..."
|
||||
echo -e "\n# Allow your user to execute specific commands without a password (for EasyComputerManager/HA)" | sudo tee -a /etc/sudoers > /dev/null
|
||||
echo "$USER_BEHIND_SUDO ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/bin/systemctl, /usr/sbin/pm-suspend, /usr/bin/awk, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot" | sudo tee -a /etc/sudoers > /dev/null
|
||||
print_colored "$COLOR_GREEN" "Sudoers file configured successfully."
|
||||
|
||||
# Firewall Configuration
|
||||
echo "Configuring firewall..."
|
||||
print_colored "$COLOR_BLUE" "Configuring firewall..."
|
||||
if command -v ufw &> /dev/null; then
|
||||
sudo ufw allow 22
|
||||
print_colored "$COLOR_GREEN" "Firewall configured to allow SSH."
|
||||
else
|
||||
echo "UFW not found. Please configure the firewall manually (if needed)."
|
||||
print_colored "$COLOR_RED" "UFW not found. Please configure the firewall manually (if needed)."
|
||||
fi
|
||||
|
||||
# Setup xhost for GUI apps
|
||||
echo "Configuring persistent xhost for starting GUI apps (like Steam)..."
|
||||
print_colored "$COLOR_BLUE" "Configuring persistent xhost for starting GUI apps (like Steam)..."
|
||||
COMMANDS="xhost +$HOMEASSISTANT_IP; xhost +localhost"
|
||||
DESKTOP_ENTRY_NAME="EasyComputerManager-AutoStart"
|
||||
DESKTOP_ENTRY_PATH="/home/$USER_BEHIND_SUDO/.config/autostart/$DESKTOP_ENTRY_NAME.desktop"
|
||||
|
||||
# Create the desktop entry file for the Desktop Environment to autostart at login every reboot
|
||||
cat > "$DESKTOP_ENTRY_PATH" <<EOF
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=$DESKTOP_ENTRY_NAME
|
||||
Exec=sh -c '$COMMANDS'
|
||||
Hidden=false
|
||||
NoDisplay=false
|
||||
X-GNOME-Autostart-enabled=true
|
||||
EOF
|
||||
chmod +x "$DESKTOP_ENTRY_PATH"
|
||||
# cat > "$DESKTOP_ENTRY_PATH" <<EOF
|
||||
# [Desktop Entry]
|
||||
# Type=Application
|
||||
# Name=$DESKTOP_ENTRY_NAME
|
||||
# Exec=sh -c '$COMMANDS'
|
||||
# Hidden=false
|
||||
# NoDisplay=false
|
||||
# X-GNOME-Autostart-enabled=true
|
||||
# EOF
|
||||
# chmod +x "$DESKTOP_ENTRY_PATH"
|
||||
print_colored "$COLOR_GREEN" "Desktop entry created at $DESKTOP_ENTRY_PATH."
|
||||
|
||||
echo ""
|
||||
echo "Done! Some features may require a reboot to work including:"
|
||||
echo " - Starting GUI apps from HomeAssistant"
|
||||
echo "You can now add your computer to HomeAssistant."
|
||||
print_colored "$COLOR_GREEN" "\nDone! Some features may require a reboot to work including:"
|
||||
print_colored "$COLOR_YELLOW" " - Starting GUI apps from HomeAssistant"
|
||||
print_colored "$COLOR_GREEN" "\nYou can now add your computer to HomeAssistant."
|
||||
print_colored "$COLOR_RED" "\nWARNING : Don't forget to install these packages : gnome-monitor-config, pactl, bluetoothctl"
|
||||
|
@ -273,7 +273,8 @@ def get_monitors_config(connection: Connection) -> dict:
|
||||
if is_unix_system(connection):
|
||||
result = connection.run("gnome-monitor-config list")
|
||||
if result.return_code != 0:
|
||||
raise HomeAssistantError(f"Could not get monitors config on system running at {connection.host}.")
|
||||
raise HomeAssistantError(f"Could not get monitors config on system running at {connection.host}. "
|
||||
f"Make sure gnome-monitor-config package is installed.")
|
||||
|
||||
monitors = []
|
||||
current_monitor = None
|
||||
@ -389,13 +390,15 @@ def get_audio_config(connection: Connection):
|
||||
# Get sinks
|
||||
result = connection.run("LANG=en_US.UTF-8 pactl list sinks")
|
||||
if result.return_code != 0:
|
||||
raise HomeAssistantError(f"Could not get audio sinks on system running at {connection.host}.")
|
||||
raise HomeAssistantError(f"Could not get audio sinks on system running at {connection.host}. "
|
||||
f"Make sure pactl package is installed!")
|
||||
config['sinks'] = parse_device_info(result.stdout.split('\n'), 'Sink')
|
||||
|
||||
# Get sources
|
||||
result = connection.run("LANG=en_US.UTF-8 pactl list sources")
|
||||
if result.return_code != 0:
|
||||
raise HomeAssistantError(f"Could not get audio sources on system running at {connection.host}.")
|
||||
raise HomeAssistantError(f"Could not get audio sources on system running at {connection.host}."
|
||||
f"Make sure pactl package is installed!")
|
||||
config['sources'] = parse_device_info(result.stdout.split('\n'), 'Source')
|
||||
|
||||
return config
|
||||
@ -450,7 +453,8 @@ def change_audio_config(connection: Connection, volume: int, mute: bool, input_d
|
||||
|
||||
if result.return_code != 0:
|
||||
raise HomeAssistantError(
|
||||
f"Could not change audio config on system running on {connection.host}, check logs with debug")
|
||||
f"Could not change audio config on system running on {connection.host}, check logs with debug and"
|
||||
f"make sure pactl package is installed!")
|
||||
else:
|
||||
raise HomeAssistantError("Not implemented yet for Windows OS.")
|
||||
|
||||
@ -487,20 +491,26 @@ def get_debug_info(connection: Connection):
|
||||
data['grub'] = data_grub
|
||||
data['audio'] = data_audio
|
||||
data['monitors'] = get_monitors_config(connection)
|
||||
data['bluetooth_devices'] = get_bluetooth_devices(connection)
|
||||
|
||||
return data
|
||||
|
||||
def get_bluetooth_devices(connection: Connection, only_connected: bool = False, return_as_string: bool = False):
|
||||
|
||||
def get_bluetooth_devices(connection: Connection, only_connected: bool = False, return_as_string: bool = False) -> []:
|
||||
commands = {
|
||||
"unix": "bash -c \'bluetoothctl info\'",
|
||||
"unix": "bluetoothctl info",
|
||||
"windows": "",
|
||||
}
|
||||
|
||||
if is_unix_system(connection):
|
||||
result = connection.run(commands["unix"])
|
||||
if result.return_code != 0:
|
||||
# _LOGGER.debug(f"No bluetooth devices connected or impossible to retrieve them at {connection.host}.")
|
||||
return []
|
||||
if result.stdout.__contains__("Missing device address argument"): # Means no devices are connected
|
||||
return []
|
||||
else:
|
||||
_LOGGER.warning(f"Cannot retrieve bluetooth devices at {connection.host}. "
|
||||
f"Make sure bluetoothctl is installed!")
|
||||
return []
|
||||
|
||||
devices = []
|
||||
current_device = None
|
||||
@ -537,4 +547,4 @@ def get_bluetooth_devices(connection: Connection, only_connected: bool = False,
|
||||
|
||||
return devices
|
||||
else:
|
||||
raise HomeAssistantError("Not implemented yet for Windows OS.")
|
||||
raise HomeAssistantError("Not implemented yet for Windows OS.")
|
||||
|
Loading…
Reference in New Issue
Block a user