1 (edited by auanta 2023-03-06 20:08:18)

Topic: [solved] Hibernation in Hyperbola (and a battery script for you!)

Update: Please view the final post in this thread for a solution on how to hibernate your computer and have comprehensive battery alerts without need of a taskbar or status bar, so you can save on screen space and mental distraction; more importantly, you save your precious files from corruption.

Hello all,

I left my  computer suspended for DAYS and I came back to see it was still at 81%! I love that for me!  It required no configuration at all!

However, I have yet to figure out hibernate. Does anyone happen to know how to make hibernation work in Hyperbola?

I'm using syslinux, so the grub solutions don't work.

It appears there is a custom ACPI script . I would edit it, but that's beyond my skill. It's located at /etc/acpi/handler.sh

Bonus, I have a battery script you can use. It needs acpid and herbe as dependencies. You can, if you wish, use espeak too.

#!/bin/bash

# Modified from: https://gist.github.com/bandaangosta/0a0fdbd03215b925576c4b234fc4d4f1
# Credits to user BlackVeils and bandaangosta

# Steps:
# 1. Save this script to battery_notify.sh
# 2. Edit the 'alarm' variable to point to your sound file of choice
# 3. Give execution permission: chmod +x battery_notify.sh
# 4. Run the script to test it. If happy, add to your startup applications.

# Set the alert tone for battery, or leave it as empty quotes.
# choose an audio file
alarm=""

# Notify when below this percentage
low_warning=21

#Notify when above this percentage
high_warning=79

# How often to check battery status, in minutes
check_interval=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed 's/%//g')
  charging=$(acpi -b | grep -c "Charging")

  # When battery is low, and not already charging
  if [ $battery_level -lt $low_warning ] &&
     [ $charging -eq 0 ]
  then
#    play -q -v 0.40 "$alarm" &
# espeak "Atencion, la bateria ya tiene 20%, por favor conecte el cargador" -s 140
    herbe " Low battery: ${battery_level}% " \
      " Bateria tiene 20%, ve a recargarlo! "
  fi

  # When battery is high, and charging
  if [ $battery_level -gt $high_warning ] &&
     [ $charging -eq 1 ]
  then
#    play -q -v 0.40 "$alarm" &
# espeak "Atencion, la bateria ya tiene 80%, por favor quite el cargador" - s 140
    herbe " High battery: ${battery_level}% " \
      " Bateria tiene 80%, disconecte el cargador ahora "
  fi
  
  sleep ${check_interval}m
done

2

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Yes: You can use uswsusp for this. Here more information about that kernel-module also: https://wiki.archlinux.org/title/Uswsusp

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!

3

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

You can also use zzz being part of testing and coming with the release 0.4.2. smile

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!

4

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

throgh wrote:

You can also use zzz being part of testing and coming with the release 0.4.2. smile

With or without runit?

wink

If it is without it, I could starting using it on my non libreboot x200 devices and potentially more, without conflict between tpad-tools.

Btw,  thank you all for what you do for the free software community.

I haven't said this for a while, due to not wanting to appear, to be, bribing/playing up to you all, but yeah, I very much mean it.

smile

HyperbolaBSD: The Future of Secure Libre Lightweight Operating Systems!

5

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Oh, the package "zzz" can be used completely without runit. I'm using it here since weeks on a test-installation. More in details:

fluxbox
tint3 (with common additions)
spacefm
zzz (for suspend)

Before leaving that out: Sure, you need to add the command within /etc/doas.conf as "/usr/sbin/zzz" to execute without password. After that: You are free to do, also with OpenRC. And ... perhaps others to come. But that's quite to early to say as testing is early into this. Runit and OpenRC are the stable ones within our system for the moment, with the thoughts for HyperbolaBSD also.

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!

6

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

throgh wrote:

Oh, the package "zzz" can be used completely without runit. I'm using it here since weeks on a test-installation. More in details:

fluxbox
tint3 (with common additions)
spacefm
zzz (for suspend)

Before leaving that out: Sure, you need to add the command within /etc/doas.conf as "/usr/sbin/zzz" to execute without password. After that: You are free to do, also with OpenRC. And ... perhaps others to come. But that's quite to early to say as testing is early into this. Runit and OpenRC are the stable ones within our system for the moment, with the thoughts for HyperbolaBSD also.

That is good news at least.

