improve to use less sudo commands

This commit is contained in:
Mathieu Broillet 2024-08-30 11:19:48 +02:00
parent eaf434efc8
commit 723b7b1284
Signed by: mathieu
GPG Key ID: A08E484FE95074C1
3 changed files with 29 additions and 18 deletions

View File

@ -32,7 +32,7 @@ fi
# Configure 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
echo "$USER_BEHIND_SUDO ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/sbin/pm-suspend, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot, /usr/bin/cat /etc/grub2.cfg, /usr/bin/cat /etc/grub.cfg" | sudo tee -a /etc/sudoers > /dev/null
print_colored "$COLOR_GREEN" "Sudoers file configured successfully."
# Firewall Configuration
@ -51,16 +51,16 @@ 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."
print_colored "$COLOR_GREEN" "\nDone! Some features may require a reboot to work including:"

View File

@ -28,7 +28,11 @@ if dual-boot), adjusting audio configurations, changing monitor settings, and mo
1. Install [HACS](https://hacs.xyz/) if not already installed.
2. In Home Assistant, go to "HACS" in the sidebar.
3. Click on "Integrations."
4. Search for "easy_computer_manager" and click "Install."
4. Click on the three dots in the top right corner and select "Custom repositories."
5. Paste the following URL in the "Repo" field: https://github.com/M4TH1EU/HA-EasyComputerManager
6. Select "Integration" from the "Category" dropdown.
7. Click "Add."
8. Search for "easy_computer_manager" and click "Install."
### Manually
@ -37,7 +41,14 @@ if dual-boot), adjusting audio configurations, changing monitor settings, and mo
3. Copy the "custom_components/easy_computer_manager" directory to the "config/custom_components/" directory in your
Home Assistant instance.
## Configuration
# Preparing your computer (required)
> [!CAUTION]
> Before adding your computer to Home Assistant, ensure that it is properly configured. (See below)
SEE WIKI
## Add Computer to Home Assistant
1. In Home Assistant, go to "Configuration" in the sidebar.
2. Select "Integrations."

View File

@ -27,19 +27,19 @@ ACTIONS = {
},
"shutdown": {
"windows": ["shutdown /s /t 0", "wmic os where Primary=TRUE call Shutdown"],
"linux": ["sudo shutdown -h now", "sudo init 0", "sudo systemctl poweroff"]
"linux": ["sudo shutdown -h now", "sudo init 0", "systemctl poweroff"]
},
"restart": {
"windows": ["shutdown /r /t 0", "wmic os where Primary=TRUE call Reboot"],
"linux": ["sudo shutdown -r now", "sudo init 6", "sudo systemctl reboot"]
"linux": ["sudo shutdown -r now", "sudo init 6", "systemctl reboot"]
},
"sleep": {
"windows": ["shutdown /h /t 0", "rundll32.exe powrprof.dll,SetSuspendState Sleep"],
"linux": ["sudo systemctl suspend", "sudo pm-suspend"]
"linux": ["systemctl suspend", "sudo pm-suspend"]
},
"get_windows_entry_grub": {
"linux": ["sudo awk -F \"'\" '/windows/ {print $2}' /boot/grub/grub.cfg",
"sudo awk -F \"'\" '/windows/ {print $2}' /boot/grub2/grub.cfg"]
"linux": ["sudo cat /etc/grub2.cfg | awk -F \"'\" '/windows/ {print $2}'",
"sudo cat /etc/grub.cfg | awk -F \"'\" '/windows/ {print $2}'"]
},
"set_grub_entry": {
"linux": {