Skip to content

Commit

Permalink
Add bridges networking to all existing bridges in the system
Browse files Browse the repository at this point in the history
and cleanup.
  • Loading branch information
igorpecovnik committed Jan 19, 2025
1 parent f0ed952 commit c8126da
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 98 deletions.
File renamed without changes
16 changes: 16 additions & 0 deletions tools/include/markdown/COC001-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Cockpit is a web-based graphical interface for servers, intended for everyone.

Here’s a subset of tasks you can perform on each host running Cockpit

- inspect and change network settings
- configure a firewall
- manage storage (including RAID and LUKS partitions)
- create and manage virtual machines
- download and run containers
- browse and search system logs
- inspect a system’s hardware
- upgrade software
- manage user accounts
- inspect and interact with systemd-based services
- use a terminal on a remote server in your local web browser
- switch between multiple Cockpit servers
11 changes: 0 additions & 11 deletions tools/include/markdown/MAN001-footer.md

This file was deleted.

20 changes: 15 additions & 5 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -1304,14 +1304,24 @@
"description": "Remote Management tools",
"sub": [
{
"id": "MAN001",
"description": "Cockpit web-based management tool",
"id": "COC001",
"description": "Cockpit OS and VM management tool",
"command": [
"see_menu module_cockpit"
"module_cockpit install"
],
"status": "Stable",
"author": "@Tearran",
"condition": ""
"author": "@igorpecovnik",
"condition": "! module_cockpit status"
},
{
"id": "COC002",
"description": "Remove Cockpit",
"command": [
"module_cockpit remove"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_cockpit status"
},
{
"id": "MAN005",
Expand Down
2 changes: 1 addition & 1 deletion tools/modules/runtime/config.runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ update_sub_submenu_data "Software" "Monitoring" "MON006" "http://$LOCALIPADD:${m
update_sub_submenu_data "Software" "Monitoring" "GRA002" "http://$LOCALIPADD:${module_options["module_grafana,port"]}"

# Management
update_sub_submenu_data "Software" "Management" "MAN001" "http://$LOCALIPADD:${module_options["module_cockpit,port"]}"
update_sub_submenu_data "Software" "Management" "COC002" "https://$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
Expand Down
133 changes: 52 additions & 81 deletions tools/modules/software/module_cockpit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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,example"]="install remove status help"
["module_cockpit,desc"]="Cockpit setup and service setting."
["module_cockpit,status"]="Stable"
["module_cockpit,doc_link"]="https://cockpit-project.org/guide/latest/"
Expand All @@ -14,103 +14,74 @@ module_options+=(
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."

## install cockpit
pkg_update
pkg_install cockpit cockpit-ws cockpit-system cockpit-storaged cockpit-machines dnsmasq virtinst qemu-kvm qemu-utils

usermod -a -G libvirt libvirtdbus
usermod -a -G libvirt libvirt-qemu

# add bridged networking if bridges exists on the system
for f in /sys/class/net/*; do
intf=$(basename $f)
if [[ $intf =~ ^br[0-9] ]]; then
cat <<- EOF > /etc/libvirt/kvm-hostbridge-${intf}.xml
<network>
<name>hostbridge-${intf}</name>
<forward mode="bridge"/>
<bridge name="${intf}"/>
</network>
EOF
virsh net-define /etc/libvirt/kvm-hostbridge-${intf}.xml
virsh net-start hostbridge-${intf}
virsh net-autostart hostbridge-${intf}
fi
done
if $DIALOG --title " Reboot required " --yes-button "Reboot" --no-button "Cancel" --yesno \
"A reboot is required to start $title properly. Shall we reboot now?" 7 34; then
reboot
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 cockpit-machines samba dnsmasq virtinst qemu-kvm qemu-utils
# add bridged networking
cat <<- EOF > /etc/libvirt/kvm-hostbridge.xml
<network>
<name>hostbridge</name>
<forward mode="bridge"/>
<bridge name="br0"/>
</network>
EOF
virsh net-define /etc/libvirt/kvm-hostbridge.xml
virsh net-start hostbridge
virsh net-autostart hostbridge
## remove cockpit
systemctl stop cockpit.socket 2>/dev/null
systemctl stop cockpit 2>/dev/null
systemctl disable cockpit 2>/dev/null
for bridge in $(grep hostbridge /etc/libvirt/kvm-hostbridge-br* | grep -o -P '(?<=name>).*(?=\</name)'); do
virsh net-destroy ${bridge}
virsh net-undefine ${bridge}
done
pkg_remove cockpit cockpit-ws cockpit-system cockpit-storaged cockpit-machines dnsmasq virtinst qemu-kvm qemu-utils

echo "Cockpit installed successfully."
;;
"${commands[2]}")
## remove cockpit
systemctl disable cockpit cockpit.socket
pkg_remove cockpit
echo "Cockpit removed successfully."
if pkg_installed cockpit; then
return 0
else
return 1
fi
;;
"${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 -e "\nUsage: ${module_options["module_cockpit,feature"]} <command>"
echo -e "Commands: ${module_options["module_cockpit,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tremove\t- Remove $title."
echo -e "\tstatus\t- Status $title."
echo
;;
*)
echo "Invalid command. Try: '${module_options["module_cockpit,example"]}'"
${module_options["module_cockpit,feature"]} ${commands[3]}
;;
esac
}

0 comments on commit c8126da

Please sign in to comment.