Btw, I noticed there  was a low power mode option, what does this do in Hyperbola? Is it like hibernate, or something else?

Just curious...

zzz seems to work fine tho. smile

zzz can be used without runit?

I always get the conflict issue... very strange...

tpad-tools is the only other interest, but no worries...

I suppose I might  not need it anyhow...

I will miss though that one function of random mac address.

tongue

HyperbolaBSD doesn't have any alpha isos yet right?

If there is, you may want to distribute as qcow2 images if anyone has interest in testing... and not the iso itself!

Just a thought till it is at beta stability...

Although maybe not, just again... a thought.

HyperbolaBSD: The Future of Secure Libre Lightweight Operating Systems!

7

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Yes, zzz can be used alone. And changing the mac-address is also possible: https://www.hyperbola.info/packages/?so … p;flagged=

About ISO for HyperbolaBSD: Not yet as we are working on the kernel.

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!

8

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

throgh wrote:

Yes, zzz can be used alone. And changing the mac-address is also possible: https://www.hyperbola.info/packages/?so … p;flagged=

About ISO for HyperbolaBSD: Not yet as we are working on the kernel.

As well as the package manager and similar stuff, right? Aka, for HyperbolaBSD...

Aka, its more than just the kernel that needs to worked on, right?

Didn't tpad-tools do this randomly anytime you connected to the internet via x200?

Although, couldn't figure out how to get the backup/thinkvantage functions to work on it yet either. :s

Either way, I am willing to bet you are close to both alpha and beta, given the team has been working on parts of both at the same time.

Watching with interest though when  I can though! smile

HyperbolaBSD: The Future of Secure Libre Lightweight Operating Systems!

9 (edited by auanta 2023-03-05 12:39:50)

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Hello! I waited for the release of zzz and tried it out. The default behavior I am seeing, contrary to the manpage, is it causes the computer to suspend but not hibernate.

When I doas zzz -Z to force it to hibernate, it looks as if it does but when I turn the computer on, it shows on bootup that the ext4 filesystem is repairing the journal, and my previous session's commands in bash are unsaved. This is what typically happens when my computer runs out of power and shutdown improperly.

OK I am trying uswsusp..How do I rebuild the ramdisk? Oh, simply reinstall linux:

pacman -S linux

(1/1) reinstalling linux-libre-lts                                                                            [#################################################################] 100%
>>> Updating module dependencies. Please wait ...
:: Running post-transaction hooks...
(1/2) Updating module dependencies...
(2/2) Updating linux-libre-lts initcpios
==> Building image from preset: /etc/mkinitcpio.d/linux-libre-lts.preset: 'default'
  -> -k /boot/vmlinuz-linux-libre-lts -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-libre-lts.img
==> Starting build: 5.10.127-gnu1-1-lts
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
  -> Running build hook: [uresume]
  -> Running build hook: [filesystems]
  -> Running build hook: [keyboard]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating xz-compressed initcpio image: /boot/initramfs-linux-libre-lts-fallback.img
==> Image generation successful

Sure took a while to finish generating...but it did!

$ doas s2disk

OMG! It hibernated successfully!

Would it be possible for me to change /etc/acpi/handler.sh to hibernate at 5%? Would uswsusp's s2disk therefore be the command in this acpi handler script?

'button/power')
  case "${2}" in
  'PBTN'|'PWRF')
    if [ -x '/sbin/openrc-shutdown' ]; then
      openrc-shutdown -p
    else
      poweroff -p
    fi
    ;;
  esac
  ;;
'battery')
  case "${2}" in
  'BAT'?|'PNP'?'C'??)
    case "${4}" in
    '00000000')
      # battery online
      ;;
    '00000001')
      # battery offline
      ;;
    esac
    ;;
  esac
  ;;
'button/sleep')
  case "${2}" in
  'SBTN'|'SLPB')
    case "${UNAME}" in
    'Linux')
      printf "${ACPID_ST}" > '/sys/power/state'
      ;;
    esac
    ;;
  esac
  ;;

I have to figure out how to make my own hibernate lines.
Maybe this? https://github.com/thcipriani/acpi/blob … handler.sh
https://gist.github.com/nk23x/7600782

Meanwhile, I modified the userspace bash script to hibernate when battery is below 6%. I need to figure out how to make it run at boot with rc-update but the world's search engines all appear to be broken. :?

