2023-12-31 14:15:49 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-06-09 11:31:24 +02:00
|
|
|
# Retrieve the username of the person who invoked sudo
|
2024-01-01 19:56:50 +01:00
|
|
|
USER_BEHIND_SUDO=$(who am i | awk '{print $1}')
|
|
|
|
|
2024-06-09 11:31:24 +02:00
|
|
|
# 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"
|
|
|
|
|
2024-01-01 18:57:37 +01:00
|
|
|
# Ask for HomeAssistant IP
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_BLUE" "Please enter your HomeAssistant local IP address (even if behind proxy, need LAN address):"
|
2024-01-01 18:57:37 +01:00
|
|
|
read -r HOMEASSISTANT_IP
|
|
|
|
|
2023-12-31 14:15:49 +01:00
|
|
|
# Enable SSH Server
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_BLUE" "Enabling SSH Server..."
|
2023-12-31 14:15:49 +01:00
|
|
|
if command -v systemctl &> /dev/null; then
|
|
|
|
sudo systemctl enable --now sshd
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_GREEN" "SSH Server enabled successfully."
|
2023-12-31 14:15:49 +01:00
|
|
|
else
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_RED" "Systemctl not found. Please enable SSH manually."
|
2023-12-31 14:15:49 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Configure sudoers
|
2024-06-09 11:31:24 +02:00
|
|
|
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."
|
2023-12-31 14:15:49 +01:00
|
|
|
|
|
|
|
# Firewall Configuration
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_BLUE" "Configuring firewall..."
|
2023-12-31 14:15:49 +01:00
|
|
|
if command -v ufw &> /dev/null; then
|
|
|
|
sudo ufw allow 22
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_GREEN" "Firewall configured to allow SSH."
|
2023-12-31 14:15:49 +01:00
|
|
|
else
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_RED" "UFW not found. Please configure the firewall manually (if needed)."
|
2023-12-31 14:15:49 +01:00
|
|
|
fi
|
|
|
|
|
2024-01-01 18:57:37 +01:00
|
|
|
# Setup xhost for GUI apps
|
2024-06-09 11:31:24 +02:00
|
|
|
print_colored "$COLOR_BLUE" "Configuring persistent xhost for starting GUI apps (like Steam)..."
|
2024-01-01 18:57:37 +01:00
|
|
|
COMMANDS="xhost +$HOMEASSISTANT_IP; xhost +localhost"
|
|
|
|
DESKTOP_ENTRY_NAME="EasyComputerManager-AutoStart"
|
2024-01-01 19:56:50 +01:00
|
|
|
DESKTOP_ENTRY_PATH="/home/$USER_BEHIND_SUDO/.config/autostart/$DESKTOP_ENTRY_NAME.desktop"
|
2024-01-01 18:57:37 +01:00
|
|
|
|
|
|
|
# Create the desktop entry file for the Desktop Environment to autostart at login every reboot
|
2024-06-09 11:31:24 +02:00
|
|
|
# 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."
|
|
|
|
|
|
|
|
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"
|