Setup for root copy

This commit is contained in:
tearran
2023-07-12 08:36:48 -07:00
committed by Igor
parent cb690fab3a
commit 47a549fa32
74 changed files with 10459 additions and 35 deletions

2
.gitignore vendored
View File

@@ -1,2 +0,0 @@
/.project
/.settings/

90
bin/cli_options.sh Normal file
View File

@@ -0,0 +1,90 @@
#!/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"
selfpath="$libpath/configng/cpu.sh"
if [[ -d "$directory/../lib" ]]; then
libpath="$directory"/../lib
elif [[ -d "/usr/lib/bash-utility/" && -d "/usr/lib/configng/" ]]; then
libpath="/usr/lib"
else
echo "Libraries not found"
exit 0
fi
# Source the files relative to the script location
source "$libpath/bash-utility/string.sh"
source "$libpath/bash-utility/collection.sh"
source "$libpath/bash-utility/array.sh"
source "$libpath/bash-utility/check.sh"
source "$libpath/configng/cpu.sh"
readarray -t functionarray < <(grep -oP '^\w+::\w+' "$selfpath")
readarray -t funnamearray < <(grep -oP '^\w+::\w+' "$selfpath" | sed 's/.*:://')
readarray -t catagoryarray < <(grep -oP '^\w+::\w+' "$selfpath" | sed 's/::.*//')
readarray -t descriptionarray < <(grep -oP '^# @description.*' "$selfpath" | sed 's/^# @description //')
# test array
#printf '%s\n' "${functionarray[@]}"
#exit 0
see_help(){
echo ""
echo "Usage: ${filename%.*} [ -h | -dev ]"
echo -e "Options:"
echo -e " -h Print this help."
echo -e " dev Options:"
for i in "${!functionarray[@]}"; do
printf '\t\t%s\t%s\n' "${functionarray[i]}" "${descriptionarray[i]}"
done
}
# TEST 3
# check for -h -dev @ $1
# if -dev check @ $1 remove and shift $1 to check for x
check_opts() {
if [ "$1" == "dev" ]; 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"
fi
elif [[ "$1" == "dev" && "$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
fi
}
#check_opts_test1 "$@"
check_opts "$@"

214
bin/cpu_test.sh Executable file
View File

@@ -0,0 +1,214 @@
#!/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.
#
# CPU related tests.
#
directory="$(dirname "$(readlink -f "$0")")"
filename=$(basename "${BASH_SOURCE[0]}")
#libpath="$directory/../lib"
#selfpath="$libpath/configng/cpu.sh"
if [[ -d "$directory/../lib" ]]; then
libpath="$directory"/../lib
elif [[ -d "/usr/lib/bash-utility" && -d "/usr/lib/configng" ]]; then
libpath="/usr/lib"
elif [[ -d "/../functions/bash-utility-master/src" ]] ; then
libpath="$directory"/../functions/bash-utility-master/src
else
echo "Libraries not found"
exit 0
fi
# Source the files relative to the script location
source "$libpath/bash-utility/string.sh"
source "$libpath/bash-utility/collection.sh"
source "$libpath/bash-utility/array.sh"
source "$libpath/bash-utility/check.sh"
source "$libpath/configng/cpu.sh"
# Rest of the script...
# @description Print value from collection.
#
# @example
# collection::each "print_func"
# #Output
# Value in collection
print_func(){
printf "%s\n" "$1"
return 0
}
# @description Check function exit code and exit script if != 0.
#
# @example
# check_return
# #Output
# Nothing
check_return(){
if [ "$?" -ne 0 ]; then
exit 1
fi
}
see_cpu(){
# Get policy
declare -i policy=$(cpu::get_policy)
printf 'Policy = %d\n' "$policy"
declare -i min_freq=$(cpu::get_min_freq $policy)
check_return
printf 'Minimum frequency = %d\n' "$min_freq"
declare -i max_freq=$(cpu::get_max_freq $policy)
check_return
printf 'Maximum frequency = %d\n' "$max_freq"
governor=$(cpu::get_governor $policy)
check_return
printf 'Governor = %s\n' "$governor"
# Return frequencies as array
declare -a freqs=( $(string::split "$(cpu::get_freqs $policy)" " ") )
check_return
printf "\nAll frequencies\n"
# Print all values in collection
printf "%s\n" "${freqs[@]}" | collection::each "print_func"
declare -a governors=( $(string::split "$(cpu::get_governors $policy)" " ") )
check_return
printf "\nAll governors\n"
# Print all values in collection
printf "%s\n" "${governors[@]}" | collection::each "print_func"
# Are we running as sudo?
[[ "$EUID" != 0 ]] && printf "Must call cpu::set_freq as sudo\n" && exit 1
# Before
printf "\nBefore\n"
cat /etc/default/cpufrequtils
cpu::set_freq $policy "$min_freq" "$max_freq" performance
# After
printf "\nAfter\n"
cat /etc/default/cpufrequtils
}
readarray -t functionarray < <(grep -oP '^\w+::\w+' "$libpath/configng/cpu.sh")
readarray -t funnamearray < <(grep -oP '^\w+::\w+' "$libpath/configng/cpu.sh" | sed 's/.*:://')
readarray -t catagoryarray < <(grep -oP '^\w+::\w+' "$libpat/configng/cpu.sh" | sed 's/::.*//')
readarray -t descriptionarray < <(grep -oP '^# @description.*' "$libpath/configng/cpu.sh" | sed 's/^# @description //')
#printf '%s\n' "${functionarray[@]}"
#exit 0
see_help(){
echo ""
echo "Usage: ${filename%.*} [ -h | -dev | ]"
echo -e "Options:"
echo -e " -h Print this help."
echo -e " -dev Options:"
for i in "${!functionarray[@]}"; do
printf '\t\t%s\t%s\n' "${functionarray[i]}" "${descriptionarray[i]}"
done
echo -e " -cpu Options:"
for i in "${!functionarray[@]}"; do
printf '\t\t%s\t%s\n' "${funnamearray[i]}" "${descriptionarray[i]}"
done
}
# check for -dev -h options
check_opts_test1()
{
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" == "-cpu" ]] ; then
echo -e " "
echo -e " TODO:"
for i in "${!functionarray[@]}"; do
printf '\t\t%s\t%s \n' "${functionarray[i]}" "${descriptions[i]}"
done
elif [[ "$1" == -h ]] ; then
see_help
else
see_cpu
fi
}
# check for -h -dev
# if -dev check for number
check_opts_test2(){
if [ "$1" == "-dev" ]; 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
case "$function_name" in
0) echo "Calling function 0 with arguments: $@" ;;
1) echo "Calling function 1 with arguments: $@" ;;
2) echo "Calling function 2 with arguments: $@" ;;
3) echo "Calling function 3 with arguments: $@" ;;
4) echo "Calling function 4 with arguments: $@" ;;
*) echo "Invalid function name" ;;
esac
else
echo "No -dev flag found"
fi
}
# check for -h -dev @ $1
# if -dev check @ $1 remove and shift $1 to check for x
check_opts() {
if [ "$1" == "-dev" ]; 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"
fi
elif [ "$1" == "-h" ]; then
see_help
else
see_cpu
fi
}
#check_opts_test1 "$@"
check_opts "$@"
#cpu::set_freq $policy "$min_freq" "$max_freq" performance

212
bin/jampi-config Executable file
View File

@@ -0,0 +1,212 @@
#!/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=$(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 "$@"

View File

@@ -1,22 +0,0 @@
# 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

View File

@@ -1,3 +0,0 @@
/tmp
gh-pages
hugo-docs

View File

@@ -1,8 +0,0 @@
{
"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]
]
}

View File

View File

View File

View File

View File

Some files were not shown because too many files have changed in this diff Show More