#!/bin/bash

# Modified from: https://gist.github.com/bandaangosta/0a0fdbd03215b925576c4b234fc4d4f1
# Credits to user BlackVeils and bandaangosta

# Steps:
# 1. Save this script to battery_notify.sh
# 2. Edit the 'alarm' variable to point to your sound file of choice
# 3. Give execution permission: chmod +x battery_notify.sh
# 4. Run the script to test it. If happy, add to your startup applications.

# Set the alert tone for battery, or leave it as empty quotes.
# choose an audio file
alarm=""

# Notify when below this percentage
low_warning=21

# Notify when above this percentage
high_warning=79

# Hibernate when critically low
crit_level=6

# How often to check battery status, in minutes
check_interval=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed 's/%//g')
  charging=$(acpi -b | grep -c "Charging")

  # When battery is critically low, and not already charging
  if [ $battery_level -lt $crit_level ] &&
     [ $charging -eq 0 ]
  then
#    play -q -v 0.40 "$alarm" &
# espeak "Atencion, la bateria ya tiene 20%, por favor conecte el cargador" -s 140
    herbe " Low battery: ${battery_level}% " \
      " Bateria tiene 5%, el sistema ya se hiberna! "
    s2disk
  fi

  # When battery is low, and not already charging
  if [ $battery_level -lt $low_warning ] &&
     [ $charging -eq 0 ]
  then
#    play -q -v 0.40 "$alarm" &
# espeak "Atencion, la bateria ya tiene 20%, por favor conecte el cargador" -s 140
    herbe " Low battery: ${battery_level}% " \
      " Bateria tiene 20%, ve a recargarlo! "
  fi

# When battery is high, and charging
  if [ $battery_level -gt $high_warning ] &&
     [ $charging -eq 1 ]
  then
#    play -q -v 0.40 "$alarm" &
# espeak "Atencion, la bateria ya tiene 80%, por favor quite el cargador" - s 140
    herbe " High battery: ${battery_level}% " \
      " Bateria tiene 80%, disconecte el cargador ahora "
  fi
  
  sleep ${check_interval}
done

10

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Hello! So I now understand that the /etc/acpi/handler.sh script is a Bourne shell script and it is compatible with my Bash script, but I am having weird problems when I add my modifications to the script directly. The power button stops working, for example. The weirdness stops when I remove my modifications. Here is my script:

#!/bin/sh
# default acpi script that takes an entry for all actions.

. '/etc/conf.d/acpid'

# check OS name with HyperbolaBSD uname.
UNAME="$(uname -s)"

acpid_ac_adapter() {
  case "${1}" in
  'plug')
    LAD="${ACPID_AP}"
    ;;
  'unplug')
    LAD="${ACPID_AU}"
    ;;
  *)
    return
    ;;
  esac

  case "${UNAME}" in
  'Linux')
    LFD="/sys/class/backlight/${ACPID_AB}"
    LBF="${LFD}/brightness"
    LMF="${LFD}/max_brightness"
    unset LFD
    printf "$((${LAD}*$(su -c 'cat '${LMF})/100))" > "${LBF}"
    unset LBF LMF
    ;;
  'HyperbolaBSD'|*)
    return
    ;;
  esac

  unset LAD
}

acpid_echo_sound() {
  _play_audio() {
    case "${1}" in
    'sndio')
      LSS="${1}"
      LSF="snd/${ACPID_SC}"
      ;;
    *)
      case "${UNAME}" in
      'Linux')
        LSS='alsa'
        LSF="hw:${ACPID_SC}"
        ;;
      'HyperbolaBSD'|*)
        LSS='oss'
        LSF="/dev/dsp${ACPID_SC}"
        ;;
      esac
      ;;
    esac

    LFD='/usr/share/sounds/freedesktop/stereo'
    LFF="${LFD}/audio-volume-change.oga"
    unset LFD

    if [ -x '/usr/bin/ffmpeg' ] && [ -f "${LFF}" ]; then
      LXC='-loglevel -8'
      ffmpeg "${LXC}" -i "${LFF}" -f "${LSS}" "${LSF}"
      unset LXC
    fi

    unset LDF LFF LSF LSS
  }

  _cksrv_and_play_audio() {
    case "${1}" in
    'openrc')
      LSC='rc-service sndiod status'
      ;;
    'runit')
      LSC='sv status sndiod'
      ;;
    esac

    case "$(${LSC})" in
    ' * status: started'|'run: sndio')
      _play_audio 'sndio'
      ;;
    *)
      _play_audio
      ;;
    esac

    unset LSC
  }

  if [ -x '/sbin/rc-service' ]; then
    _cksrv_and_play_audio 'openrc'
  elif [ -x '/usr/bin/sv' ]; then
    _cksrv_and_play_audio 'runit'
  fi
}

