mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
Refactored pc roles and added README.md's with help of ChatGPT. See https://chat.openai.com/share/df22ba6a-76d0-47c2-a8c7-daec3f42b4e5
This commit is contained in:
42
roles/driver-msi-keyboard-color/README.md
Normal file
42
roles/driver-msi-keyboard-color/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Ansible Role: driver-msi-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
|
||||
|
||||
- `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.
|
||||
|
139
roles/driver-msi-keyboard-color/files/keyboard_color.sh
Normal file
139
roles/driver-msi-keyboard-color/files/keyboard_color.sh
Normal file
@@ -0,0 +1,139 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# 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
|
||||
morning_blue_color="5bc0eb" # Morning Blue Color
|
||||
dawn_color="ff7f00" # Dawn Color
|
||||
morning_golden_hour_color="f9c80e" # Morning Golden Hour Color
|
||||
sunrise_color="ffd700" # Sunrise Color
|
||||
noon_color="ffffff" # Noon Color
|
||||
twilight_color="ff6f61" # Twilight Color
|
||||
evening_golden_hour_color="fdbe51" # Evening Golden Hour Color
|
||||
evening_blue_color="0000ff" # Evening Blue Color
|
||||
sunset_color="ff4500" # Sunset Color
|
||||
night_color="990000" # Night Color
|
||||
|
||||
# Function to calculate the color based on the transition ratio
|
||||
calculate_color() {
|
||||
local color_start=$1
|
||||
local color_end=$2
|
||||
local transition_ratio=$3
|
||||
|
||||
local start_r=$((16#${color_start:0:2}))
|
||||
local start_g=$((16#${color_start:2:2}))
|
||||
local start_b=$((16#${color_start:4:2}))
|
||||
|
||||
local end_r=$((16#${color_end:0:2}))
|
||||
local end_g=$((16#${color_end:2:2}))
|
||||
local end_b=$((16#${color_end:4:2}))
|
||||
|
||||
local current_r=$(awk "BEGIN { r = ${start_r} + (${end_r} - ${start_r}) * ${transition_ratio}; printf(\"%.0f\", r) }")
|
||||
local current_g=$(awk "BEGIN { g = ${start_g} + (${end_g} - ${start_g}) * ${transition_ratio}; printf(\"%.0f\", g) }")
|
||||
local current_b=$(awk "BEGIN { b = ${start_b} + (${end_b} - ${start_b}) * ${transition_ratio}; printf(\"%.0f\", b) }")
|
||||
|
||||
local calculated_color=$(printf "%02x%02x%02x" "$current_r" "$current_g" "$current_b")
|
||||
|
||||
if [ "$calculated_color" = "ffff100" ]; then
|
||||
calculated_color="ffffff"
|
||||
fi
|
||||
|
||||
echo "$calculated_color"
|
||||
}
|
||||
|
||||
# Get the current time in HH:MM format
|
||||
current_time=$(date +%H:%M)
|
||||
|
||||
# Calculate the transition ratio based on the current time
|
||||
if [[ "$current_time" > "22:00" || "$current_time" < "04:00" ]]; then
|
||||
# Night (22:00 to 04:00)
|
||||
color_start="$night_color"
|
||||
color_end="$night_color"
|
||||
color_start_time="22:00"
|
||||
color_end_time="04:00"
|
||||
elif [[ "$current_time" > "21:00" ]]; then
|
||||
# Evening Blue Hour to Night (21:00 to 22:00)
|
||||
color_start="$evening_blue_color"
|
||||
color_end="$night_color"
|
||||
color_start_time="21:00"
|
||||
color_end_time="22:00"
|
||||
elif [[ "$current_time" > "20:00" ]]; then
|
||||
# Evening Golden Hour to Evening Blue Hour (20:00 to 21:00)
|
||||
color_start="$evening_golden_hour_color"
|
||||
color_end="$evening_blue_color"
|
||||
color_start_time="20:00"
|
||||
color_end_time="21:00"
|
||||
elif [[ "$current_time" > "19:30" ]]; then
|
||||
# Sunset to Evening Golden Hour (19:30 to 20:00)
|
||||
color_start="$sunset_color"
|
||||
color_end="$evening_golden_hour_color"
|
||||
color_start_time="19:30"
|
||||
color_end_time="20:00"
|
||||
elif [[ "$current_time" > "12:00" ]]; then
|
||||
# Noon to Sunset (12:00 to 19:30)
|
||||
color_start="$noon_color"
|
||||
color_end="$sunset_color"
|
||||
color_start_time="12:00"
|
||||
color_end_time="19:30"
|
||||
elif [[ "$current_time" > "07:30" ]]; then
|
||||
# Sunrise to Noon (07:30 to 12:00)
|
||||
color_start="$sunrise_color"
|
||||
color_end="$noon_color"
|
||||
color_start_time="07:30"
|
||||
color_end_time="12:00"
|
||||
elif [[ "$current_time" > "07:00" ]]; then
|
||||
# Morning Golden Hour to Sunrise (07:00 to 07:30)
|
||||
color_start="$morning_golden_hour_color"
|
||||
color_end="$sunrise_color"
|
||||
color_start_time="07:00"
|
||||
color_end_time="07:30"
|
||||
elif [[ "$current_time" > "06:00" ]]; then
|
||||
# Dawn to Morning Golden Hour (06:00 to 07:00)
|
||||
color_start="$dawn_color"
|
||||
color_end="$morning_golden_hour_color"
|
||||
color_start_time="06:00"
|
||||
color_end_time="07:00"
|
||||
elif [[ "$current_time" > "05:00" ]]; then
|
||||
# Morning Blue Hour to Dawn (05:00 to 06:00)
|
||||
color_start="$morning_blue_color"
|
||||
color_end="$dawn_color"
|
||||
color_start_time="05:00"
|
||||
color_end_time="06:00"
|
||||
elif [[ "$current_time" > "04:00" ]]; then
|
||||
# Night to Morning Blue Hour (22:00 to 04:00)
|
||||
color_start="$night_color"
|
||||
color_end="$morning_blue_color"
|
||||
color_start_time="04:00"
|
||||
color_end_time="05:00"
|
||||
fi
|
||||
|
||||
# Get the current date in YYYY-MM-DD format
|
||||
current_date=$(date +%Y-%m-%d)
|
||||
|
||||
# Calculate the start and end timestamps based on the current date and time
|
||||
start_timestamp=$(date -d "${current_date} ${color_start_time}" +%s)
|
||||
end_timestamp=$(date -d "${current_date} ${color_end_time}" +%s)
|
||||
|
||||
# Get the current timestamp
|
||||
current_timestamp=$(date +%s)
|
||||
|
||||
# Calculate the transition ratio
|
||||
transition_ratio=$(awk "BEGIN { ratio = ($current_timestamp - $start_timestamp) / ($end_timestamp - $start_timestamp); print ratio }")
|
||||
|
||||
# Calculate the current color based on the transition ratio
|
||||
current_color=$(calculate_color "$color_start" "$color_end" "$transition_ratio")
|
||||
|
||||
echo "Changing keyboard color to #$current_color."
|
||||
|
||||
# Set the color using msi-perkeyrgb
|
||||
msi-perkeyrgb --model GS65 -s "$current_color" --id "$vendor_and_product_id"
|
12
roles/driver-msi-keyboard-color/meta/main.yml
Normal file
12
roles/driver-msi-keyboard-color/meta/main.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
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:
|
||||
- system-aur-helper
|
||||
- systemd_notifier
|
9
roles/driver-msi-keyboard-color/tasks/main.yml
Normal file
9
roles/driver-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
|
8
roles/driver-msi-keyboard-color/tasks/setup_script.yml
Normal file
8
roles/driver-msi-keyboard-color/tasks/setup_script.yml
Normal file
@@ -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
|
30
roles/driver-msi-keyboard-color/tasks/setup_timers.yml
Normal file
30
roles/driver-msi-keyboard-color/tasks/setup_timers.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
- name: Copy keyboard-color.timer file
|
||||
template:
|
||||
src: keyboard-color.timer.j2
|
||||
dest: /etc/systemd/system/keyboard-color.timer
|
||||
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: restarted
|
||||
enabled: yes
|
||||
tags:
|
||||
- keyboard-color
|
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Keyboard Color Service
|
||||
OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/opt/keyboard_color.sh {{ vendor_and_product_id }}
|
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Keyboard Color Timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_msi_keyboard_color}}
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Reference in New Issue
Block a user