Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
makifdb committed Jan 21, 2022
0 parents commit 71d3f53
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
22 changes: 22 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Maintainer: Mehmet Akif Duba <mail[at]makifdb[dot]com>

# Based on the code from:
# Lenovsky <lenovsky@pm.me>

pkgname=lenopow
pkgver=1.0.4
pkgrel=1
pkgdesc="A script to enable/disable battery conservation mode in Lenovo Ideapad/LEGION notebooks."
arch=('any')
url="https://github.com/makifdb/${pkgname}"
license=('custom:unlicense')
source=("https://github.com/makifdb/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('3a018b070e08df728a39bdd6d4bf1a75083b06c3fe6a0b54ac11e6895fa2e4ec')

package() {
cd "${srcdir}/${pkgname}-${pkgver}"

make PREFIX=/usr DESTDIR="${pkgdir}" install
install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# lenopow

> Lenovo Ideapad/LEGION battery conservation mode on Manjaro Linux
**lenopow** allows managing Lenovo Ideapad's/LEGION's firmware on the battery
and shifts between the usual charging thresholds from 95/100% to 55/60%.
In some cases, not charging the battery to 100% constantly may improve
the overall lifespan of the battery. This setting is suggested for a system
that is always plugged into the AC adapter.

## Instalation

The standard `make install` routine is used.

The following additional variables are supported:

- `DESTDIR` -- determines environment for staged installs,
- `PREFIX` -- determines where the script will be installed (default: `/usr/local`).

## Requirements

The script requires the following to run:

- `bash`
- `linux >= 4.14`

## Usage

Run: `lenopow [operation]`

| Operation | Description |
| :---------------- | :----------------------------------------------- |
| `-h`, `--help` | Show help message. |
| `-v`, `--version` | Show script version. |
| `-s`, `--status` | Show battery protection status. |
| `-e`, `--enable` | Enable battery protection (charge level 55-60%). |
| `-d`, `--disable` | Disable battery protection (charge level 100%). |

## License

This simple wrapper script, with a definitely too big name, is licensed under the Unlicense - see the [LICENSE](LICENSE) file for details.
103 changes: 103 additions & 0 deletions lenopow
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash

# Maintainer: Mehmet Akif Duba <mail[at]makifdb[dot]com>

# Based on the code from:
# Lenovsky <lenovsky@pm.me>

readonly VERSION=1.0.4
readonly BATTERY_PROTECTION='/sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode'
readonly BATTERY_PROTECTION_ON=1
readonly BATTERY_PROTECTION_OFF=0

usage() {
# Prints general usage of the script.

cat <<EOF
usage: ${0##*/} [operation]
operations:
-h, --help Show this message.
-v, --version Show script version.
-s, --status Show battery protection status.
-e, --enable Enable battery protection (charge level 55-60%).
-d, --disable Disable battery protection (charge level 100%).
EOF
}

die() {
# Raises an error message and exits.
# param: $1: $error_message: error message

local exit_code=1
local error_message="$1"

echo "${0##*/}: ${error_message}" 1>&2

exit "${exit_code}"
}

battery_protection_show() {
# Shows battery protection status based on $BATTERY_PROTECTION value.

local status="$(cat "${BATTERY_PROTECTION}")"

if [[ "${status}" -eq "${BATTERY_PROTECTION_ON}" ]]; then
echo "Battery protection: ENABLED"
elif [[ "${status}" -eq "${BATTERY_PROTECTION_OFF}" ]]; then
echo "Battery protection: DISABLED"
else
echo "Battery protection: UNKNOWN"
fi
}

battery_protection_store() {
# Stores value in $BATTERY_PROTECTION
# param: $1: $store: values for $BATTERY_PROTECTION, where:
# * 1 -> enabled
# * 0 -> disabled

local store="$1"

if [[ "${store}" -eq "${BATTERY_PROTECTION_ON}" ]]; then
echo 'Battery protection enabled (charge level 55-60%)'
sudo bash -c "echo '${store}' >'${BATTERY_PROTECTION}'"
elif [[ "${store}" -eq "${BATTERY_PROTECTION_OFF}" ]]; then
echo 'Battery protection disabled (charge level 100%)'
sudo bash -c "echo '${store}' >'${BATTERY_PROTECTION}'"
else
die "Invalid value encountered in 'battery_protection_store()'"
fi
}

main() {
# Parses command-line arguments in order to perform the stuff.
# param: $1: $key: key to the stuff

local key="$1"

case "${key}" in
-h | --help)
usage
;;
-v | --version)
echo "${0##*/} v${VERSION}"
;;
-s | --status)
battery_protection_show
;;
-e | --enable)
battery_protection_store "${BATTERY_PROTECTION_ON}"
;;
-d | --disable)
battery_protection_store "${BATTERY_PROTECTION_OFF}"
;;
"")
die "No operation specified. See '${0##*/} --help'."
;;
*)
die "Invaild operation '${key}'. See '${0##*/} --help'."
;;
esac
}

main "$@"
9 changes: 9 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NAME := lenopow
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin

install:
install -D -m755 $(NAME) '$(DESTDIR)$(BINDIR)/$(NAME)'

uninstall:
rm '$(DESTDIR)$(BINDIR)/$(NAME)'

0 comments on commit 71d3f53

Please sign in to comment.