acpid_video_brightness() {
  case "${1}" in
  'up')
    LCB='+'
    ;;
  'down')
    LCB='-'
    ;;
  *)
    return
    ;;
  esac

  case "${UNAME}" in
  'Linux')
    LFD="/sys/class/backlight/${ACPID_AB}"
    LBF="${LFD}/brightness"
    LMF="${LFD}/max_brightness"
    unset LFD
    printf "$((${ACPID_BP}*$(su -c 'cat '${LMF})/100 ${LCB} $(cat ${LBF})))" \
      > "${LBF}"
    unset LBF LMF
    ;;
  'HyperbolaBSD'|*)
    return
    ;;
  esac

  unset LCB
}

case "${1}" in
'ac_adapter')
  case "${2}" in
  'AC'|'ACAD'|'ACPI'????':'??|'ADP'?)
    case "${4}" in
    '00000000')
      # ac pluged
      acpid_ac_adapter 'plug'
      ;;
    '00000001')
      # ac unpluged
      acpid_ac_adapter 'unplug'
      ;;
    esac
    ;;
  esac
  ;;
'battery')
  case "${2}" in
  'BAT'?|'PNP'?'C'??)
    case "${4}" in
    '00000000')
      # battery online
      ;;
    '00000001')
      # battery offline
      ;;
    esac
    ;;
  esac
  ;;
'button/lid')
  case "${3}" in
  'close')
    case "${UNAME}" in
    'Linux')
      printf "${ACPID_ST}" > '/sys/power/state'
      ;;
    esac
    ;;
  'open')
    ;;
  esac
  ;;
'button/mute')
  case "${2}" in
  'MUTE')
    case "${UNAME}" in
    'Linux')
      if [ -x '/usr/bin/amixer' ]; then
        amixer -c "${ACPID_SC}" set 'Master' toggle
      fi
      acpid_echo_sound
      ;;
    #'HyperbolaBSD'|*)
    #  if [ -x '/usr/bin/sndioctl' ]; then
    #    sndioctl -nq snd/${ACPID_SC}.mute='off'
    #  elif [ -x '/usr/sbin/mixerctl' ]; then
    #    mixerctl -qf "/dev/audioctl${ACPID_SC}" output.dac.mute='off'
    #  fi
    #  acpid_echo_sound
    #  ;;
    esac
    ;;
  esac
  ;;
'button/power')
  case "${2}" in
  'PBTN'|'PWRF')
    if [ -x '/sbin/openrc-shutdown' ]; then
      openrc-shutdown -p
    else
      poweroff -p
    fi
    ;;
  esac
  ;;
'button/sleep')
  case "${2}" in
  'SBTN'|'SLPB')
    case "${UNAME}" in
    'Linux')
      printf "${ACPID_ST}" > '/sys/power/state'
      ;;
    esac
    ;;
  esac
  ;;
'button/volumedown')
  case "${2}" in
  'VOLDN')
    case "${UNAME}" in
    'Linux')
      if [ -x '/usr/bin/amixer' ]; then
        amixer -c "${ACPID_SC}" set 'Master' "${ACPID_SP}%-"
      fi
        acpid_echo_sound
      ;;
    #'HyperbolaBSD'|*)
    #  if [ -x '/usr/bin/sndioctl' ]; then
    #    sndioctl -nq snd/${ACPID_SC}.level-="${ACPID_SP}"
    #  elif [ -x '/usr/sbin/mixerctl' ]; then
    #    mixerctl -qf "/dev/audioctl${ACPID_SC}" \
    #      output.dac.level-="${ACPID_SP}"
    #  fi
    #  acpid_echo_sound
    #  ;;
    esac
    ;;
  esac
  ;;
'button/volumeup')
  case "${2}" in
  'VOLUP')
    case "$(uname -s)" in
    'Linux')
      if [ -x '/usr/bin/amixer' ]; then
        amixer -c "${ACPID_SC}" set 'Master' "${ACPID_SP}%+"
      fi
      acpid_echo_sound
      ;;
    #'HyperbolaBSD'|*)
    #  if [ -x '/usr/bin/sndioctl' ]; then
    #    sndioctl -nq snd/${ACPID_SC}.level+="${ACPID_SP}"
    #  elif [ -x '/usr/sbin/mixerctl' ]; then
    #    mixerctl -qf "/dev/audioctl${ACPID_SC}" \
    #      output.dac.level+="${ACPID_SP}"
    #  fi
    #  acpid_echo_sound
    #  ;;
    esac
    ;;
  esac
  ;;
'jack/headphone')
  case "${2}" in
  'HEADPHONE')
    case "${3}" in
    'plug')
      ;;
    'unplug')
      ;;
    esac
    ;;
  esac
  ;;
'video/brightnessdown')
  case "${2}" in
  'BRTDN')
    acpid_video_brightness 'down'
    ;;
  esac
  ;;
'video/brightnessup')
  case "${2}" in
  'BRTUP')
    acpid_video_brightness 'up'
    ;;
  esac
  ;;
'video/switchmode')
  case "${2}" in
  'VMOD')
    ;;
  esac
  ;;
'cd/next')
  case "${2}" in
  'CDNEXT')
    ;;
  esac
  ;;
'cd/play')
  case "${2}" in
  'CDPLAY')
    # It is disabled, because it is not supported with multimedia keys and
    # it was not tested.
    #if [ -x '/usr/bin/mpv' ]; then
    #  mpv 'cdda://:1' -cache '1024'
    #elif [ -x '/usr/bin/mplayer' ]; then
    #  mplayer 'cdda://:1' -cache '1024'
    #fi
    ;;
  esac
  ;;
'cd/prev')
  case "${2}" in
  'CDPREV')
    ;;
  esac
  ;;
'cd/stop')
  case "${2}" in
  'CDSTOP')
    ;;
  esac
  ;;
esac

# Modified from: https://gist.github.com/bandaangosta/0a0fdbd03215b925576c4b234fc4d4f1
# Credits to user BlackVeils and bandaangosta

# Notify when below this percentage
low_warning=21

# Notify when above this percentage
high_warning=79

# Hibernate when critically low
crit_level=6

# How often to check battery status, in minutes
check_interval=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed 's/%//g')
  charging=$(acpi -b | grep -c "Charging")

  # When battery is critically low, and not already charging
  if [ $battery_level -lt $crit_level ] &&
     [ $charging -eq 0 ]
  then
    wall " Bateria criticamente baja: ${battery_level}% " \
      " Bateria tiene 5%, el sistema ya se hiberna! "
    s2disk
  fi

  # When battery is low, and not already charging
  if [ $battery_level -lt $low_warning ] &&
     [ $charging -eq 0 ]
  then
   wall " Bateria baja: ${battery_level}% " \
      " Bateria tiene menos que 20%, ve a recargarla! "
   sleep 1
  fi

# When battery is high, and charging
  if [ $battery_level -gt $high_warning ] &&
     [ $charging -eq 1 ]
  then
    wall " Bateria alta: ${battery_level}% " \
      " Bateria tiene mas que 80%, disconecte el cargador ahora "
    sleep 1
  fi
  
  sleep ${check_interval}
done

11

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

I have updated the script so that this portion is nested:

acpi_battery() {

    # Notify when below this percentage
    low_warning=21
    # Notify when above this percentage
    high_warning=79
    # Hibernate when critically low
    crit_level=6
    # How often to check battery status, in minutes
    check_interval=5

    while true; do
      battery_level=$(acpi -b \
      | cut -d, -f2 | cut --characters=2,3,4 \
      | sed 's/%//g')
    charging=$(acpi -b | grep -c "Charging")

      # When battery is critically low, and not already charging
        if [ $battery_level -lt $crit_level ] &&
         [ $charging -eq 0 ]
        then
        wall " Bateria criticamente baja: ${battery_level}% " \
             " Bateria tiene 5%, el sistema ya se hiberna! "
        s2disk
        fi
       # When battery is low, and not already charging
        if [ $battery_level -lt $low_warning ] &&
         [ $charging -eq 0 ]
        then
        wall " Bateria baja: ${battery_level}% " \
             " Bateria tiene menos que 20%, ve a recargarla! "
         sleep 1
        fi
    # When battery is high, and charging
      if [ $battery_level -gt $high_warning ] &&
         [ $charging -eq 1 ]
      then
        wall " Bateria alta: ${battery_level}% " \
             " Bateria tiene mas que 80%, disconecte el cargador ahora "
         sleep 1
      fi

    sleep ${check_interval}
    done
    unset low_warning high_warning crit_level check_interval
    }

Now I do not have anymore weird problems like that.

However, now my script is not being called, I guess, as it does not work.

12 (edited by auanta 2023-03-06 04:58:15)

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

(Mods if youre reading this, you can leave this up)

OK, I have updated my script once again.

This time, instead of including my modifications in /etc/acpi/handler.sh I invoke my script by calling it in a separate file.

#!/bin/sh
# default acpi script that takes an entry for all actions.

. '/etc/conf.d/acpid'
. '/etc/conf.d/acpi_handler.d.sh'

In my debugging process I learned that ny efforts to nest the script cause it to be useless, so I removed the nesting. Contents of /etc/conf.d/acpi_handler.d.sh :

    # Notify when below this percentage
    low_warning=21
    # Notify when above this percentage
    high_warning=79
    # Hibernate when critically low
    crit_level=6
    # How often to check battery status, in minutes
    check_interval=5

    while true; do
      battery_level=$(acpi -b \
      | cut -d, -f2 | cut --characters=2,3,4 \
      | sed 's/%//g')
    charging=$(acpi -b | grep -c "Charging")

      # When battery is critically low, and not already charging
        if [ $battery_level -lt $crit_level ] &&
         [ $charging -eq 0 ]
        then
        wall " Bateria criticamente baja: ${battery_level}% " \
             " Bateria tiene 5%, el sistema ya se hiberna! "
        s2disk
        fi
       # When battery is low, and not already charging
        if [ $battery_level -lt $low_warning ] &&
         [ $charging -eq 0 ]
        then
        wall " Bateria baja: ${battery_level}% " \
             " Bateria tiene menos que 20%, ve a recargarla! "
        fi
    # When battery is high, and charging
      if [ $battery_level -gt $high_warning ] &&
         [ $charging -eq 1 ]
      then
        wall " Bateria alta: ${battery_level}% " \
             " Bateria tiene mas que 80%, disconecte el cargador ahora "
      fi

    sleep ${check_interval}m
    done
    unset low_warning high_warning crit_level check_interval

However, now the power button does not work again, I have still broken the handler.sh so I think I need to nest my script and find a way to invoke it while making it play nice with handler.sh

Now for the good news: I set up graphical pop-up reminders, and optional sound notifications by launching a second separate, non-root script from .xinitrc. This is useful when your terminal does not support such things as utmp or you just want the animated, ephemeral pop up notifications. Here is the script you can use:

#!/bin/bash

# Set the alert tone for battery, or leave it as empty quotes.
# choose an audio file
#alarm=""

# Notify when below this percentage
low_warning=21

# Notify when above this percentage
high_warning=79

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed 's/%//g')
  charging=$(acpi -b | grep -c "Charging")
  sleep 1m

    # When battery is low, and not already charging
    if [ $battery_level -lt $low_warning ] &&
       [ $charging -eq 0 ]
    then
      #play -q -v 0.40 "$alarm" &
      #espeak "blablabla" -s 140
      herbe "Batteria baja: ${battery_level}% " \
            " Bateria no tiene carga suficiente, ve a recargarla ahora para protegerla. "
       sleep 1m
      fi

    # When battery is high, and charging
     if [ $battery_level -gt $high_warning ] &&
        [ $charging -eq 1 ]
     then
      #play -q -v 0.40 "$alarm" &
      #espeak "blablabla" - s 140
      herbe " Batteria alta: ${battery_level}% " \
      " Bateria ya esta llena, disconecte el cargador ahora para protegerla."
       sleep 5m
      fi
done

Then just set up your .xinitrc:

light -S 5 &
. /home/you/yourscripts/battery_notify.sh &
redshift &
exec cwm

The script definitely works well, no apparent bugs that I found, but when it comes to harmonious coexistence between handler.sh and handler.d.sh, I can't yet get handler.d.sh to stop disabling some of the handler.sh functionality.

13 (edited by auanta 2023-03-06 19:54:34)

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Hello everyone,

