mirror of
https://github.com/armbian/configng.git
synced 2026-01-06 10:37:41 -08:00
Initial refactoring
This commit is contained in:
165
README.md
Normal file → Executable file
165
README.md
Normal file → Executable file
@@ -1,114 +1,77 @@
|
||||
# configng
|
||||
This is a refactoring of [armbian-config](https://github.com/armbian/config) using [Bash Utility](https://labbots.github.io/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
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/armbian/build/main/.github/armbian-logo.png" alt="Armbian logo" width="144">
|
||||
<br>
|
||||
Armbian ConfigNG
|
||||
<br>
|
||||
<a href="https://www.codefactor.io/repository/github/tearran/configng"><img src="https://www.codefactor.io/repository/github/tearran/configng/badge" alt="CodeFactor" /></a>
|
||||
</p>
|
||||
|
||||
# User guide
|
||||
## 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 ]
|
||||
Run the following commands:
|
||||
|
||||
Options:
|
||||
-h) Print this help.
|
||||
sudo apt install git
|
||||
cd ~/
|
||||
git clone https://github.com/armbian/configng.git
|
||||
cd configng
|
||||
./bin/armbian-configng --dev
|
||||
|
||||
foo) Usage: config foo [ desk_setup::options ][ io::options ][ boardled::options ][ cpu::options ][ extra_drive::options ][ benchymark::options ]::
|
||||
If all goes well you should see the Text-Based User Inerface (TUI)
|
||||
|
||||
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](https://google.github.io/styleguide/shellguide.html) 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.
|
||||
### To see a list of all functions and their descriptions, run the following command:
|
||||
~~~
|
||||
bash ~/configng/bin/armbian-configng -h
|
||||
~~~
|
||||
## Coding Style
|
||||
follow the following coding style:
|
||||
~~~
|
||||
# @description A short description of the function.
|
||||
#
|
||||
# @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}"
|
||||
# @options A description if there are options.
|
||||
function group::string() {s
|
||||
echo "hello world"
|
||||
return 0
|
||||
}
|
||||
```
|
||||
~~~
|
||||
## Codestyle can be used to auto generate
|
||||
- [Markdown](share/armbian-configng/readme.md)
|
||||
- [JSON](share/armbian-configng/data/armbian-configng.json)
|
||||
- [CSV](share/armbian-configng/data/armbian-configng.csv)
|
||||
- [HTML](share/armbian-configng/armbian-configng-table.html)
|
||||
- [github.io](//tearran/github.io/armbian-configng/index.html)
|
||||
## Functions list as of 2023-12-05
|
||||
## network
|
||||
System and Security
|
||||
|
||||
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
|
||||
### set_wifi.sh
|
||||
|
||||
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
|
||||
```
|
||||
- **Group Name:** network
|
||||
- **Action Name:** NMTUI
|
||||
- **Options:** none.
|
||||
- **Description:** Network Manager.
|
||||
|
||||
Return values should use stdout:
|
||||
```
|
||||
# Return value
|
||||
printf '%s\n' "$(cat $file)"
|
||||
```
|
||||
## system
|
||||
Network Wired wireless Bluetooth access point
|
||||
|
||||
### hello_world.sh
|
||||
|
||||
- **Group Name:** system
|
||||
- **Action Name:** Hello
|
||||
- **Options:** none
|
||||
- **Description:** Hello System.
|
||||
|
||||
### see_monitor.sh
|
||||
|
||||
- **Group Name:** monitor
|
||||
- **Action Name:** Bencharking
|
||||
- **Options:**
|
||||
- **Description:** Armbian Monitor and Bencharking.
|
||||
|
||||
|
||||
# Inclueded projects
|
||||
- [Bash Utility](https://labbots.github.io/bash-utility)
|
||||
- [Armbian config](https://github.com/armbian/config.git)
|
||||
|
||||
Only use sudo when needed and never run as root!
|
||||
|
||||
222
bin/armbian-configng
Executable file
222
bin/armbian-configng
Executable file
@@ -0,0 +1,222 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script provides a command-line interface for managing Armbian configuration.
|
||||
# It loads libraries of functions from the lib directory and displays them in a menu.
|
||||
# The user can select a function to run, or use a text-based user interface (TUI) to navigate the menus.
|
||||
# The script also provides a help option and a debug option for developers.
|
||||
# The script requires sudo privileges to run some functions.
|
||||
# The script uses whiptail or dialog for the TUI, depending on which is available.
|
||||
|
||||
#set -x
|
||||
#set -e
|
||||
|
||||
#
|
||||
# Enable Dynamic directory root use home ~/ , /bin , /usr/sbin etc..
|
||||
bin="$(dirname "${BASH_SOURCE[0]}")"
|
||||
directory="$(cd "$bin/../" && pwd )"
|
||||
file_name="$(basename "${BASH_SOURCE[0]}")"
|
||||
filename="${file_name%.*}"
|
||||
libpath=$(cd "$directory/lib/$filename/" && pwd)
|
||||
#sharepath=$(cd "$directory/share/${filename%-dev}/" && pwd)
|
||||
|
||||
|
||||
#
|
||||
# Consept Distribution Compatibility checks
|
||||
check_distro() {
|
||||
|
||||
[[ -f "/usr/bin/${filename%%-*}-config" ]] && distro_config="${filename%%-*}"
|
||||
[[ -f "/etc/${filename%%-*}-release" ]] && distro_release="${filename%%-*}"
|
||||
# if both true then we are good to go
|
||||
[[ -z "$distro_config" ]] || [[ -z "$distro_release" ]] && echo "W: Costum build, Tech support links are missing."
|
||||
[[ -n "$distro_config" ]] && [[ -n "$distro_release" ]] && echo "I: This build seems to be community supported" | ./armbian-interface -o
|
||||
[[ -f "/usr/sbin/${filename%%-*}-config" ]] && distro_config="${filename%%-*}"
|
||||
[[ -f "/etc/${filename%%-*}-release" ]] && distro_release="${filename%%-*}"
|
||||
|
||||
}
|
||||
|
||||
[[ "$1" == "--dev" ]] && dev=1 && shift 1
|
||||
|
||||
#
|
||||
# Check if the script is dev version.
|
||||
suffix="${file_name##*-}"
|
||||
|
||||
if [[ "$suffix" == dev ]]; then
|
||||
dev=1
|
||||
check_distro #| armbian-interface -o
|
||||
fi
|
||||
|
||||
if [[ "$(id -u)" != "0" ]] && [[ "$dev" == "1" ]] ; then
|
||||
|
||||
cat << EOF #| ./armbian-interface -o
|
||||
I: Running in UX development mode
|
||||
W: Admin functions will not work as expected
|
||||
|
||||
EOF
|
||||
elif [[ "$(id -u)" == "0" ]] && [[ "$dev" == "1" ]] ; then
|
||||
cat << EOF | ./armbian-interface -o
|
||||
I: Running in UX development mode
|
||||
W: Document files may need Admin privleges to edit/remove
|
||||
|
||||
EOF
|
||||
|
||||
fi
|
||||
|
||||
#
|
||||
# Check if the script is being run as root
|
||||
# UX Development mode bypasses root check, many functions will not work as expected
|
||||
|
||||
if [[ "$(id -u)" != "0" ]] && [[ "$dev" != "1" ]]; then
|
||||
echo -e "E: This tool requires root privileges. Try: \"sudo $filename\"" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare -A dialogue
|
||||
|
||||
#
|
||||
# Check if whiptail or dialog is installed and set the variable 'dialogue' accordingly.
|
||||
# todo add a fallback TUI and GUI
|
||||
if command -v whiptail &> /dev/null; then
|
||||
dialogue="whiptail"
|
||||
elif command -v dialog &> /dev/null; then
|
||||
dialogue="dialog"
|
||||
else
|
||||
echo "TUI not found"
|
||||
echo "Warning: Using fallback TUI"
|
||||
sleep 1
|
||||
clear && generate_read
|
||||
fi
|
||||
|
||||
source "$libpath/functions.sh"
|
||||
source "$libpath/documents.sh"
|
||||
for file in "$libpath"/*/*.sh; do
|
||||
source "$file"
|
||||
done
|
||||
|
||||
#
|
||||
# mapfile -t categories < <(ls -d "$libpath"/* )
|
||||
mapfile -t categories < <(find "$libpath"/* -type d)
|
||||
declare -A functions
|
||||
|
||||
for category in "${categories[@]}"; do
|
||||
category_name="${category##*/}"
|
||||
|
||||
category_file="$category/readme.md"
|
||||
if [[ -f "$category_file" ]]; then
|
||||
category_description=$(grep -oP "(?<=# @description ).*" "$category_file")
|
||||
fi
|
||||
|
||||
for file in "$category"/*.sh; do
|
||||
description=""
|
||||
while IFS= read -r line; do
|
||||
if [[ $line =~ ^#\ @description\ (.*)$ ]]; then
|
||||
description="${BASH_REMATCH[1]}"
|
||||
elif [[ $line =~ ^function\ (.*::.*)\(\)\{$ ]]; then
|
||||
# END: be15d9bcejpp
|
||||
function_name="${BASH_REMATCH[1]}"
|
||||
key="$category_name:${file##*/}:${function_name}"
|
||||
functions["$key,function_name"]=$(echo "$function_name" | sed 's/.*:://')
|
||||
functions["$key,group_name"]=$(echo "$function_name" | sed 's/::.*//')
|
||||
functions["$key,description"]=$description
|
||||
elif [[ $line =~ ^#\ @options\ (.*)$ ]]; then
|
||||
functions["$key,options"]="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
done < "$file"
|
||||
functions["$key,category"]=$category_name
|
||||
functions["$key,category_description"]=$category_description
|
||||
done
|
||||
done
|
||||
|
||||
|
||||
#
|
||||
# WIP: Check arguments for no flag options
|
||||
# armbian-config --help
|
||||
# Change to BASH: /usr/sbin/armbian-config main=System selection=BASH
|
||||
handle_no_flag(){
|
||||
if [[ "$1" == *"="* ]]; then
|
||||
IFS='=' read -r key value <<< "$1"
|
||||
function_name=$(parse_action "$key" "$value")
|
||||
# Call the function using variable indirection
|
||||
${function_name}
|
||||
elif [[ "$1" == "help"* ]]; then
|
||||
generate_list_cli
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Check arguments for long flag options
|
||||
# Help message related to the functions the back end
|
||||
handle_long_flag(){
|
||||
if [[ "$1" == "--help" ]]; then
|
||||
generate_list_run
|
||||
exit 0 ;
|
||||
elif [[ "$1" == "--doc" ]]; then
|
||||
generate_doc
|
||||
exit 0 ;
|
||||
fi
|
||||
# WIP:
|
||||
if [ "$1" == "--run" ]; then
|
||||
shift # Shifts the arguments to the left, excluding the first argument ("-r")
|
||||
group_name="$1" # Takes the first argument as the group name
|
||||
shift 1 # Shifts the arguments again to exclude the group name
|
||||
|
||||
function_name=$(parse_action "$group_name" "$1")
|
||||
if [ $? -eq 0 ]; then
|
||||
# Call the function using variable indirection
|
||||
${function_name}
|
||||
fi
|
||||
elif [ "$1" == "--help" ]; then
|
||||
generate_list_run
|
||||
exit
|
||||
elif [ "$1" == "--test" ]; then
|
||||
check_distro | armbian-interface -o && $1 > /dev/null
|
||||
fi
|
||||
|
||||
}
|
||||
#
|
||||
# Check arguments for short flag options
|
||||
# THe interface help message
|
||||
handle_short_flag(){
|
||||
if [ "$1" == "-h" ]; then
|
||||
generate_help
|
||||
exit 0 ;
|
||||
# Generate a text-based user interface
|
||||
elif [ "$1" == "-t" ] ; then
|
||||
generate_read ; exit 0 ;
|
||||
# Generate all doc files
|
||||
elif [ "$1" == "-d" ] ; then
|
||||
generate_doc ; exit 0 ;
|
||||
elif [ "$1" == "-j" ] ; then
|
||||
generate_json ; exit 0 ;
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
*"="*)
|
||||
# Handle the case where $1 contains "="
|
||||
handle_no_flag "$@"
|
||||
;;
|
||||
*"--"*)
|
||||
# Handle the case where $1 starts with "--"
|
||||
handle_long_flag "$@"
|
||||
;;
|
||||
*"-"*)
|
||||
# Handle the case where $1 starts with "-"
|
||||
handle_short_flag "$1"
|
||||
;;
|
||||
*)
|
||||
handle_no_flag "$@"
|
||||
# Handle the case where $1 does not match any of the above patterns
|
||||
# You can add your code here
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -z "$1" ]] ; then
|
||||
while true; do
|
||||
generate_tui ;
|
||||
if [[ "$?" == "0" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
fi
|
||||
119
bin/armbian-interface
Executable file
119
bin/armbian-interface
Executable file
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Copyright (c) 2023 Joseph C Turner
|
||||
# All rights reserved.
|
||||
#
|
||||
# This script.
|
||||
# demonstrates the compatibility of multiple interfaces for displaying menus or messages.
|
||||
# It uses an array to set the options for all three menus (bash, whiptail, and dialog).
|
||||
# The script checks if whiptail or dialog are available on the system and uses them to display the menu in a more user-friendly way.
|
||||
# If neither of these programs is available, it falls back to using bash.
|
||||
# while both are installed falls back to whiptail to display the menu.
|
||||
# The user can override the default program by passing an argument when running the script:
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
## DIRECTORY variable to the absolute path of the script's directory
|
||||
directory="$(dirname "$(readlink -f "$0")")"
|
||||
filename=$(basename "${BASH_SOURCE[0]}")
|
||||
|
||||
## DIALOG variable to the absolute path of the script's directory
|
||||
DIALOG="bash"
|
||||
[[ -x "$(command -v dialog)" ]] && DIALOG="dialog"
|
||||
[[ -x "$(command -v whiptail)" ]] && DIALOG="whiptail"
|
||||
|
||||
show_help(){
|
||||
|
||||
echo -e "\nUsage: [command] | ${filename%.*} [ -h | -m | -o ]"
|
||||
echo "Options:"
|
||||
echo " -h, Print this help."
|
||||
echo ""
|
||||
echo " -o, Opens an OK message Box"
|
||||
echo ""
|
||||
echo " -m, Opens an Menu select Box."
|
||||
echo ""
|
||||
echo " -p, Opens Popup message box. "
|
||||
echo ""
|
||||
exit 1;
|
||||
}
|
||||
|
||||
show_message(){
|
||||
|
||||
# Read the input from the pipe continuously until there is no more input
|
||||
input=""
|
||||
while read -r line; do
|
||||
input+="$line\n"
|
||||
done
|
||||
|
||||
# Display the "OK" message box with the input data
|
||||
[[ $DIALOG != "bash" ]] && $DIALOG --title "Message Box" --msgbox "$input" 0 0
|
||||
[[ $DIALOG == "bash" ]] && echo -e "$input"
|
||||
[[ $DIALOG == "bash" ]] && read -p "Press [Enter] to continue..." ; echo "" ; exit 1
|
||||
|
||||
}
|
||||
|
||||
show_popup(){
|
||||
|
||||
|
||||
input=""
|
||||
while read -r line; do
|
||||
input+="$line\n"
|
||||
done
|
||||
|
||||
[[ $DIALOG != "bash" ]] && $DIALOG --title "Popup Box" --infobox "$input" 0 0
|
||||
[[ $DIALOG == "bash" ]] && echo -e "$input"
|
||||
|
||||
}
|
||||
|
||||
show_menu(){
|
||||
|
||||
|
||||
# Get the input and convert it into an array of options
|
||||
inpu_raw=$(cat)
|
||||
# Remove the lines befor -h
|
||||
input=$(echo "$inpu_raw" | sed 's/-\([a-zA-Z]\)/\1/' | grep '^ [a-zA-Z] ' | grep -v '\[')
|
||||
options=()
|
||||
while read -r line; do
|
||||
package=$(echo "$line" | awk '{print $1}')
|
||||
description=$(echo "$line" | awk '{$1=""; print $0}' | sed 's/^ *//')
|
||||
options+=("$package" "$description")
|
||||
done <<< "$input"
|
||||
|
||||
# Display the menu and get the user's choice
|
||||
[[ $DIALOG != "bash" ]] && choice=$($DIALOG --title "Menu" --menu "Choose an option:" 0 0 9 "${options[@]}" 3>&1 1>&2 2>&3)
|
||||
|
||||
# Check if the user made a choice
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "$choice"
|
||||
else
|
||||
echo "You cancelled."
|
||||
fi
|
||||
}
|
||||
|
||||
[[ $1 == "-m" ]] && show_menu ;
|
||||
[[ $1 == "-o" ]] && show_message ;
|
||||
[[ $1 == "-h" ]] && show_help ;
|
||||
[[ $1 == "-p" ]] && show_popup ;
|
||||
[[ -z "$@" ]] && show_help ;
|
||||
130
bin/config.sh
130
bin/config.sh
@@ -1,130 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com
|
||||
#
|
||||
# This file is licensed under the terms of the GNU General Public
|
||||
# License version 2. This program is licensed "as is" without any
|
||||
# warranty of any kind, whether express or implied.
|
||||
#
|
||||
#
|
||||
|
||||
directory="$(dirname "$(readlink -f "$0")")"
|
||||
filename=$(basename "${BASH_SOURCE[0]}")
|
||||
|
||||
libpath="$directory/../lib"
|
||||
|
||||
if [[ -d "$directory/../lib" ]]; then
|
||||
libpath="$directory"/../lib
|
||||
# installed option todo change when lib location determined
|
||||
#elif [[ ! -d "$directory/../lib" && -d "/usr/lib/bash-utility/" && -d "/usr/lib/config/" ]]; then
|
||||
# libpath="/usr/lib"
|
||||
else
|
||||
echo "Libraries not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Source the files relative to the script location
|
||||
for file in "$libpath"/bash-utility/*; do
|
||||
source "$file"
|
||||
done
|
||||
for file in "$libpath"/config/*; do
|
||||
source "$file"
|
||||
done
|
||||
|
||||
functionarray=()
|
||||
funnamearray=()
|
||||
catagoryarray=()
|
||||
descriptionarray=()
|
||||
|
||||
for file in "$libpath"/config/*.sh; do
|
||||
mapfile -t temp_functionarray < <(grep -oP '^\w+::\w+' "$file")
|
||||
functionarray+=("${temp_functionarray[@]}")
|
||||
|
||||
mapfile -t temp_funnamearray < <(grep -oP '^\w+::\w+' "$file" | sed 's/.*:://')
|
||||
funnamearray+=("${temp_funnamearray[@]}")
|
||||
|
||||
mapfile -t temp_catagoryarray < <(grep -oP '^\w+::\w+' "$file" | sed 's/::.*//')
|
||||
catagoryarray+=("${temp_catagoryarray[@]}")
|
||||
|
||||
mapfile -t temp_descriptionarray < <(grep -oP '^# @description.*' "$file" | sed 's/^# @description //')
|
||||
descriptionarray+=("${temp_descriptionarray[@]}")
|
||||
done
|
||||
|
||||
see_help_dev(){
|
||||
# Extract unique prefixes
|
||||
declare -A prefixes
|
||||
for i in "${!functionarray[@]}"; do
|
||||
prefix="${functionarray[i]%%::*}"
|
||||
prefixes["$prefix"]=1
|
||||
done
|
||||
|
||||
# Construct usage line
|
||||
usage=""
|
||||
for prefix in "${!prefixes[@]}"; do
|
||||
usage+="[ $prefix::options ]"
|
||||
done
|
||||
|
||||
|
||||
# echo "$usage"
|
||||
echo "Usage: ${filename%.*} [ -h | foo ]"
|
||||
echo ""
|
||||
echo -e "Options:"
|
||||
echo -e " -h) Print this help."
|
||||
echo -e ""
|
||||
echo -e " foo) Usage: ${filename%.*} foo $usage "
|
||||
echo ""
|
||||
|
||||
# Group options by prefix
|
||||
declare -A groups
|
||||
for i in "${!functionarray[@]}"; do
|
||||
prefix="${functionarray[i]%%::*}"
|
||||
suffix="${functionarray[i]#*::}"
|
||||
groups["$prefix"]+=$'\t\t'"$suffix\t${descriptionarray[i]}"$'\n'
|
||||
done
|
||||
|
||||
# Print grouped options
|
||||
for group in "${!groups[@]}"; do
|
||||
echo -e " $group::options"
|
||||
echo -e "${groups[$group]}"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# TEST 7
|
||||
# check for -h -dev @ $1
|
||||
# if -dev check @ $1 remove and shift $1 to check for x
|
||||
check_opts() {
|
||||
if [ "$1" == "foo" ]; then
|
||||
shift # Shifts the arguments to the left, excluding the first argument ("-dev")
|
||||
function_name="$1" # Assigns the next argument as the function name
|
||||
shift # Shifts the arguments again to exclude the function name
|
||||
|
||||
found=false
|
||||
|
||||
for ((i=0; i<${#functionarray[@]}; i++)); do
|
||||
if [ "$function_name" == "${functionarray[i]}" ]; then
|
||||
found=true
|
||||
${functionarray[i]} "$@"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$found" == false ]; then
|
||||
echo "Invalid function name"
|
||||
see_help_dev
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
elif [[ "$1" == "foo" && "$2" == "cpu::set_freq" ]]; then
|
||||
# Disabled till understood.
|
||||
echo "cpu::set_freq policy min_freq max_freq performance"
|
||||
echo "Disabled durring current testing"
|
||||
|
||||
else
|
||||
see_help_dev
|
||||
fi
|
||||
}
|
||||
|
||||
check_opts "$@"
|
||||
224
bin/jampi-config
224
bin/jampi-config
@@ -1,224 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Copyright (c) 2023 Joseph C Turner
|
||||
# All rights reserved.
|
||||
#
|
||||
# This script.
|
||||
# demonstrates the compatibility of multiple interfaces for displaying menus or messages.
|
||||
# It uses an array to set the options for all three menus (bash, whiptail, and dialog).
|
||||
# The script checks if whiptail or dialog are available on the system and uses them to display the menu in a more user-friendly way.
|
||||
# If neither of these programs is available, it falls back to using bash.
|
||||
# while both are installed falls back to whiptail to display the menu.
|
||||
# The user can override the default program by passing an argument when running the script:
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
# Comeback to this later
|
||||
#
|
||||
##DIRECTORY variable to the absolute path of the script's directory
|
||||
##directory=$(cd "$(dirname "$0")" && pwd)
|
||||
#directory="$(dirname "$(readlink -f "$0")")"
|
||||
#filename=$(basename "${BASH_SOURCE[0]}")
|
||||
#selfpath="$directory"/"$filename"
|
||||
##libpath="${directory}"/"its-lib" #Include these scripts Library
|
||||
#libpath="$selfpath"
|
||||
#
|
||||
#
|
||||
#clear
|
||||
## Check for the availability of whiptail and dialog command-line programs
|
||||
## Set the default program to use for displaying messages
|
||||
#( ! command -v whiptail >/dev/null && ! command -v dialog >/dev/null ) && default="bash"
|
||||
#( command -v whiptail >/dev/null && ! command -v dialog >/dev/null ) && default="whiptail"
|
||||
#( ! command -v whiptail >/dev/null && command -v dialog >/dev/null ) && default="dialog"
|
||||
#
|
||||
## if both whiptail and dialog change to prefered
|
||||
#( command -v whiptail >/dev/null && command -v dialog >/dev/null ) && default="whiptail"
|
||||
#
|
||||
#
|
||||
#[[ "$1" == -b ]] && default="bash"
|
||||
#[[ "$1" == -w ]] && default="whiptail"
|
||||
#[[ "$1" == -n ]] && default="dialog"
|
||||
#
|
||||
#[[ "$1" == -m ]] && {
|
||||
#export NEWT_COLORS="
|
||||
#root=blue,black
|
||||
#border=green,black
|
||||
#title=green,black
|
||||
#roottext=red,black
|
||||
#window=red,black
|
||||
#textbox=white,black
|
||||
#button=black,green
|
||||
#compactbutton=white,black
|
||||
#listbox=white,black
|
||||
#actlistbox=black,white
|
||||
#actsellistbox=black,green
|
||||
#checkbox=green,black
|
||||
#actcheckbox=black,green
|
||||
#"
|
||||
#}
|
||||
#
|
||||
## Check the cpu architecture. for later handeling if nessery
|
||||
#architecture=$(dpkg --print-architecture)
|
||||
#[[ "$architecture" == "armf" ]] && true ;
|
||||
#
|
||||
##setup menu arrays
|
||||
#readarray -t functionarray < <( grep -A1 '^##.*@.*:*' "$libpath" | grep -oP '^\w+\(\)' | sed 's/()//' )
|
||||
#readarray -t descriptions < <( grep -e '^##.*@.*' "$libpath" | sed "s|^## *@||g;s| ## *@.*||g;s|.*: *||g" )
|
||||
#readarray -t descriptionarray < <( for i in "${!descriptions[@]}" ; do printf "%s\n %s\n" "$i" "${descriptions[i]}" ; done )
|
||||
#
|
||||
### System@Settings:Advanced Settings (armbian-config)
|
||||
#cmd_advance()
|
||||
#{
|
||||
# sudo armbian-config
|
||||
#}
|
||||
#
|
||||
### System@CPU info:Example from Bash Utility (cpu_test.sh)
|
||||
#cmd_cpu_info()
|
||||
#{
|
||||
# [[ ! -f /usr/sbin/cpu_test_library.sh ]] && cmd_cpu_ls ;
|
||||
# [[ -f /usr/sbin/cpu_test_library.sh ]] && shell_command=$(sudo /usr/sbin/cpu_test_library.sh )
|
||||
# message_box=$( printf '%s ' "${shell_command[@]}" ) ;
|
||||
# see_message
|
||||
#}
|
||||
#
|
||||
#
|
||||
### System@CPU info:An example function (lscpu)
|
||||
#cmd_cpu_ls()
|
||||
#{
|
||||
#
|
||||
# shell_command="$(lscpu)" ;
|
||||
# message_box=$( printf '%s ' "${shell_command[@]}" ) ;
|
||||
# see_message
|
||||
#}
|
||||
#
|
||||
### System@Bootup Time:An example function (systemd-analyze time)
|
||||
#cmd_boot_time()
|
||||
#{
|
||||
#
|
||||
# shell_command="$(systemd-analyze time)" ;
|
||||
# message_box=$( printf '%s ' "${shell_command[@]}" ) ;
|
||||
# see_message
|
||||
#}
|
||||
#
|
||||
### System@Login Info :An example function (Login Info)
|
||||
#cmd_lslogins()
|
||||
#{
|
||||
#
|
||||
# shell_command="$(lslogins)" ;
|
||||
# message_box=$( printf '%s ' "${shell_command[@]}" ) ;
|
||||
# see_message
|
||||
#}
|
||||
#
|
||||
#
|
||||
## Function to display a message using whiptail, dialog or printf depending on what is available on the system
|
||||
#see_message()
|
||||
#{
|
||||
# # Use if neither whiptail nor dialog are available on the system
|
||||
# if [[ "$default" == "bash" ]] || ( ! command -v whiptail >/dev/null && ! command -v dialog >/dev/null ); then
|
||||
# # Use printf to display the message
|
||||
# printf '%s ' "${shell_command[@]}"
|
||||
#
|
||||
# # Use as default if whiptail is available
|
||||
# elif [[ "$default" == "whiptail" ]] && ( command -v whiptail >/dev/null ); then
|
||||
# # Use whiptail to display the message
|
||||
# whiptail --backtitle "newt whitail: $architecture" --title "description" --msgbox "${message_box[@]}" 0 0 --clear --scrolltext
|
||||
#
|
||||
# # Use if dialog is available on the system but not whiptail
|
||||
# elif [[ "$default" == "dialog" ]] && ( command -v dialog >/dev/null ); then
|
||||
# # Use dialog to display the message
|
||||
# dialog --backtitle "ncurses dialog: $architecture" --title "description" --msgbox "${message_box[@]}" 0 0 ; clear
|
||||
# fi
|
||||
#}
|
||||
#
|
||||
#see_menu()
|
||||
#{
|
||||
#
|
||||
# if [[ "$default" == "bash" ]]; then
|
||||
# PS3="Enter a number: "
|
||||
# select i in "${descriptions[@]}" ; do ${functionarray[$REPLY - 1]} ; break ; done
|
||||
#
|
||||
# elif [[ "$default" == "whiptail" ]]; then
|
||||
# OPTION=$(whiptail --backtitle "newt whiptail: $architecture" --title "Config" --menu "Choose your option" 20 80 7 "${descriptionarray[@]}" 3>&1 1>&2 2>&3)
|
||||
# [[ -n $OPTION ]] && clear && "${functionarray[$OPTION]}"
|
||||
#
|
||||
# elif [[ "$default" == "dialog" ]]; then
|
||||
# OPTION=$(dialog --backtitle "ncurses dialog: $architecture" --title "Config" --menu "Choose your option" 20 80 7 "${descriptionarray[@]}" 3>&1 1>&2 2>&3)
|
||||
# [[ -n $OPTION ]] && clear && "${functionarray[$OPTION]}"
|
||||
# fi
|
||||
#}
|
||||
#
|
||||
#see_help(){
|
||||
#
|
||||
# echo ""
|
||||
# echo "Usage: ${filename%.*} [ -h | -b | -n | -w | -d | -dev ]"
|
||||
# echo -e "Options:"
|
||||
# echo -e " -h Print this help."
|
||||
# echo -e " -b GNU bash "
|
||||
# echo -e " -n NCURSES dialog "
|
||||
# echo -e " -w NEWT whiptail - default colors "
|
||||
# echo -e " -m dark mode whiptail "
|
||||
# echo -e " -dev Options:"
|
||||
# for i in "${!functionarray[@]}"; do
|
||||
# printf '\t\t%s\t%s \n' "${functionarray[i]}" "${descriptions[i]}"
|
||||
# done
|
||||
#
|
||||
# }
|
||||
#
|
||||
#main()
|
||||
#{
|
||||
# if [[ "$1" == --dev ]] ; then
|
||||
# default="bash"
|
||||
# local found=false
|
||||
# for i in "${!functionarray[@]}"; do
|
||||
# if [ "$2" == "${functionarray[i]}" ]; then
|
||||
# "${functionarray[i]}"
|
||||
# found=true
|
||||
# break
|
||||
# fi
|
||||
# done
|
||||
# if ! $found; then
|
||||
# see_help
|
||||
# exit 0
|
||||
# fi
|
||||
# elif [[ "$1" == -h ]] ; then
|
||||
# see_help
|
||||
# else
|
||||
# see_menu
|
||||
# fi
|
||||
#}
|
||||
#
|
||||
#main "$@"
|
||||
|
||||
if command -v whiptail > /dev/null; then
|
||||
DIALOG=whiptail
|
||||
elif command -v dialog > /dev/null; then
|
||||
DIALOG=dialog
|
||||
else
|
||||
echo "Error: Neither whiptail nor dialog is installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
input=$(cat)
|
||||
$DIALOG --title "Config Options" --msgbox "$input" 0 0
|
||||
388
lib/armbian-configng/documents.sh
Normal file
388
lib/armbian-configng/documents.sh
Normal file
File diff suppressed because one or more lines are too long
145
lib/armbian-configng/functions.sh
Normal file
145
lib/armbian-configng/functions.sh
Normal file
@@ -0,0 +1,145 @@
|
||||
|
||||
|
||||
# This function is used to generate a text-based user interface (TUI) for navigating the menus.
|
||||
generate_tui() {
|
||||
local options=()
|
||||
local i=0
|
||||
declare -A categories_array
|
||||
for category in "${categories[@]}"; do
|
||||
local category_name="${category##*/}"
|
||||
local category_description=""
|
||||
local category_file="$category/readme.md"
|
||||
|
||||
if [[ -f "$category_file" ]]; then
|
||||
category_description=$(grep -oP "(?<=# @description ).*" "$category_file")
|
||||
fi
|
||||
|
||||
categories_array["$i"]="$category_name"
|
||||
description_array["$i"]="$category_description"
|
||||
options+=("$i" "$(printf '%-7s - %-8s' "${categories_array[$i]}" "${description_array[$i]}")")
|
||||
#options+=("$i" "${categories_array[$i]} - ${description_array[$i]}")
|
||||
((++i))
|
||||
done
|
||||
options+=("$i" "$(printf '%-7s - %-8s' "Legacy" "Run Legacy configuration")")
|
||||
|
||||
#options+=("$i" "Legacy - Run Legacy configuration")
|
||||
((++i))
|
||||
options+=("$i" "$(printf '%-7s - %-8s' "Help" "Documentation, support, sources")")
|
||||
#options+=("$i" "Help - Documentation, support, sources" )
|
||||
((++i))
|
||||
|
||||
local choice
|
||||
|
||||
choice=$($dialogue --menu "Select a category:" 0 0 9 "${options[@]}" 3>&1 1>&2 2>&3)
|
||||
|
||||
if [[ -n $choice ]]; then
|
||||
|
||||
if ((choice == "$i - 1")); then
|
||||
generate_help | armbian-interface -o
|
||||
exit ;
|
||||
elif ((choice == "$i - 2")); then
|
||||
armbian-config
|
||||
exit ;
|
||||
else
|
||||
generate_sub_tui "${categories_array[$choice]}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# This function is used to generate a text-based user interface (TUI) for navigating the menus.
|
||||
generate_sub_tui() {
|
||||
local category="$1"
|
||||
local options=()
|
||||
local i=0
|
||||
declare -A functions_array
|
||||
for file in "$libpath/$category"/*.sh; do
|
||||
mapfile -t functions_in_file < <(grep -oP '(?<=function\s)\w+::\w+' "$file")
|
||||
for function in "${functions_in_file[@]}"; do
|
||||
key="${category##*/}:${file##*/}:${function}"
|
||||
functions_array["$i"]="$function"
|
||||
options+=("$i" "${functions["$key,function_name"]} - ${functions["$key,description"]}")
|
||||
((++i))
|
||||
done
|
||||
done
|
||||
|
||||
local choice
|
||||
|
||||
choice=$($dialogue --menu "Select a function:" 0 0 9 "${options[@]}" 3>&1 1>&2 2>&3)
|
||||
|
||||
if [[ -n $choice ]]; then
|
||||
generate_action "${functions_array[$choice]}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# This function is used to generate a whiptail/dialog text-based user interface (TUI) for navigating the menus.
|
||||
generate_action() {
|
||||
local function_name="$1"
|
||||
${function_name}
|
||||
}
|
||||
|
||||
# This function is used to generate a bash text-based user interface (TUI) for navigating the menus.
|
||||
generate_read() {
|
||||
echo
|
||||
echo "Please select an action:"
|
||||
echo
|
||||
# Initialize an empty array to store the function keys
|
||||
declare -a function_keys
|
||||
|
||||
# Loop through each key in the functions array
|
||||
local i=1
|
||||
local current_category=""
|
||||
for key in "${!functions[@]}"; do
|
||||
if [[ $key == *",function_name" ]]; then
|
||||
# Add the key to the function_keys array
|
||||
function_keys[i]="${key%,function_name}"
|
||||
|
||||
# Check if the category has changed and display it if so
|
||||
local category="${functions["${function_keys[i]},category"]}" # < editor"
|
||||
if [[ "$category" != "$current_category" ]]; then
|
||||
echo "Category: $category"
|
||||
current_category="$category"
|
||||
fi
|
||||
|
||||
# Display the function and its description as an option in the menu
|
||||
echo " $i. ${functions["${function_keys[i]},group_name"]} ${functions[$key]} - ${functions["${function_keys[i]},description"]}" #" < for my editor
|
||||
((i++))
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "$i. Show help"
|
||||
((i++))
|
||||
echo "$i. Exit"
|
||||
|
||||
read -p "Enter your choice: " choice
|
||||
|
||||
if ((choice == i-1)); then
|
||||
generate_help
|
||||
elif ((choice == i)); then
|
||||
exit 0
|
||||
elif ((choice >= 1 && choice <= ${#function_keys[@]})); then
|
||||
# Call the selected function using variable indirection
|
||||
eval "${functions["${function_keys[choice]},group_name"]}::${functions["${function_keys[choice]},function_name"]}" #" < for my editor
|
||||
else
|
||||
echo "Invalid choice"
|
||||
fi
|
||||
}
|
||||
|
||||
# This function is used to parse the action name and return the full function name.
|
||||
parse_action() {
|
||||
local group=$1
|
||||
local action=$2
|
||||
|
||||
# Construct the full function name
|
||||
local function_name="${group}::${action}"
|
||||
|
||||
# Check if the function exists
|
||||
if declare -f "$function_name" > /dev/null; then
|
||||
# Return the function name
|
||||
echo "$function_name"
|
||||
else
|
||||
echo "Error: Unknown action '$action' for group '$group'"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
3
lib/armbian-configng/network/readme.md
Normal file
3
lib/armbian-configng/network/readme.md
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
# @description Network Wired wireless Bluetooth access point
|
||||
|
||||
19
lib/armbian-configng/network/set_wifi.sh
Normal file
19
lib/armbian-configng/network/set_wifi.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com
|
||||
#
|
||||
# This file is licensed under the terms of the GNU General Public
|
||||
# License version 2. This program is licensed "as is" without any
|
||||
# warranty of any kind, whether express or implied.
|
||||
|
||||
|
||||
|
||||
# @description Network Manager.
|
||||
#
|
||||
# @exitcode 0 If successful.
|
||||
#
|
||||
# @options none
|
||||
function network::NMTUI(){
|
||||
nmtui connect
|
||||
return 0
|
||||
}
|
||||
21
lib/armbian-configng/system/hello_world.sh
Normal file
21
lib/armbian-configng/system/hello_world.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com
|
||||
#
|
||||
# This file is licensed under the terms of the GNU General Public
|
||||
# License version 2. This program is licensed "as is" without any
|
||||
# warranty of any kind, whether express or implied.
|
||||
|
||||
|
||||
# @description Hello System.
|
||||
#
|
||||
# @exitcode 0 If successful.
|
||||
#
|
||||
# @options none.
|
||||
#
|
||||
function system::Hello(){
|
||||
|
||||
echo "Hello Armbian"
|
||||
return 0
|
||||
}
|
||||
|
||||
2
lib/armbian-configng/system/readme.md
Normal file
2
lib/armbian-configng/system/readme.md
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
# @description System and Security
|
||||
45
lib/armbian-configng/system/see_monitor.sh
Normal file
45
lib/armbian-configng/system/see_monitor.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com
|
||||
#
|
||||
# This file is licensed under the terms of the GNU General Public
|
||||
# License version 2. This program is licensed "as is" without any
|
||||
# warranty of any kind, whether express or implied.
|
||||
|
||||
|
||||
# @description Armbian Monitor and Bencharking.
|
||||
#
|
||||
# @exitcode 0 If successful.
|
||||
#
|
||||
# @options none
|
||||
function monitor::Bencharking(){
|
||||
see_menu #| armbian-interface -o
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
see_menu(){
|
||||
# Define the script
|
||||
script="$(which armbianmonitor)"
|
||||
|
||||
# Run the script with the -h option and save the output to a variable
|
||||
help_message=$("$script" -h ) || exit 2
|
||||
|
||||
# Reformat the help message into an array line by line
|
||||
readarray -t script_launcher < <(echo "$help_message" | sed 's/-\([a-zA-Z]\)/\1/' | grep '^ [a-zA-Z] ' | grep -v '\[')
|
||||
|
||||
# Loop through each line in the array and create a menu string
|
||||
menu_string=""
|
||||
for line in "${script_launcher[@]}"; do
|
||||
# Append the formatted line to the menu string
|
||||
if [[ "$line" != " d "* ]] && [[ "$line" != " c "* ]]; then
|
||||
menu_string+="$line\n"
|
||||
fi
|
||||
done
|
||||
|
||||
# Use the get_help_msg function and pipe its output into configng-interface -m
|
||||
selected_option=$(echo -e "$menu_string" | armbian-interface -m)
|
||||
|
||||
# Run the armbian-monitor script with the selected option
|
||||
[[ -n "$selected_option" ]] && "$script" -"$selected_option";
|
||||
}
|
||||
|
||||
22
lib/bash-utility-master/.editorconfig
Normal file
22
lib/bash-utility-master/.editorconfig
Normal file
@@ -0,0 +1,22 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
# for shfmt
|
||||
[*.sh]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
shell_variant = bash
|
||||
switch_case_indent = true
|
||||
space_redirects = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
3
lib/bash-utility-master/.gitignore
vendored
Normal file
3
lib/bash-utility-master/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/tmp
|
||||
gh-pages
|
||||
hugo-docs
|
||||
8
lib/bash-utility-master/.remarkrc
Normal file
8
lib/bash-utility-master/.remarkrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"plugins": [
|
||||
"remark-preset-lint-markdown-style-guide",
|
||||
["remark-lint-list-item-spacing", false],
|
||||
["remark-lint-maximum-line-length", false],
|
||||
["remark-lint-no-duplicate-headings", false]
|
||||
]
|
||||
}
|
||||
76
lib/bash-utility-master/CODE_OF_CONDUCT.md
Normal file
76
lib/bash-utility-master/CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
- Using welcoming and inclusive language
|
||||
- Being respectful of differing viewpoints and experiences
|
||||
- Gracefully accepting constructive criticism
|
||||
- Focusing on what is best for the community
|
||||
- Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
- The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at <admin@labbots.com>. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
<https://www.contributor-covenant.org/faq>
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
129
lib/bash-utility-master/CONTRIBUTING.md
Normal file
129
lib/bash-utility-master/CONTRIBUTING.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# Contributing to Bash-Utility
|
||||
|
||||
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
||||
The following is a set of guidelines for contributing to this project on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
|
||||
|
||||
## Table of Contents
|
||||
- [Code Contributions](#code-contributions)
|
||||
- [Code Guidelines](#code-guidelines)
|
||||
- [Styleguide](#styleguide)
|
||||
- [Bashdoc guideline](#bashdoc-guideline)
|
||||
- [Documentation](#documentation)
|
||||
- [Commit Guidelines](#commit-guidelines)
|
||||
- [Pull Request Guidelines](#pull-request-guidelines)
|
||||
- [Contact](#contact)
|
||||
|
||||
## Code Contributions
|
||||
|
||||
Great, the more, the merrier.
|
||||
|
||||
Sane code contributions are always welcome, whether to the code or documentation.
|
||||
|
||||
Before making a pull request, make sure to follow below guidelines:
|
||||
|
||||
### Code Guidelines
|
||||
|
||||
#### Styleguide
|
||||
|
||||
- Variable names must be meaningful and self-documenting.
|
||||
- Long variable names must be structured by underscores to improve legibility.
|
||||
- Global variables and constants must be ALL CAPS with underscores. (eg., INPUT_FILE)
|
||||
- local variables used within functions must be all lower case with underscores ( only if required ). (eg., input_data)
|
||||
- Variable names can be alphanumeric with underscores. No special characters in variable names.
|
||||
- Variables name must not start with number.
|
||||
- Variables within function must be declared. So the scope of variable is restricted to the function.
|
||||
- Avoid accessing global variables within functions.
|
||||
- Function names must be all lower case with underscores to seperate words (snake_case).
|
||||
- Function name must start with section name followed by 2 colons and then the function name (eg., `array::contains()`)
|
||||
- Try using bash builtins and string substitution as much as possible.
|
||||
- Use printf everywhere instead of echo.
|
||||
- Before adding a new logic, be sure to check the existing code.
|
||||
- Make sure to add the function in appropriate section based on its operation.
|
||||
- Use [shfmt](https://github.com/mvdan/sh) to format the script. Use below command:
|
||||
|
||||
```shell
|
||||
shfmt upload.sh
|
||||
```
|
||||
|
||||
The repo already provides the .editorconfig file, which shfmt reads, so no need for extra flags.
|
||||
You can also install shfmt for various editors, refer their repo for information.
|
||||
Note: This is strictly necessary to maintain consistency, do not skip.
|
||||
|
||||
- Script should pass all [shellcheck](https://www.shellcheck.net/) warnings, if not, then disable the warning and give a valid reason.
|
||||
|
||||
#### Bashdoc guideline
|
||||
|
||||
The documentation is generated based on the function documentation within the script file. So ensure to follow the style so the documentation is
|
||||
properly generated by the generator.
|
||||
|
||||
Follow the below bashdoc template to add function introductory comment.
|
||||
|
||||
```bash
|
||||
# @description Multiline description goes here and
|
||||
# there
|
||||
#
|
||||
# @example
|
||||
# sample::function a b c
|
||||
# echo 123
|
||||
#
|
||||
# @arg $1 string Some arg.
|
||||
# @arg $2 any Rest of arguments.
|
||||
#
|
||||
# @noargs
|
||||
#
|
||||
# @exitcode 0 If successfull.
|
||||
# @exitcode >0 On failure
|
||||
# @exitcode 5 On some error.
|
||||
#
|
||||
# @stdout Path to something.
|
||||
#
|
||||
# @see sample::other_function(()
|
||||
sample::function() {
|
||||
}
|
||||
```
|
||||
|
||||
- Each function must have a description detailing what the function does and a sample usage example to show how the function can be used.
|
||||
- specify whether the function accepts args or no args by specifying @arg or @noargs tag in the comment.
|
||||
- Make sure to document the exitcode emitted by the function.
|
||||
- If the function is similar to other function add a reference to function using @see tag.
|
||||
|
||||
### Documentation
|
||||
|
||||
- Refrain from making unnecessary newlines or whitespace.
|
||||
- Use pure markdown as much as possible, html is accepted but shouldn't be a priority.
|
||||
- The markdown must pass RemarkLint checks.
|
||||
- The function documentation and Table of Content is autogenerated using `generate_readme.sh`. So DO NOT edit them manually. Use the following command to update ToC and Bashdoc.
|
||||
|
||||
```bash
|
||||
./bin/generate_readme.sh -f README.md -s src/
|
||||
```
|
||||
|
||||
### Commit Guidelines
|
||||
|
||||
It is recommended to use small commits over one large commit. Small, focused commits make the review process easier and are more likely to be accepted.
|
||||
|
||||
It is also important to summarise the changes made with brief commit messages. If the commit fixes a specific issue, it is also good to note that in the commit message.
|
||||
|
||||
The commit message should start with a single line that briefly describes the changes. That should be followed by a blank line and then a more detailed explanation.
|
||||
|
||||
Before committing check for unnecessary whitespace with `git diff --check`.
|
||||
|
||||
### Pull Request Guidelines
|
||||
|
||||
The following guidelines will increase the likelihood that your pull request will get accepted:
|
||||
|
||||
- Follow the commit and code guidelines.
|
||||
- Keep the patches on topic and focused.
|
||||
- Try to avoid unnecessary formatting and clean-up where reasonable.
|
||||
|
||||
A pull request should contain the following:
|
||||
|
||||
- At least one commit (all of which should follow the Commit Guidelines).
|
||||
- Title that summarises the issue/feature.
|
||||
- Description that briefly summarises the changes.
|
||||
|
||||
After submitting a pull request, you should get a response within 7 days. If you do not, don't hesitate to ping the thread.
|
||||
|
||||
## Contact
|
||||
|
||||
For further inquiries, you can contact the developer by opening an issue on the repository.
|
||||
21
lib/bash-utility-master/LICENSE
Normal file
21
lib/bash-utility-master/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 labbots
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
3026
lib/bash-utility-master/README.md
Normal file
3026
lib/bash-utility-master/README.md
Normal file
File diff suppressed because it is too large
Load Diff
20
lib/bash-utility-master/bash_utility.sh
Executable file
20
lib/bash-utility-master/bash_utility.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source src/array.sh
|
||||
source src/string.sh
|
||||
source src/variable.sh
|
||||
source src/file.sh
|
||||
source src/misc.sh
|
||||
source src/date.sh
|
||||
source src/interaction.sh
|
||||
source src/check.sh
|
||||
source src/format.sh
|
||||
source src/collection.sh
|
||||
source src/json.sh
|
||||
source src/terminal.sh
|
||||
source src/validation.sh
|
||||
source src/debug.sh
|
||||
source src/os.sh
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user