From f5f657f702d060168fc23c15cefb0366210724c3 Mon Sep 17 00:00:00 2001 From: L3D Date: Mon, 11 Mar 2019 20:22:44 +0100 Subject: [PATCH] Add akku warning script --- roles/akku-warning/files/akku.sh | 11 +++++++++++ roles/akku-warning/tasks/main.yml | 26 ++++++++++++++++++++++++++ setup.yml | 9 +++++++++ 3 files changed, 46 insertions(+) create mode 100644 roles/akku-warning/files/akku.sh create mode 100644 roles/akku-warning/tasks/main.yml diff --git a/roles/akku-warning/files/akku.sh b/roles/akku-warning/files/akku.sh new file mode 100644 index 0000000..9e4b9a8 --- /dev/null +++ b/roles/akku-warning/files/akku.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +power="$((`cat /sys/class/power_supply/BAT0/energy_now` * 100 / `cat /sys/class/power_supply/BAT0/energy_full_design`))" + +if (( $power < 15 && $power > 9 )); then + zenity --warning --title="Low Power" --text="$power percent remaining.\n\nPlease recharge soon!" --display=:0.0 +elif (( $power < 9 && $power > 5 )); then + zenity --warning --title="Critical Power" --text="$power percent remaining.\n\nPlease recharge NOW!" --display=:0.0 +elif (( $power < 5 )); then + zenity --warning --title="Critical Power" --text="$power percent remaining.\n\nRECHARGE!\nNOW!" --display=:0.0 +fi diff --git a/roles/akku-warning/tasks/main.yml b/roles/akku-warning/tasks/main.yml new file mode 100644 index 0000000..4ef80e2 --- /dev/null +++ b/roles/akku-warning/tasks/main.yml @@ -0,0 +1,26 @@ +--- + +- name: copy sound warning script + become: yes + copy: + src: 'files/akku.sh' + dest: '/opt/akku.sh' + owner: 'root' + group: 'root' + mode: '0755' + +- name: install zenity + become: yes + package: + name: zenity + state: present + +- name: Check akku every 2 minutes + become: yes + cron: + name: check if akku still okay + job: /opt/akku.sh + minute: '*/2' + user: root + cron_file: /etc/crontab + diff --git a/setup.yml b/setup.yml index 03330f2..9e57789 100644 --- a/setup.yml +++ b/setup.yml @@ -26,6 +26,15 @@ roles: - dotfiles +- name: set akku warning + hosts: thinkpad + tags: + - setup + - akku + roles: + - akku-warning + + - name: install modules for sound and bluetooth hosts: thinkpad tags: