Skip to content

Commit

Permalink
Add missing cockpit module (#342)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Tearran and igorpecovnik authored Dec 30, 2024
1 parent 85bd37f commit de9ab05
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 45 deletions.
2 changes: 2 additions & 0 deletions tests/MAN001.conf
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/MAN002.conf
Original file line number Diff line number Diff line change
@@ -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
49 changes: 7 additions & 42 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@
"status": "Stable",
"author": "@armbian",
"condition": "module_sonarr status"
},
},
{
"id": "SON003",
"description": "Sonarr purge with data folder",
Expand Down Expand Up @@ -1264,7 +1264,6 @@
"author": "@igorpecovnik",
"condition": "module_netdata status"
}

]
},
{
Expand All @@ -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",
Expand Down Expand Up @@ -1357,7 +1322,7 @@
"id": "NET003",
"description": "iperf3 bandwidth measuring tool",
"prompt": "This operation will install iperf3.",
"command": [
"command": [
"pkg_install iperf3"
],
"status": "Stable",
Expand Down Expand Up @@ -1428,4 +1393,4 @@
]
}
]
}
}
6 changes: 3 additions & 3 deletions tools/modules/functions/interface_menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
3 changes: 3 additions & 0 deletions tools/modules/runtime/config.runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 104 additions & 0 deletions tools/modules/software/module_cockpit.sh
Original file line number Diff line number Diff line change
@@ -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"]} <command>"
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
}

0 comments on commit de9ab05

Please sign in to comment.