You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0+
  3. # Copyright (C) 2018, Martin Kepplinger <martink@posteo.de>
  4. RED='\033[0;31m'
  5. GREEN='\033[0;32m'
  6. YELLOW='\033[0;33m'
  7. NC='\033[0m'
  8. check_x230_root()
  9. {
  10. command -v dmidecode >/dev/null 2>&1 || { echo -e >&2 "${RED}Please install dmidecode and run as root.${NC}"; exit 1; }
  11. local LAPTOP=$(dmidecode | grep -i x230 | sort -u)
  12. if [ -z "$LAPTOP" ] ; then
  13. echo "This is no Thinkpad X230. This script is useless then."
  14. exit 0
  15. fi
  16. }
  17. check_battery() {
  18. local capacity=$(cat /sys/class/power_supply/BAT*/capacity 2>/dev/null || echo -ne "0")
  19. local online=$(cat /sys/class/power_supply/AC/online 2>/dev/null || cat /sys/class/power_supply/ADP*/online 2>/dev/null || echo -ne "0")
  20. local failed=0
  21. if [ "${online}" == "0" ] ; then
  22. failed=1
  23. fi
  24. if [ "${capacity}" -lt 25 ]; then
  25. failed=1
  26. fi
  27. if [ $failed == "1" ]; then
  28. echo -e "${YELLOW}WARNING:${NC} To prevent shutdowns, we recommend to only run this script when"
  29. echo " your laptop is plugged in to the power supply AND"
  30. echo " the battery is present and sufficiently charged (over 25%)."
  31. while true; do
  32. read -r -p "Continue anyways? (please do NOT!) y/N: " yn
  33. case $yn in
  34. [Yy]* ) break;;
  35. [Nn]* ) exit;;
  36. * ) exit;;
  37. esac
  38. done
  39. fi
  40. }
  41. warn_not_root() {
  42. if [[ $EUID -eq 0 ]]; then
  43. echo -e "${RED}This script should not be run as root!${NC}"
  44. fi
  45. }