mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-22 12:41:05 +01:00
Optimized msi-keyboard-color and caffeine
This commit is contained in:
parent
b8a23f95db
commit
df6e2c7fc5
@ -16,6 +16,7 @@ on_calendar_docker_compose_restart_unhealthy: "*-*-* 09,10,11,12,13,14,15,16,17,
|
||||
on_calendar_pull_primary_backups: "*-*-* 21:30:00"
|
||||
on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00"
|
||||
on_calendar_deploy_mailu_certificates: "*-*-* 13,01:30:00"
|
||||
on_calendar_msi_keyboard_color: "*-*-* *:00,15,30,45:00"
|
||||
|
||||
# Space Variables
|
||||
size_percent_maximum_backup: 75
|
||||
|
@ -249,7 +249,7 @@
|
||||
hosts: msi_perkeyrgb
|
||||
become: true
|
||||
roles:
|
||||
- pc_driver-msi-perkeyrgb
|
||||
- pc_application-msi-keyboard-color
|
||||
|
||||
- name: setup ssh hosts
|
||||
hosts: ssh
|
||||
|
25
roles/pc_application-caffeine/README.md
Normal file
25
roles/pc_application-caffeine/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Ansible Role: caffeine_auto_start
|
||||
|
||||
An Ansible Role that installs `caffeine-ng` on Archlinux systems and sets it to start automatically when the user logs in.
|
||||
|
||||
## Requirements
|
||||
|
||||
- The target system should be Archlinux.
|
||||
- Ansible 2.4 or higher.
|
||||
- The [kewlfft.aur.aur](https://galaxy.ansible.com/kewlfft/aur) Ansible Galaxy role for managing AUR packages.
|
||||
|
||||
## Role Variables
|
||||
|
||||
None.
|
||||
|
||||
## License
|
||||
|
||||
AGPL 3
|
||||
|
||||
## Author
|
||||
|
||||
Kevin Veen-Birkenbach - kevin@veen.world - https://www.veen.world/
|
||||
|
||||
## Background
|
||||
|
||||
The code for this role was created in an interactive conversation with OpenAI's language model. You can view the original conversation [here](https://chat.openai.com/share/fa846dac-6068-4386-b3e7-b75f1248ec82).
|
@ -1,2 +0,0 @@
|
||||
# Defaults for caffeine_auto_start role
|
||||
caffeine_executable_path: "/usr/bin/caffeine"
|
@ -1,10 +0,0 @@
|
||||
# handlers file for caffeine_auto_start
|
||||
- name: reload systemd
|
||||
command: systemctl daemon-reload
|
||||
|
||||
- name: enable and start caffeine
|
||||
systemd:
|
||||
name: caffeine.service
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,2 +1,16 @@
|
||||
---
|
||||
dependencies:
|
||||
- pc_system-aur-helper
|
||||
- pc_system-aur-helper
|
||||
galaxy_info:
|
||||
author: Kevin Veen-Birkenbach
|
||||
description: Ansible role for installing caffeine-ng and setting it to start at user login.
|
||||
license: AGPL 3
|
||||
min_ansible_version: 2.4
|
||||
platforms:
|
||||
- name: Archlinux
|
||||
versions:
|
||||
- all
|
||||
galaxy_tags:
|
||||
- caffeine
|
||||
- autostart
|
||||
- archlinux
|
||||
|
@ -1,13 +1,16 @@
|
||||
- name: install caffeine
|
||||
---
|
||||
- name: Install caffeine
|
||||
kewlfft.aur.aur:
|
||||
use: yay
|
||||
name:
|
||||
- caffeine-ng
|
||||
|
||||
- name: Copy caffeine systemd service file
|
||||
- name: Create autostart directory if it doesn't exist
|
||||
file:
|
||||
path: "{{ ansible_env.HOME }}/.config/autostart"
|
||||
state: directory
|
||||
|
||||
- name: Copy caffeine.desktop file to autostart directory
|
||||
template:
|
||||
src: caffeine.service.j2
|
||||
dest: /etc/systemd/system/caffeine.service
|
||||
notify:
|
||||
- reload systemd
|
||||
- enable and start caffeine
|
||||
src: caffeine.desktop.j2
|
||||
dest: "{{ ansible_env.HOME }}/.config/autostart/caffeine.desktop"
|
||||
|
10
roles/pc_application-caffeine/templates/caffeine.desktop.j2
Normal file
10
roles/pc_application-caffeine/templates/caffeine.desktop.j2
Normal file
@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Exec=/usr/bin/caffeine
|
||||
Hidden=false
|
||||
NoDisplay=false
|
||||
X-GNOME-Autostart-enabled=true
|
||||
Name[en_US]=caffeine
|
||||
Name=caffeine
|
||||
Comment[en_US]=
|
||||
Comment=
|
@ -1,8 +0,0 @@
|
||||
[Unit]
|
||||
Description=Caffeine auto start
|
||||
|
||||
[Service]
|
||||
ExecStart={{ caffeine_executable_path }}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
42
roles/pc_application-msi-keyboard-color/README.md
Normal file
42
roles/pc_application-msi-keyboard-color/README.md
Normal file
@ -0,0 +1,42 @@
|
||||
# Ansible Role: keyboard-color
|
||||
|
||||
Ansible role to set up dynamic keyboard color change on MSI laptops.
|
||||
|
||||
## Requirements
|
||||
|
||||
- An MSI laptop
|
||||
- The `msi-perkeyrgb` tool installed on the system
|
||||
- Ansible 2.9 or later
|
||||
|
||||
## Role Variables
|
||||
|
||||
Available variables are listed below, along with their default values:
|
||||
|
||||
```yaml
|
||||
vendor_and_product_id: ""
|
||||
```
|
||||
|
||||
The `vendor_and_product_id` variable is required and should be set to the vendor and product ID of the MSI laptop.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `pc_system-aur-helper`
|
||||
|
||||
## Example Playbook
|
||||
|
||||
```yaml
|
||||
- hosts: all
|
||||
roles:
|
||||
- keyboard-color
|
||||
vars:
|
||||
vendor_and_product_id: "your_vendor_and_product_id"
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
This role was created by [Kevin Veen-Birkenbach](https://github.com/kevinveenbirkenbach).
|
||||
|
||||
## Chat Conversation
|
||||
|
||||
To see how this role was developed, you can refer to the [Chat Conversation](https://chat.openai.com/share/41c47fdb-a92d-466d-9e92-5a894fe6bec3) that produced this software.
|
||||
|
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the vendor and product ID is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Error: Vendor and product ID is missing."
|
||||
echo "Usage: /opt/keyboard_color.sh <vendor_and_product_id>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the vendor and product ID from the command-line argument
|
||||
vendor_and_product_id=$1
|
||||
|
||||
# Define the color transition parameters
|
||||
fade_duration=1800 # 30 minutes in seconds
|
||||
transition_start="06:00"
|
||||
transition_end="06:30"
|
||||
red_start="18:00"
|
||||
red_end="06:00"
|
||||
red_color="ff0000"
|
||||
|
||||
# Get the current time in HH:MM format
|
||||
current_time=$(date +%H:%M)
|
||||
|
||||
# Check if it's within the red period
|
||||
if [[ "$current_time" > "$red_start" || "$current_time" < "$red_end" ]]; then
|
||||
# Set the color to red directly
|
||||
sudo msi-perkeyrgb --model GS65 -s "$red_color" --id "$vendor_and_product_id"
|
||||
else
|
||||
# Check if it's within the fading period
|
||||
if [[ "$current_time" > "$transition_start" && "$current_time" < "$transition_end" ]]; then
|
||||
# Calculate the transition ratio within the fading period
|
||||
start_seconds=$(date -d "$transition_start" +%s)
|
||||
end_seconds=$(date -d "$transition_end" +%s)
|
||||
current_seconds=$(date -d "$current_time" +%s)
|
||||
transition_ratio=$(awk "BEGIN { ratio = ($current_seconds - $start_seconds) / ($end_seconds - $start_seconds); print ratio }")
|
||||
|
||||
# Calculate the current color based on the transition ratio
|
||||
r=$(awk "BEGIN { value = 255 - 255 * $transition_ratio; printf(\"%.0f\", value) }")
|
||||
g=0
|
||||
b=0
|
||||
|
||||
# Convert the RGB values to hexadecimal format
|
||||
current_color=$(printf '%02x%02x%02x' $r $g $b)
|
||||
|
||||
# Set the color using msi-perkeyrgb
|
||||
sudo msi-perkeyrgb --model GS65 -s "$current_color" --id "$vendor_and_product_id"
|
||||
else
|
||||
# Calculate the transition ratio based on the time of day
|
||||
start_seconds=$(date -d "$transition_end" +%s)
|
||||
end_seconds=$(date -d "$red_start" +%s)
|
||||
current_seconds=$(date -d "$current_time" +%s)
|
||||
transition_ratio=$(awk "BEGIN { ratio = ($current_seconds - $start_seconds) / ($end_seconds - $start_seconds); print ratio }")
|
||||
|
||||
# Calculate the current color based on the transition ratio
|
||||
r=$(awk "BEGIN { value = 255 * $transition_ratio; printf(\"%.0f\", value) }")
|
||||
g=$(awk "BEGIN { value = 0 + (255 - 0) * $transition_ratio; printf(\"%.0f\", value) }")
|
||||
b=$(awk "BEGIN { value = 0 + (255 - 0) * $transition_ratio; printf(\"%.0f\", value) }")
|
||||
|
||||
# Convert the RGB values to hexadecimal format
|
||||
current_color=$(printf '%02x%02x%02x' $r $g $b)
|
||||
|
||||
# Set the color using msi-perkeyrgb
|
||||
sudo msi-perkeyrgb --model GS65 -s "$current_color" --id "$vendor_and_product_id"
|
||||
fi
|
||||
fi
|
11
roles/pc_application-msi-keyboard-color/meta/main.yml
Normal file
11
roles/pc_application-msi-keyboard-color/meta/main.yml
Normal file
@ -0,0 +1,11 @@
|
||||
galaxy_info:
|
||||
role_name: keyboard-color
|
||||
author: Kevin Veen-Birkenbach
|
||||
description: "Ansible role to set up dynamic keyboard color change on MSI laptops"
|
||||
min_ansible_version: 2.9
|
||||
platforms:
|
||||
- name: Linux
|
||||
versions:
|
||||
- all
|
||||
dependencies:
|
||||
- pc_system-aur-helper
|
9
roles/pc_application-msi-keyboard-color/tasks/main.yml
Normal file
9
roles/pc_application-msi-keyboard-color/tasks/main.yml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Install MSI packages
|
||||
kewlfft.aur.aur:
|
||||
use: yay
|
||||
name:
|
||||
- msi-perkeyrgb
|
||||
|
||||
- include_tasks: setup_script.yml
|
||||
- include_tasks: setup_timers.yml
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Copy keyboard_color.sh script
|
||||
copy:
|
||||
src: keyboard_color.sh
|
||||
dest: /opt/keyboard_color.sh
|
||||
mode: 0755
|
||||
tags:
|
||||
- keyboard-color
|
@ -0,0 +1,30 @@
|
||||
---
|
||||
- name: Copy keyboard-color.timer file
|
||||
template:
|
||||
src: keyboard-color.timer
|
||||
dest: /etc/systemd/system/keyboard-color.j2
|
||||
mode: 0644
|
||||
tags:
|
||||
- keyboard-color
|
||||
|
||||
- name: Copy keyboard-color.service file
|
||||
template:
|
||||
src: keyboard-color.service.j2
|
||||
dest: /etc/systemd/system/keyboard-color.service
|
||||
mode: 0644
|
||||
tags:
|
||||
- keyboard-color
|
||||
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
tags:
|
||||
- keyboard-color
|
||||
|
||||
- name: Enable and start keyboard-color.timer
|
||||
systemd:
|
||||
name: keyboard-color.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
tags:
|
||||
- keyboard-color
|
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Keyboard Color Service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/opt/keyboard_color.sh {{ vendor_and_product_id }}
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Keyboard Color Timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_msi_keyboard_color}}
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
@ -1,4 +0,0 @@
|
||||
# pc_driver-msi-perkeyrgb
|
||||
# further information
|
||||
- https://github.com/Askannz/msi-perkeyrgb
|
||||
- https://wiki.archlinux.org/title/MSI_GS66_11UX
|
@ -1,2 +0,0 @@
|
||||
dependencies:
|
||||
- pc_system-aur-helper
|
@ -1,9 +0,0 @@
|
||||
- name: Install MSI packages
|
||||
kewlfft.aur.aur:
|
||||
use: yay
|
||||
name:
|
||||
- msi-perkeyrgb
|
||||
|
||||
- name: Change preset of keyboard {{vendor_and_product_id}} to {{preset}}
|
||||
ansible.builtin.shell: sudo msi-perkeyrgb --model GS65 -p "{{preset}}" --id "{{vendor_and_product_id}}"
|
||||
become: true
|
Loading…
Reference in New Issue
Block a user