websoft9/install/install_cockpit.sh

96 lines
3 KiB
Bash
Raw Normal View History

2023-09-19 10:30:33 +00:00
#!/bin/bash
# Define PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
# Export PATH
export PATH
2023-09-21 10:15:19 +00:00
## Cockpit build at redhat family: https://copr.fedorainfracloud.org/coprs/g/cockpit/cockpit-preview/monitor/
## PackageKit: https://www.freedesktop.org/software/PackageKit/
## [apt show cockpit] or [apt install cockpit] show all additional packages
2023-09-19 09:44:20 +00:00
2023-09-21 10:15:19 +00:00
# $cockpit_port is define at install.sh
if [ -z "$cockpit_port" ]; then
cockpit_port="9000"
fi
2023-09-19 09:44:20 +00:00
2023-09-21 10:15:19 +00:00
cockpit_packages="cockpit cockpit-pcp cockpit-sosreport"
cockpit_plugin_delete="apps,selinux,kdump,sosreport,packagekit"
menu_overrides_github_page_url="https://websoft9.github.io/websoft9/cockpit/menu_override"
cockpit_menu_overrides=(networkmanager.override.json shell.override.json storaged.override.json systemd.override.json users.override.json)
Install_PackageKit(){
if command -v pkcon &> /dev/null; then
echo "pkcon is at you system"
elif command -v yum &> /dev/null; then
sudo yum install PackageKit
elif command -v dnf &> /dev/null; then
sudo dnf install PackageKit
elif command -v apt &> /dev/null; then
sudo apt update
sudo apt install packagekit
2023-09-19 09:44:20 +00:00
else
2023-09-21 10:15:19 +00:00
echo "PackageKit not found, Cockpit can not install"
exit 1
2023-09-19 09:44:20 +00:00
fi
}
2023-09-20 11:37:12 +00:00
2023-09-21 10:15:19 +00:00
Set_Firewall(){
if command -v firewall-cmd &> /dev/null; then
echo "Set firewall for Cockpit..."
sudo firewall-cmd --permanent --zone=public --add-service=cockpit
sudo firewall-cmd --reload
2023-09-19 09:44:20 +00:00
fi
2023-09-21 10:15:19 +00:00
if [ -f /etc/selinux/config ]; then
echo "Set Selinux for Cockpit..."
sudo setenforce 0 1>/dev/null 2>&1
sudo sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 1>/dev/null 2>&1
2023-09-19 09:44:20 +00:00
fi
2023-09-21 10:15:19 +00:00
}
2023-09-19 09:44:20 +00:00
2023-09-21 10:15:19 +00:00
Set_Cockpit(){
echo "Set Cockpit for Websoft9..."
sudo systemctl daemon-reload
sudo systemctl enable --now cockpit cockpit.socket
echo "Set Cockpit allowed root user"
file="/etc/cockpit/disallowed-users"
if [ -f "$file" ]; then
echo "" > "$file"
else
echo "$file is not exist"
fi
echo "Set cockpit port to $cockpit_port ..."
sudo sed -i "s/ListenStream=9090/ListenStream=$cockpit_port/" /lib/systemd/system/cockpit.socket
}
2023-09-19 09:44:20 +00:00
2023-09-21 10:15:19 +00:00
Download_Menu_Override(){
for file in "${cockpit_menu_overrides[@]}"
do
wget -N -P /etc/cockpit "$menu_overrides_github_page_url/$file"
done
2023-09-19 09:44:20 +00:00
}
2023-09-21 10:15:19 +00:00
Edit_Menu(){
echo "Start to edit Cockpit origin Menu ..."
# uninstall plugins
cp -r /data/apps/websoft9/cockpit/menu_override/* /etc/cockpit || Download_Menu_Override
sudo rm -rf /usr/share/cockpit/{$cockpit_plugin_delete}
sudo systemctl daemon-reload
sudo systemctl restart cockpit.socket
}
2023-09-19 09:44:20 +00:00
2023-09-20 11:37:12 +00:00
Install_Cockpit(){
2023-09-21 10:15:19 +00:00
echo "Prepare to install Cockpit ..."
sudo pkcon refresh
sudo pkcon get-updates
sudo pkcon install $cockpit_packages -y || echo "Install failed or this OS not support Cockpit"
sudo pkcon update cockpit -y || echo "Upgrade failed or this OS not support Cockpit"
Set_Firewall
Set_Cockpit
Edit_Menu
2023-09-19 11:55:23 +00:00
}
2023-09-21 10:15:19 +00:00
Install_PackageKit
2023-09-20 11:37:12 +00:00
Install_Cockpit