From de9ab05986774c0722ccb1618f83f819952c1404 Mon Sep 17 00:00:00 2001 From: Joey Turner Date: Mon, 30 Dec 2024 03:39:02 -0700 Subject: [PATCH] Add missing cockpit module (#342) * add cockpit module * add json * unit-testing * fix test * modified: tests/MAN001.conf modified: tests/MAN002.conf * Show cockpit port Only problem here is that it shows it also when service is disabled --------- Co-authored-by: Igor Pecovnik --- tests/MAN001.conf | 2 + tests/MAN002.conf | 4 + tools/json/config.software.json | 49 ++-------- tools/modules/functions/interface_menu.sh | 6 +- tools/modules/runtime/config.runtime.sh | 3 + tools/modules/software/module_cockpit.sh | 104 ++++++++++++++++++++++ 6 files changed, 123 insertions(+), 45 deletions(-) create mode 100644 tests/MAN002.conf create mode 100644 tools/modules/software/module_cockpit.sh diff --git a/tests/MAN001.conf b/tests/MAN001.conf index 7fb6f613e..a7a1f41bd 100644 --- a/tests/MAN001.conf +++ b/tests/MAN001.conf @@ -1,2 +1,4 @@ ENABLED=true +PREINSTALL="./bin/armbian-config --api module_cockpit install" in order to satisfy test case CONDITION="[ -f /usr/bin/cockpit-bridge ]" +RELEASE="bookworm:jammy:noble" run on specific or leave empty to run on all diff --git a/tests/MAN002.conf b/tests/MAN002.conf new file mode 100644 index 000000000..f201b7b25 --- /dev/null +++ b/tests/MAN002.conf @@ -0,0 +1,4 @@ +ENABLED=false +PREINSTALL="./bin/armbian-config --api module_cockpit purge" in order to satisfy test case +CONDITION="[ ! -f /usr/bin/cockpit-bridge ]" +RELEASE="bookworm:jammy:noble" run on specific or leave empty to run on all diff --git a/tools/json/config.software.json b/tools/json/config.software.json index 74807b6da..7ae7b67d7 100644 --- a/tools/json/config.software.json +++ b/tools/json/config.software.json @@ -612,7 +612,7 @@ "status": "Stable", "author": "@armbian", "condition": "module_sonarr status" - }, + }, { "id": "SON003", "description": "Sonarr purge with data folder", @@ -1264,7 +1264,6 @@ "author": "@igorpecovnik", "condition": "module_netdata status" } - ] }, { @@ -1273,47 +1272,13 @@ "sub": [ { "id": "MAN001", - "description": "Install Cockpit web-based management tool", - "about": "This operation will install Cockpit.\ncockpit cockpit-ws cockpit-system cockpit-storaged", - "command": [ - "see_current_apt update", - "pkg_install cockpit cockpit-ws cockpit-system cockpit-storaged " - ], - "status": "Stable", - "author": "@schwar3kat", - "condition": "! pkg_installed cockpit" - }, - { - "id": "MAN002", - "description": "Purge Cockpit web-based management tool", - "about": "This operation will purge Cockpit.", + "description": "Cockpit web-based management tool", "command": [ - "pkg_remove cockpit" + "see_menu module_cockpit" ], "status": "Stable", - "author": "@schwar3kat", - "condition": "pkg_installed cockpit" - }, - { - "id": "MAN003", - "description": "Start Cockpit Service", - "command": [ - "sudo systemctl enable --now cockpit.socket | show_infobox " - ], - "status": "Stable", - "author": "@schwar3kat", - "condition": "pkg_installed cockpit && ! systemctl is-enabled cockpit.socket > /dev/null 2>&1" - }, - { - "id": "MAN004", - "description": "Stop Cockpit Service", - "command": [ - "systemctl stop cockpit cockpit.socket", - "systemctl disable cockpit.socket | show_infobox " - ], - "status": "Stable", - "author": "@schwar3kat", - "condition": "pkg_installed cockpit && systemctl is-enabled cockpit.socket > /dev/null 2>&1" + "author": "@Tearran", + "condition": "" }, { "id": "MAN005", @@ -1357,7 +1322,7 @@ "id": "NET003", "description": "iperf3 bandwidth measuring tool", "prompt": "This operation will install iperf3.", - "command": [ + "command": [ "pkg_install iperf3" ], "status": "Stable", @@ -1428,4 +1393,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/tools/modules/functions/interface_menu.sh b/tools/modules/functions/interface_menu.sh index 028ca1ced..9dfc60386 100644 --- a/tools/modules/functions/interface_menu.sh +++ b/tools/modules/functions/interface_menu.sh @@ -41,17 +41,17 @@ function see_menu() { options=() while IFS= read -r line; do if [[ $line =~ ^[[:space:]]*([a-zA-Z0-9_-]+)[[:space:]]*-\s*(.*)$ ]]; then - options+=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}") + options+=("${BASH_REMATCH[1]}" " - ${BASH_REMATCH[2]}") fi done <<< "$help_message" # Display menu based on DIALOG tool case $DIALOG in "dialog") - choice=$(dialog --title "${function_name^} Management" --menu "Choose an option:" 15 60 9 "${options[@]}" 2>&1 >/dev/tty) + choice=$(dialog --title "${function_name^}" --menu "Choose an option:" 0 80 9 "${options[@]}" 2>&1 >/dev/tty) ;; "whiptail") - choice=$(whiptail --title "${function_name^} Management" --menu "Choose an option:" 15 60 9 "${options[@]}" 3>&1 1>&2 2>&3) + choice=$(whiptail --title "${function_name^}" --menu "Choose an option:" 0 80 9 "${options[@]}" 3>&1 1>&2 2>&3) ;; "read") echo "Available options:" diff --git a/tools/modules/runtime/config.runtime.sh b/tools/modules/runtime/config.runtime.sh index 8083737bc..da0705f68 100644 --- a/tools/modules/runtime/config.runtime.sh +++ b/tools/modules/runtime/config.runtime.sh @@ -125,6 +125,9 @@ update_sub_submenu_data "Software" "DNS" "DNS003" "http://$LOCALIPADD:${module_o update_sub_submenu_data "Software" "Monitoring" "MON002" "http://$LOCALIPADD:${module_options["module_uptimekuma,port"]}" update_sub_submenu_data "Software" "Monitoring" "MON006" "http://$LOCALIPADD:${module_options["module_netdata,port"]}" +# Management +update_sub_submenu_data "Software" "Management" "MAN001" "http://$LOCALIPADD:${module_options["module_cockpit,port"]}" + # Downloaders update_sub_submenu_data "Software" "Downloaders" "DOW002" "http://$LOCALIPADD:${module_options["module_qbittorrent,port"]%% *}" # removing second port from url update_sub_submenu_data "Software" "Downloaders" "DEL002" "http://$LOCALIPADD:${module_options["module_deluge,port"]%% *}" # removing second port from url diff --git a/tools/modules/software/module_cockpit.sh b/tools/modules/software/module_cockpit.sh new file mode 100644 index 000000000..f57129ca0 --- /dev/null +++ b/tools/modules/software/module_cockpit.sh @@ -0,0 +1,104 @@ +module_options+=( + ["module_cockpit,author"]="@tearran" + ["module_cockpit,maintainer"]="@igorpecovnik" + ["module_cockpit,feature"]="module_cockpit" + ["module_cockpit,example"]="help install remove start stop enable disable status check" + ["module_cockpit,desc"]="Cockpit setup and service setting." + ["module_cockpit,status"]="Stable" + ["module_cockpit,doc_link"]="https://cockpit-project.org/guide/latest/" + ["module_cockpit,group"]="Management" + ["module_cockpit,port"]="9090" + ["module_cockpit,arch"]="x86-64 arm64 armhf" +) + +function module_cockpit() { + local title="cockpit" + local condition=$(dpkg -s "cockpit" 2>/dev/null | sed -n "s/Status: //p") + # Convert the example string to an array + local commands + IFS=' ' read -r -a commands <<< "${module_options["module_cockpit,example"]}" + + case "$1" in + "${commands[0]}") + ## help/menu options for the module + echo -e "\nUsage: ${module_options["module_cockpit,feature"]} " + echo -e "Commands: ${module_options["module_cockpit,example"]}" + echo "Available commands:" + if [[ -z "$condition" ]]; then + echo -e " install\t- Install $title." + else + if [[ "$(systemctl is-active cockpit.socket 2>/dev/null)" == "active" ]]; then + echo -e "\tstop\t- Stop the $title service." + else + echo -e "\tstart\t- Start the $title service." + fi + if [[ $(systemctl is-enabled cockpit.socket) == "enabled" ]]; then + echo -e "\tdisable\t- Disable $title from starting on boot." + elif [[ $(systemctl is-enabled cockpit.socket) == "disabled" ]]; then + echo -e "\tenable\t- Enable $title to start on boot." + + fi + echo -e "\tstatus\t- Show the status of the $title service." + echo -e "\tremove\t- Remove $title." + fi + echo + ;; + "${commands[1]}") + ## install cockpit + pkg_update + pkg_install cockpit cockpit-ws cockpit-system cockpit-storaged + echo "Cockpit installed successfully." + ;; + "${commands[2]}") + ## remove cockpit + systemctl disable cockpit cockpit.socket + pkg_remove cockpit + echo "Cockpit removed successfully." + ;; + "${commands[3]}") + ## start cockpit + + systemctl start cockpit.socket + echo "Cockpit service started." + ;; + "${commands[4]}") + ## stop cockpit + + systemctl stop cockpit.socket + echo "Cockpit service stopped." + ;; + "${commands[5]}") + ## enable cockpit + #systemctl enable cockpit + systemctl enable cockpit.socket + echo "Cockpit service enabled." + ;; + "${commands[6]}") + ## disable cockpit + #systemctl disable cockpit + systemctl disable cockpit.socket + echo "Cockpit service disabled." + ;; + "${commands[7]}") + ## status cockpit + #systemctl status cockpit + systemctl status cockpit.socket + ;; + "${commands[-1]}") + ## check cockpit status + if [[ $(systemctl is-active cockpit.socket) == "active" ]]; then + echo "Cockpit service is active." + return 0 + elif [[ $(systemctl is-enabled cockpit.socket) == "disabled" ]]; then + echo "Cockpit service is disabled." + return 0 + else + return 1 + fi + ;; + *) + echo "Invalid command. Try: '${module_options["module_cockpit,example"]}'" + ;; + esac +} +