Advertisement
nariox

set-power-uuid.sh

Sep 15th, 2020
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -eu
  4.  
  5.  
  6. die() {
  7.     echo "$1" >&2
  8.     exit 1
  9. }
  10.  
  11.  
  12. main() {
  13.     local uuid="$1"; shift
  14.  
  15.     echo $uuid
  16.  
  17.     # Ensure we have the device node
  18.     if [[ ! -d /sys/devices/platform/INT3400:00/ ]]; then
  19.         die "INT3400 device not found"
  20.     fi
  21.  
  22.     # Ensure we have the thermal zone...
  23.     local zone
  24.     for zone in /sys/class/thermal/thermal_zone?; do
  25.         if [[ -f "$zone/type" ]] && [[ "$(cat $zone/type)" = "INT3400 Thermal" ]]; then
  26.             break
  27.         fi
  28.     done
  29.     if [[ -z "${zone:-}" ]]; then
  30.         die "Could not find 'INT3400 Thermal' thermal zone"
  31.     fi
  32.  
  33.     # ... and that we can enable/disable it (which is only true when the right
  34.     # kernel patches are present).
  35.     if [[ ! -f "$zone/mode" ]]; then
  36.         die "Thermal zone 'mode' not found; are the kernel patches applied?"
  37.     fi
  38.  
  39.     # Ensure the given UUID exists in the `available_uuids` set.
  40.     if ! grep -q "^$uuid$" "/sys/devices/platform/INT3400:00/uuids/available_uuids" 2>&1 >/dev/null; then
  41.         die "UUID '$uuid' is not supported by the device"
  42.     fi
  43.  
  44.     # Okay, all set!  Disable zone, set UUID, then enable.
  45.     echo disabled > "$zone/mode"
  46.     echo "$uuid" > "/sys/devices/platform/INT3400:00/uuids/current_uuid"
  47.     echo enabled > "$zone/mode"
  48.     echo "Set UUID to: $uuid" >&2
  49.  
  50.     # Ensure that the UUID set properly by reading it back.
  51.     if [[ "$(cat /sys/devices/platform/INT3400:00/uuids/current_uuid)" != "$uuid" ]]; then
  52.         die "UUID did not set correctly"
  53.     fi
  54.  
  55.     echo "Success" >&2
  56. }
  57.  
  58.  
  59. if [ -z "$*" ]; then
  60.     main "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D"
  61. else
  62.     main "$@"
  63. fi
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement