engineer-80 / configng

Next generation bash based configuration API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

configng

This is a refactoring of armbian-config using Bash Utility embedded in this project. This allows for functional programming in Bash. Error handling and validation are also included. The idea is to provide an API in Bash that can be called from a Command line interface, Text User interface and others. Why Bash? Well, because it's going to be in every distribution. Striped down distributions may not include Python, C/C++, etc. build/runtime environments

Quick start

  • sudo apt install git
  • cd ~/
  • git clone https://github.com/armbian/configng.git
  • bash ~/configng/config.sh

If all goes well you should see list or avalible commands

Usage: config [ -h | foo ]

Options:
 -h)  Print this help.

 foo)  Usage: config foo [ desk_setup::options ][ io::options ][ boardled::options ][ cpu::options ][ extra_drive::options ][ benchymark::options ]::

        desk_setup::options
                see_desktops    Display a list of avalible desktops to install.

        io::options
                set_ir_toggle   [ enable ][ disable ] Infrared Remote Control.

        boardled::options
                see_sysled      See a list of board led options.
                see_sysled_none Set board led options to none (off).
                see_sysled_cpu  Set board led options to monitor CPU.
                see_sysled_beat Set board led options to heartbeat pulse.

        cpu::options
                see_policy      Return policy as int based on original armbian-config logic.
                see_freqs       Return CPU frequencies as string delimited by space.
                see_min_freq    Return CPU minimum frequency as string.
                see_max_freq    Return CPU maximum frequency as string.
                see_governor    Return CPU governor as string.
                see_governors   Return CPU avalible governors as string delimited by space.
                set_freq        ** disabled ** Set min, max and CPU governor.

        extra_drive::options
                set_spi_vflash  Set up a simulated MTD spi flash for testing.
                rem_spi_vflash  Remove tsting simulated MTD spi flash.

        benchymark::options
                see_monitor     system boot-up performance statistics.
                see_boot_times  system boot-up performance statistics.

Change the systems led to pulse a hearbeat

 bash ~/configng/bin/config.sh foo boardled::see_sysled_beat

Change the systems led to off show a result in whiptail or dialog if installed

 bash ~/configng/bin/config.sh foo boardled::see_sysled_none | bash ~/configng/bin/jampi-config.sh

See avalible settings sytem led options and current setting in []

 bash ~/configng/bin/config.sh foo boardled::see_sysled

See avalible armbian monitor options

 bash ~/configng/bin/config.sh foo benchymark:see_monitor

Coding standards

Shell Style Guide has some good ideas, but fundementally look at the code in lib:

# @description Strip characters from the beginning of a string.
#
# @example
#   echo "$(string::lstrip "Hello World!" "He")"
#   #Output
#   llo World!
#
# @arg $1 string The input string.
# @arg $2 string The characters you want to strip.
#
# @exitcode 0  If successful.
# @exitcode 2 Function missing arguments.
#
# @stdout Returns the modified string.
string::lstrip() {
[[ $# -lt 2 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2
printf '%s\n' "${1##$2}"
}

Functions should follow filename::func_name style. Then you can tell just from the name which file the function is located in. Return codes should also follow a similar pattern:

  • 0 Successful
  • 1 Not found
  • 2 Function missing arguments
  • 3-255 all other errors

Validate values:

# Validate minimum frequency is <= maximum frequency
[ "$min_freq" -gt "$max_freq" ] && printf "%s: Minimum frequency must be <= maximum frequency\n" "${FUNCNAME[0]}" && return 5

Return values should use stdout:

# Return value
printf '%s\n' "$(cat $file)"

Only use sudo when needed and never run as root!

About

Next generation bash based configuration API


Languages

Language:Shell 100.0%