Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust software $json_data to match recent changes #339

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ jobs:
echo "# Succesful tests:" >> $GITHUB_STEP_SUMMARY
echo "|Release|Command|Description|" >> $GITHUB_STEP_SUMMARY
echo "|:---|:---|:---|" >> $GITHUB_STEP_SUMMARY
cat ./*.teststats | sed '$ s/.$//' >> $GITHUB_STEP_SUMMARY
cat ./*.teststats | sed '$ s/.$//' >> $GITHUB_STEP_SUMMARY
30 changes: 25 additions & 5 deletions bin/armbian-config
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ lib_dir="$script_dir/../lib/armbian-config"
doc_dir="$script_dir/../share/doc/armbian-config"
json_file="$lib_dir/config.jobs.json"

#
# Load The Bash procedure Objects
json_data=$(<"$json_file")

#
# Prepare the module options array
Expand All @@ -37,7 +34,7 @@ declare -A module_options

source "$lib_dir/config.functions.sh"
set_runtime_variables
check_distro_status
#check_distro_status
echo "Loaded Runtime variables..." #| show_infobox ;
#set_newt_colors 2
echo "Loaded Dialog..." #| show_infobox ;
Expand All @@ -52,9 +49,32 @@ echo "Loaded Software helpers..." #| show_infobox ;
#
# Loads the variables from beta armbian-config for runtime handling

source "$lib_dir/config.runtime.sh"

#
# Load The Bash procedure Objects
old_json_data=$(<"$json_file")

# Generate the new JSON data
new_json_data=$(generate_software_json)

json_data=$(jq -s '
.[0] as $existing |
.[1] as $new |
{
menu: ($existing.menu + $new.menu)
}
' <(echo "$old_json_data") <(echo "$new_json_data"))


#source "$lib_dir/config.runtime.sh"
echo "Loaded Runtime conditions..." #| show_infobox ;







clear

case "$1" in
Expand Down
194 changes: 194 additions & 0 deletions generate_json_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@



function set_json_data() {
local i=0

features=()
for key in "${!module_options[@]}"; do
if [[ $key == *",feature" ]]; then
features+=("${module_options[$key]}")
fi
done

{
echo -e "["

for feature in "${features[@]}"; do
feature_prefix=$(echo "${feature:0:3}" | tr '[:lower:]' '[:upper:]') # Extract first 3 letters and convert to uppercase

i=$((i + 1))
id=$(printf "%s%03d" "$feature_prefix" "$i") # Combine prefix with padded number

# Get keys pairs
desc_key="${feature},desc"
example_key="${feature},example"
author_key="${feature},author"
ref_key="${feature},ref_link"
status_key="${feature},status"
doc_key="${feature},doc_link"
helpers_key="${feature},helpers"
group_key="${feature},group"
commands_key="${feature},commands"
port_key="${feature},port"
arch_key="${feature},arch"

# Get array info
author="${module_options[$author_key]}"
ref_link="${module_options[$ref_key]}"
status="${module_options[$status_key]}"
doc_link="${module_options[$doc_key]}"
desc="${module_options[$desc_key]}"
example="${module_options[$example_key]}"
helpers="${module_options[$helpers_key]}"
group="${module_options[$group_key]}"
commands="${module_options[$commands_key]}"
port="${module_options[$port_key]}"
arch="${module_options[$arch_key]}"

echo " {"
echo " \"id\": \"$id\","
echo " \"feature\": \"$feature\","
echo " \"helpers\": \"$helpers\","
echo " \"description\": \"$desc ($feature)\","
echo " \"command\": \"$feature\","
echo " \"options\": \"$example\","
echo " \"status\": \"$status\","
echo " \"condition\": \" \","
echo " \"reference\": \"$ref_link\","
echo " \"author\": \"$author\","
echo " \"group\": \"$group\","
echo " \"commands\": \"$commands\","
echo " \"port\": \"$port\","
echo " \"arch\": \"$arch\""

if [ $i -ne ${#features[@]} ]; then
echo " },"
else
echo " }"
fi
done
echo "]"

} | jq .

}


function generate_module_list() {
set_json_data | jq '
# Define an array of allowed software groups
def softwareGroups: ["WebHosting", "Netconfig", "Downloaders", "Database", "DNS", "DevTools", "HomeAutomation", "Benchy", "Containers", "Media", "Monitoring", "Management"];

{
"menu": [
{
"id": "Software",
"description": "Run/Install 3rd party applications",
"sub": (
group_by(.group)
# Skip grouped arrays where the group is null, empty, or not in softwareGroups
| map(select(.[0].group != null and .[0].group != "" and (.[0].group | IN(softwareGroups[]))))
| map({
"id": .[0].group,
"description": .[0].group,
"sub": (
map({
"id": .id,
"description": .description,
"command": [("see_menu " + .feature)],
"options": ("help " + .options + " status"),
"status": .status,
"condition": "",
"author": .author
})
)
})
)
}
]
}
'
}


function generate_json_data() {
set_json_data | jq '{
"menu": [
{
"id": "tests",
"description": "Run/Install 3rd party applications",
"sub": [
{
"id": "Modules",
"description": "Various installable modules",
"sub": [
.[] |
if (.feature | type == "string") and (.feature | startswith("module_")) then
{
"id": .id,
"description": .description,
"command": [("see_menu " + .feature)],
"options": ("help " + .options + " status"),
"status": .status,
"condition": "",
"author": .author
}
else empty
end
]
}
]
}
]
}'

}


# Test Function
interface_json_data_old() {

# uncomment to set the data to a file
set_json_data | jq --tab --indent 4 '.' > tools/json/config.temp.json
#generate_json_data | jq --indent 4 "." > tools/json/config.temp.json
#json_file="$tools_dir/json/config.temp.json

json_data=$(generate_json_data)
#generate_top_menu "$json_data"

generate_menu "Software" "$json_data"
}


# Test Function
interface_json_data() {
# Convert the example string to an array
local commands=("raw" "mnu" "top" "sub" "help")
json_data=$(generate_json_data)
case "$1" in

"${commands[0]}")
echo "Setting JSON data to file..."
set_json_data | jq --tab --indent 4 '.' > tools/json/config.temp.json
;;
"${commands[1]}")
echo "Generating JSON data..."
generate_json_data | jq --tab --indent 4 '.' > tools/json/config.temp.json
;;
"${commands[2]}")
generate_top_menu "$json_data"
;;
"${commands[3]}")
generate_menu "Software" "$json_data"
;;
"${commands[-1]}")
echo "Usage: interface_json_data <command>"
echo "Available commands:"
echo -e "\traw\t- Set flat JSON data to a file for inspection not used"
echo -e "\tmnu\t- Generate the Menu JSON data to file for inspection not used"
echo -e "\ttop\t- Show the top menu using the JSON data."
echo -e "\tsub\t- Show the Software menu using the JSON data."
;;
esac
}
2 changes: 1 addition & 1 deletion tests/CON002.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ENABLED=true
ENABLED=false
RELEASE="bookworm:jammy:noble"
CONDITION="docker run hello-world"
2 changes: 1 addition & 1 deletion tests/CON005.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ENABLED=true
ENABLED=false
RELEASE="bookworm:jammy:noble"
CONDITION="test=\$(docker container ls -a | grep portainer )"
2 changes: 1 addition & 1 deletion tests/HAB001.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ENABLED=true
ENABLED=false
CONDITION="[ -f /lib/systemd/system/openhab.service ]"
2 changes: 1 addition & 1 deletion tests/MAN001.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ENABLED=true
ENABLED=false
CONDITION="[ -f /usr/bin/cockpit-bridge ]"
2 changes: 1 addition & 1 deletion tests/MON001.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ENABLED=true
ENABLED=false
RELEASE="bookworm:jammy:noble"
CONDITION="test=\$(docker container ls -a | grep uptime-kuma )"
2 changes: 1 addition & 1 deletion tests/SY008.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ENABLED=true
ENABLED=false
PREINSTALL="bash bin/armbian-config --cmd SY009"
CONDITION="[ ! -f /usr/bin/zsh ]"
2 changes: 1 addition & 1 deletion tests/SY101.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ENABLED=true
ENABLED=false
RELEASE="jammy:bullseye"
2 changes: 1 addition & 1 deletion tests/SY102.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ENABLED=true
ENABLED=false
RELEASE="bullseye:bookworm:trixie:jammy:noble"
2 changes: 1 addition & 1 deletion tests/SY202.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ENABLED=true
ENABLED=false
2 changes: 1 addition & 1 deletion tests/SY203.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ENABLED=true
ENABLED=false
2 changes: 1 addition & 1 deletion tests/SY206.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ENABLED=true
ENABLED=false
2 changes: 1 addition & 1 deletion tests/SY207.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ENABLED=true
ENABLED=false
28 changes: 0 additions & 28 deletions tools/json/config.help.json

This file was deleted.

2 changes: 1 addition & 1 deletion tools/json/config.software.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"menu": [
{
"id": "Software",
"id": "Software00",
"description": "Run/Install 3rd party applications",
"sub": [
{
Expand Down
Loading
Loading