I will now mark this as solved because I figured out how to fix my script. For these scripts to work, you need to install uswsusp (to gain access to the s2disk command), wall, herbe (optional), alsa-utils (optional), and espeak (optional). And here is the final product:

1. The /etc/acpi/handler.sh has this modification:
At the very bottom, put:

. '/etc/conf.d/acpi_handler.d.sh'

2. /etc/conf.d/acpi_handler.d.sh :

hibernate_notify () {
    # Notify when below this percentage
    low_warning=21
    # Notify when above this percentage
    high_warning=79
    # Hibernate when critically low
    crit_level=6
    # How often to check battery status, in minutes
    check_interval=5

    while true; do
      battery_level=$(acpi -b \
      | cut -d, -f2 | cut --characters=2,3,4 \
      | sed 's/%//g')
    charging=$(acpi -b | grep -c "Charging")

      # When battery is critically low, and not already charging
        if [ $battery_level -lt $crit_level ] &&
         [ $charging -eq 0 ]
        then
        wall " Bateria criticamente baja: ${battery_level}% " \
             " Bateria tiene 5%, el sistema ya se hiberna! "
        s2disk
        fi
       # When battery is low, and not already charging
        if [ $battery_level -lt $low_warning ] &&
         [ $charging -eq 0 ]
        then
        wall " Bateria baja: ${battery_level}% " \
             " Bateria tiene menos que 20%, ve a recargarla! "
        fi
    # When battery is high, and charging
      if [ $battery_level -gt $high_warning ] &&
         [ $charging -eq 1 ]
      then
        wall " Bateria alta: ${battery_level}% " \
             " Bateria tiene mas que 80%, disconecte el cargador ahora "
      fi

    sleep ${check_interval}m
    done
    unset low_warning high_warning crit_level check_interval
}

hibernate_notify

Optional: for graphical notification bubbles
3. Put this in your .xinitrc before any exec commands:

. ~/battery_notify.sh &

4. Contents of battery_notify.sh :

#!/bin/bash

# Set the alert tone for battery, or leave it as empty quotes.
# specify path to an audio file
#alarm=""

# Notify when below this percentage
low_warning=21
low_alarm=""
low_repeat=1

# Notify when above this percentage
high_warning=79
high_alarm=""
high_repeat=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed 's/%//g')
  charging=$(acpi -b | grep -c "Charging")
  sleep 1m

    # When battery is low, and not already charging
    if [ $battery_level -lt $low_warning ] &&
       [ $charging -eq 0 ]
    then
      #play -q -v 0.40 "$low_alarm" &
      #espeak "blablabla" -s 140
      herbe "Batteria baja: ${battery_level}% " \
            " Bateria no tiene carga suficiente, ve a recargarla ahora para protegerla. "
       sleep ${low_repeat}m
      fi

    # When battery is high, and charging
     if [ $battery_level -gt $high_warning ] &&
        [ $charging -eq 1 ]
     then
      #play -q -v 0.40 "$alarm" &
      #espeak "blablabla" - s 140
      herbe " Batteria alta: ${battery_level}% " \
      " Bateria ya esta llena, disconecte el cargador ahora para protejerla."
       sleep ${high_repeat}m
      fi
done

I am very satisfied with its outcome and I hope that others will consider using it.

14

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

The only weird bug I experienced is the power button stopped triggering shutdown (equivalent to openrc-shutdown -p). The suspend on lid close also stopped working but recently started working again. All the other acpi related buttons work.

My friend and I looked over the scripts and we can't figure out why.

To some, this lack of power button responsiveness may be a bonus.

Hopefully I get better at this so I can make it perfect.

15

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

Hey, if you think this is ready for distribution: Would you be interested doing so? Either you choose a git-repository like notabug or codeberg. Or we can do something via Hyperbola direct, if you want.

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!

16 (edited by auanta 2023-03-26 22:31:12)

Re: [solved] Hibernation in Hyperbola (and a battery script for you!)

throgh wrote:

Hey, if you think this is ready for distribution: Would you be interested doing so? Either you choose a git-repository like notabug or codeberg. Or we can do something via Hyperbola direct, if you want.

As soon as I work out the weird buggyness, sure smile I mean, I just feel bad inflicting this on unsuspecting users, Idk what I'm doing. Would be good if an expert reviewed and patched it!