diff --git a/cockpit/Notes b/cockpit/Notes deleted file mode 100644 index 879f8d2a..00000000 --- a/cockpit/Notes +++ /dev/null @@ -1,19 +0,0 @@ -# Cockpit - -对[Cockpit](https://cockpit-project.org/)进行菜单改造和功能整合,使得我们的 runtime 产品具有更好的用户体验。 - -## 删除 - -* machines -* subscriptions -* kdump -* updates -* playground -* sosreport - -## 新增 - -* nginx-proxy -* 文件管理 -* 数据库管理 -* 导航页面 diff --git a/cockpit/README.md b/cockpit/README.md index 76ac1043..35090ea5 100644 --- a/cockpit/README.md +++ b/cockpit/README.md @@ -1,10 +1,19 @@ # Cockpit +Cockpit is used for backend service gatway, we have not modify Cockpit core, just improve the installation and modify config for Websoft9 ## Install -1. Install Cockpit core and official plugin +``` +wget https://websoft9.github.io/websoft9/install/install_cockpit.sh && bash install_cockpit.sh +``` +## Development +Developer should improve these codes: -2. Install plugin powered by websoft9 \ No newline at end of file +- Install and Upgrade Cockpit: */install/install_cockpit.sh* +- Override the default menus: */cockpit/menu_override* +- Cockipt configuration file: */cockpit/cockpit.conf* + +> shell.override.json is used for Top menu of Cockpit \ No newline at end of file diff --git a/cockpit/cockpit.conf b/cockpit/cockpit.conf index cadd02d0..9dcdf2cc 100644 --- a/cockpit/cockpit.conf +++ b/cockpit/cockpit.conf @@ -1,2 +1,4 @@ +# docs: https://cockpit-project.org/guide/latest/cockpit.conf.5.html + [WebService] AllowUnencrypted = true \ No newline at end of file diff --git a/install/install_cockpit.sh b/install/install_cockpit.sh index 7efd38cb..04c90807 100644 --- a/install/install_cockpit.sh +++ b/install/install_cockpit.sh @@ -9,18 +9,25 @@ export PATH ## PackageKit: https://www.freedesktop.org/software/PackageKit/ ## [apt show cockpit] or [apt install cockpit] show all additional packages +# Below vars from install.sh +# cockpit_port +# install_path + # $cockpit_port is define at install.sh if [ -z "$cockpit_port" ]; then cockpit_port="9000" fi +echo_prefix_cockpit=$'\n[Cockpit] - ' cockpit_packages="cockpit cockpit-pcp cockpit-sosreport" -cockpit_plugin_delete="apps,selinux,kdump,sosreport,packagekit" +cockpit_plugin_delete="apps,machines,selinux,subscriptions,kdump,updates,playground,packagekit" menu_overrides_github_page_url="https://websoft9.github.io/websoft9/cockpit/menu_override" +cockpit_config_github_page_url="https://websoft9.github.io/websoft9/cockpit/cockpit.conf" cockpit_menu_overrides=(networkmanager.override.json shell.override.json storaged.override.json systemd.override.json users.override.json) Install_PackageKit(){ + echo "$echo_prefix_cockpit Try to install pkcon" if command -v pkcon &> /dev/null; then echo "pkcon is at you system" elif command -v yum &> /dev/null; then @@ -36,7 +43,14 @@ Install_PackageKit(){ fi } +Restart_Cockpit(){ + echo "$echo_prefix_cockpit Restart Cockpit" + sudo systemctl daemon-reload + sudo systemctl restart cockpit +} + Set_Firewall(){ + echo "$echo_prefix_cockpit Set firewall for cockpit access" if command -v firewall-cmd &> /dev/null; then echo "Set firewall for Cockpit..." sudo firewall-cmd --permanent --zone=public --add-service=cockpit @@ -51,46 +65,93 @@ Set_Firewall(){ } 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" + echo "$echo_prefix_cockpit Set Cockpit for Websoft9" + + echo "Cockpit allowed root user ..." + echo "" > /etc/cockpit/disallowed-users + + echo "Set Cockpit config file..." + if [ -f "$install_path/cockpit/cockpit.conf" ]; then + cp -f "$install_path/cockpit/cockpit.conf" /etc/cockpit/cockpit.conf else - echo "$file is not exist" + echo "Download config from URL" + curl -sSL $cockpit_config_github_page_url | sudo tee /etc/cockpit/cockpit.conf > /dev/null fi - echo "Set cockpit port to $cockpit_port ..." + + echo "Change cockpit default port to $cockpit_port ..." sudo sed -i "s/ListenStream=9090/ListenStream=$cockpit_port/" /lib/systemd/system/cockpit.socket } Download_Menu_Override(){ for file in "${cockpit_menu_overrides[@]}" do - wget -N -P /etc/cockpit "$menu_overrides_github_page_url/$file" + + echo "$menu_overrides_github_page_url/$file" + + curl -sSL "$menu_overrides_github_page_url/$file" | sudo tee /etc/cockpit/"$file" > /dev/null + if [ $? -ne 0 ]; then + echo "Failed to download files" + exit 1 + fi + done } Edit_Menu(){ - echo "Start to edit Cockpit origin Menu ..." - # uninstall plugins - cp -r /data/apps/websoft9/cockpit/menu_override/* /etc/cockpit || Download_Menu_Override + echo "$echo_prefix_cockpit Start to edit Cockpit origin Menu" + if [ -f "$install_path/cockpit/cockpit.conf" ]; then + cp -f "$install_path/cockpit/cockpit.conf" /etc/cockpit/cockpit.conf + else + echo "Download config file from URL..." + curl -sSL $cockpit_config_github_page_url | sudo tee /etc/cockpit/cockpit.conf > /dev/null + fi + + if test -d "$install_path/cockpit/menu_override"; then + cp -r $install_path/cockpit/menu_override/* /etc/cockpit + else + echo "Download override files from URL..." + Download_Menu_Override + fi + sudo rm -rf /usr/share/cockpit/{$cockpit_plugin_delete} - sudo systemctl daemon-reload - sudo systemctl restart cockpit.socket +} + +Upgrade_Cockpit(){ + echo "$echo_prefix_cockpit Prepare to upgrade Cockpit" + output=$(sudo pkcon update $cockpit_packages -y 2>&1) + if [ $? -ne 0 ]; then + echo "Cockpit upgrade failed or not need upgrade..." + else + echo "$output" + fi } Install_Cockpit(){ - 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" + + sudo pkcon refresh > /dev/null + sudo pkcon get-updates > /dev/null + + if systemctl is-active --quiet cockpit; then + Upgrade_Cockpit + Restart_Cockpit + else + echo "$echo_prefix_cockpit Prepare to install Cockpit" + export DEBIAN_FRONTEND=noninteractive + sudo pkcon install $cockpit_packages -y + Restart_Cockpit + fi + Set_Firewall Set_Cockpit Edit_Menu + Restart_Cockpit } + +#### -------------- main() start here ------------------- #### + Install_PackageKit -Install_Cockpit \ No newline at end of file +Install_Cockpit + +# release package memory +sudo systemctl restart packagekit.service \ No newline at end of file