Skip to content

Commit

Permalink
Refactored json Software section to accommodate the growing number ti…
Browse files Browse the repository at this point in the history
…tles (#111)
  • Loading branch information
Tearran authored Sep 25, 2024
1 parent 05296b1 commit 569365c
Show file tree
Hide file tree
Showing 6 changed files with 524 additions and 422 deletions.
168 changes: 84 additions & 84 deletions lib/armbian-configng/config.ng.docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ sudo armbian-config
$(see_full_list)
## Install
Armbian installation
## Install
Armbian installation
~~~
sudo apt install armbian-config
~~~
3rd party Debian based distributions
~~~
{
sudo wget https://apt.armbian.com/armbian.key -O key
sudo gpg --dearmor < key | sudo tee /usr/share/keyrings/armbian.gpg > /dev/null
sudo chmod go+r /usr/share/keyrings/armbian.gpg
sudo echo "deb [arch=\$(dpkg --print-architecture) signed-by=/usr/share/keyrings/armbian.gpg] http://apt.armbian.com \$(lsb_release -cs) main \$(lsb_release -cs)-utils \$(lsb_release -cs)-desktop" | sudo tee /etc/apt/sources.list.d/armbian.list
sudo apt update
sudo apt install armbian-config
sudo wget https://apt.armbian.com/armbian.key -O key
sudo gpg --dearmor < key | sudo tee /usr/share/keyrings/armbian.gpg > /dev/null
sudo chmod go+r /usr/share/keyrings/armbian.gpg
sudo echo "deb [arch=\$(dpkg --print-architecture) signed-by=/usr/share/keyrings/armbian.gpg] http://apt.armbian.com \$(lsb_release -cs) main \$(lsb_release -cs)-utils \$(lsb_release -cs)-desktop" | sudo tee /etc/apt/sources.list.d/armbian.list
sudo apt update
sudo apt install armbian-config
}
~~~
Expand Down Expand Up @@ -95,9 +95,9 @@ Click for more info:
<summary><b>Jobs / JSON Object</b></summary>
A list of the jobs defined in the Jobs file.
$(see_jq_menu_list)
~~~
$(see_jq_menu_list)
~~~
</details>
Expand Down Expand Up @@ -137,23 +137,23 @@ sudo apt install git jq whiptail
Get Development and contribute:
~~~
{
git clone https://github.com/armbian/configng
cd configng
./armbian-configng --help
git clone https://github.com/armbian/configng
cd configng
./armbian-configng --help
}
~~~
Install and test Development deb:
~~~
{
sudo apt install whiptail
latest_release=\$(curl -s https://api.github.com/repos/armbian/configng/releases/latest)
deb_url=\$(echo "\$latest_release" | jq -r '.assets[] | select(.name | endswith(".deb")) | .browser_download_url')
curl -LO "\$deb_url"
deb_file=\$(echo "\$deb_url" | awk -F"/" '{print \$NF}')
sudo dpkg -i "\$deb_file"
sudo dpkg --configure -a
sudo apt --fix-broken install
sudo apt install whiptail
latest_release=\$(curl -s https://api.github.com/repos/armbian/configng/releases/latest)
deb_url=\$(echo "\$latest_release" | jq -r '.assets[] | select(.name | endswith(".deb")) | .browser_download_url')
curl -LO "\$deb_url"
deb_file=\$(echo "\$deb_url" | awk -F"/" '{print \$NF}')
sudo dpkg -i "\$deb_file"
sudo dpkg --configure -a
sudo apt --fix-broken install
}
~~~
Expand Down Expand Up @@ -185,10 +185,10 @@ function serve_doc() {
python3 -m http.server > /tmp/config.log 2>&1 &
local server_pid=$!
local input=("
Starting server...
Server PID: $server_pid
Press [Enter] to exit"
Starting server...
Server PID: $server_pid
Press [Enter] to exit"
)

$DIALOG --title "Message Box" --msgbox "$input" 0 0
Expand Down Expand Up @@ -436,14 +436,13 @@ module_options+=(
# This function is used to generate a markdown list from the json object using jq.
#
function see_jq_menu_list() {

jq -r '
.menu[] |
.sub[] |
"### " + .id + "\n\n" +
(.description // "No description available") + "\n\nJobs:\n\n~~~\n" +
((.command // ["No commands available"]) | join("\n")) +
"\n~~~\n"
.menu[] |
.sub[] |
"### " + .id + "\n\n" +
(.description // "No description available") + "\n\nJobs:\n\n~~~\n" +
((.command // ["No commands available"]) | join("\n")) +
"\n~~~\n"
' $json_file
}

Expand All @@ -464,62 +463,63 @@ see_cmd_list() {

if [[ -n "$help_menu" && "$help_menu" != "cmd" ]]; then
echo "$json_data" | jq -r --arg menu "$help_menu" '
def recurse_menu(menu; level):
menu | .id as $id | .description as $desc |
if has("sub") then
if level == 0 then
"\n \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
elif level == 1 then
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
else
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
end
else
if level == 0 then
" --cmd \($id) - \($desc)"
elif level == 1 then
" --cmd \($id) - \($desc)"
else
"\t--cmd \($id) - \($desc)"
end
end;
# Find the correct menu if $menu is passed, otherwise show all
if $menu == "" then
.menu | map(recurse_menu(. ; 0)) | join("\n")
else
.menu | map(select(.id == $menu) | recurse_menu(. ; 0)) | join("\n")
end
'
def recurse_menu(menu; level):
menu | .id as $id | .description as $desc |
if has("sub") then
if level == 0 then
"\n \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
elif level == 1 then
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
else
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
end
else
if level == 0 then
" --cmd \($id) - \($desc)"
elif level == 1 then
" --cmd \($id) - \($desc)"
else
"\t--cmd \($id) - \($desc)"
end
end;
# Find the correct menu if $menu is passed, otherwise show all
if $menu == "" then
.menu | map(recurse_menu(. ; 0)) | join("\n")
else
.menu | map(select(.id == $menu) | recurse_menu(. ; 0)) | join("\n")
end
'
elif [[ -z "$1" || "$1" == "cmd" ]]; then
echo "$json_data" | jq -r --arg menu "$help_menu" '
def recurse_menu(menu; level):
menu | .id as $id | .description as $desc |
if has("sub") then
if level == 0 then
"\n \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
elif level == 1 then
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
else
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
end
else
if level == 0 then
" --cmd \($id) - \($desc)"
elif level == 1 then
" --cmd \($id) - \($desc)"
else
"\t--cmd \($id) - \($desc)"
end
end;
.menu | map(recurse_menu(. ; 0)) | join("\n")
'
def recurse_menu(menu; level):
menu | .id as $id | .description as $desc |
if has("sub") then
if level == 0 then
"\n \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
elif level == 1 then
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
else
" \($id) - \($desc)\n" + (.sub | map(recurse_menu(. ; level + 1)) | join("\n"))
end
else
if level == 0 then
" --cmd \($id) - \($desc)"
elif level == 1 then
" --cmd \($id) - \($desc)"
else
"\t--cmd \($id) - \($desc)"
end
end;
.menu | map(recurse_menu(. ; 0)) | join("\n")
'

else
echo "nope"
fi
}


module_options+=(
["see_cli_legacy,author"]="Joey Turner"
["see_cli_legacy,ref_link"]=""
Expand All @@ -538,10 +538,10 @@ Please use 'armbian-config --help' for more information.
Usage: $script_name main=[arguments] selection=[options]
EOF
cat << EOF
$script_name main=System selection=Headers - Install headers:
$script_name main=System selection=Headers_remove - Remove headers:

cat << EOF
$script_name main=System selection=Headers - Install headers:
$script_name main=System selection=Headers_remove - Remove headers:
EOF

# TODO Migrate following features
Expand Down
52 changes: 30 additions & 22 deletions lib/armbian-configng/config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -597,19 +597,19 @@ function execute_command() {

# Extract commands
local commands=$(jq -r --arg id "$id" '
.menu[] |
.. |
objects |
select(.id == $id) |
.command[]?' "$json_file")
.menu[] |
.. |
objects |
select(.id == $id) |
.command[]?' "$json_file")

# Check if a prompt exists
local prompt=$(jq -r --arg id "$id" '
.menu[] |
.. |
objects |
select(.id == $id) |
.prompt?' "$json_file")
.menu[] |
.. |
objects |
select(.id == $id) |
.prompt?' "$json_file")

# If a prompt exists, display it and wait for user confirmation
if [[ "$prompt" != "null" && $INPUTMODE != "cmd" ]]; then
Expand Down Expand Up @@ -842,8 +842,8 @@ module_options+=(
["see_current_apt,author"]="Joey Turner"
["see_current_apt,ref_link"]=""
["see_current_apt,feature"]="see_current_apt"
["see_current_apt,desc"]="Check when apt list was last updated"
["see_current_apt,example"]="see_current_apt"
["see_current_apt,desc"]="Check when apt list was last updated and suggest updating or update"
["see_current_apt,example"]="see_current_apt || see_current_apt update"
["see_current_apt,doc_link"]=""
["see_current_apt,status"]="Active"
)
Expand All @@ -852,37 +852,45 @@ module_options+=(
#
see_current_apt() {
# Number of seconds in a day
local update_apt="$1"
local day=86400

local ten_minutes=600
# Get the current date as a Unix timestamp
local now=$(date +%s)

# Get the timestamp of the most recently updated file in /var/lib/apt/lists/
local update=$(stat -c %Y /var/lib/apt/lists/* | sort -n | tail -1)
local update=$(stat -c %Y /var/lib/apt/lists/* 2>/dev/null | sort -n | tail -1)

# Check if the update timestamp was found
if [[ -z "$update" ]]; then
echo "No package lists found."
return 1 # No package lists exist
fi

# Calculate the number of seconds since the last update
local elapsed=$((now - update))

# Check if any apt-related processes are running
if ps -C apt-get,apt,dpkg > /dev/null; then
echo "A pkg is running."
echo "A package manager is currently running."
export running_pkg="true"
return 1 # The processes are running
else
export running_pkg="false"
#echo "apt, apt-get, or dpkg is not currently running"
fi

# Check if the package list is up-to-date
if ((elapsed < day)); then
#echo "Checking for apt-daily.service"
echo "$(date -u -d @${elapsed} +"%T")"
if ((elapsed < ten_minutes)); then
[[ "$update_apt" != "update" ]] && echo "The package lists are up-to-date."
return 0 # The package lists are up-to-date
else
#echo "Checking for apt-daily.service"
echo "Update the package lists"
return 1 # The package lists are not up-to-date
[[ "$update_apt" != "update" ]] && echo "Update the package lists." # Suggest updating
[[ "$update_apt" == "update" ]] && apt_install_wrapper apt-get update
return 0 # The package lists are not up-to-date
fi
}


module_options+=(
["are_headers_installed,author"]="Gunjan Gupta"
["are_headers_installed,ref_link"]=""
Expand Down
Loading

0 comments on commit 569365c

Please sign in to comment.