install cockpit

This commit is contained in:
Darren 2023-09-21 18:15:19 +08:00 committed by GitHub
parent 7d048fab6d
commit 2864c70774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 214 deletions

View file

@ -5,204 +5,92 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
function get_os_type() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
else
OS=$(uname -s)
fi
## 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
if [[ "$OS" == "CentOS Linux" ]]; then
echo "CentOS"
elif [[ "$OS" == "CentOS Stream" ]]; then
echo "CentOS Stream"
elif [[ "$OS" == "Rocky Linux" ]]; then
echo "Rocky Linux"
elif [[ "$OS" == "Oracle Linux Server" ]]; then
echo "OracleLinux"
elif [[ "$OS" == "Debian GNU/Linux" ]]; then
echo "Debian"
elif [[ "$OS" == "Ubuntu" ]]; then
echo "Ubuntu"
elif [[ "$OS" == "Fedora Linux" ]]; then
echo "Fedora"
elif [[ "$OS" =~ "Red Hat Enterprise Linux" ]]; then
echo "Redhat"
# $cockpit_port is define at install.sh
if [ -z "$cockpit_port" ]; then
cockpit_port="9000"
fi
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
else
echo $OS
echo "PackageKit not found, Cockpit can not install"
exit 1
fi
}
function get_os_version() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VERSION=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
VERSION=$(lsb_release -sr)
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
fi
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
fi
}
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
OS=$(uname -s)
VERSION=$(uname -r)
echo "$file is not exist"
fi
echo $VERSION
echo "Set cockpit port to $cockpit_port ..."
sudo sed -i "s/ListenStream=9090/ListenStream=$cockpit_port/" /lib/systemd/system/cockpit.socket
}
os_type=$(get_os_type)
os_version=$(get_os_version)
Check_OS(){
echo "Check OS environment for install Cockpit..."
echo os_type: $os_type
echo os_version: $os_version
if [ $(id -u) != "0" ]; then
echo "Please change to root or 'sudo su' to up system privileges, and reinstall the script again ."
exit 1
fi
if [ $(getconf WORD_BIT) = '32' ] && [ $(getconf LONG_BIT) = '64' ] ; then
echo "64-bit operating system detected."
else
echo "This script only works on 64-bit operating systems."
exit 1
fi
if [ "$os_type" == 'CentOS' ] ;then
if [ "$os_version" != "7" ]; then
echo "This app only supported on CentOS 7"
exit 1
fi
fi
if [ "$os_type" == 'CentOS Stream' ] ;then
if [ "$os_version" != "8" ] || [ "$os_version" != "9" ]; then
echo "This app only supported on CentOS Stream 8,9"
exit 1
fi
fi
if [ "$os_type" == 'Rocky Linux' ] ;then
if [ "${os_version:0:1}" == "8" ] || [ "${os_version:0:1}" == "9" ]; then
echo ""
else
echo "This app only supported on Rocky Linux 8"
exit 1
fi
fi
if [ "$os_type" == 'Fedora' ];then
if [ "$os_version" != "37" ]; then
echo "This app only supported on Fedora 37"
exit 1
fi
fi
if [ "$os_type" == 'Redhat' ];then
if [ "${os_version:0:1}" != "7" ] && [ "${os_version:0:1}" != "8" ] && [ "${os_version:0:1}" != "9" ]; then
echo "This app only supported on Redhat 7,8"
exit 1
fi
fi
if [ "$os_type" == 'Ubuntu' ];then
if [ "$os_version" != "22.04" ] && [ "$os_version" != "20.04" ] && [ "$os_version" != "18.04" ]; then
echo "This app only supported on Ubuntu 22.04,20.04,18.04"
exit 1
fi
fi
if [ "$os_type" == 'Debian' ];then
if [ "$os_version" != "11" ];then
echo "This app only supported on Debian 11"
exit 1
fi
fi
Download_Menu_Override(){
for file in "${cockpit_menu_overrides[@]}"
do
wget -N -P /etc/cockpit "$menu_overrides_github_page_url/$file"
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
sudo rm -rf /usr/share/cockpit/{$cockpit_plugin_delete}
sudo systemctl daemon-reload
sudo systemctl restart cockpit.socket
}
Install_Cockpit(){
echo "Prepare to install Cockpit ..."
if [ "${os_type}" == 'Debian' ]; then
VERSION_CODENAME=$(cat /etc/os-release |grep VERSION_CODENAME|cut -f2 -d"=")
sudo echo "deb http://deb.debian.org/debian ${VERSION_CODENAME}-backports main" >/etc/apt/sources.list.d/backports.list
sudo apt update
sudo apt install -t ${VERSION_CODENAME}-backports cockpit -y
sudo apt install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>&1
fi
if [ "${os_type}" == 'Ubuntu' ]; then
if grep -q "^#.*deb http://mirrors.tencentyun.com/ubuntu.*backports" /etc/apt/sources.list; then
echo "Add backports deb ..."
sudo sed -i 's/^#\(.*deb http:\/\/mirrors.tencentyun.com\/ubuntu.*backports.*\)/\1/' /etc/apt/sources.list
apt update
fi
VERSION_CODENAME=$(cat /etc/os-release |grep VERSION_CODENAME|cut -f2 -d"=")
sudo apt install -t ${VERSION_CODENAME}-backports cockpit -y
sudo apt install cockpit-pcp -y 1>/dev/null 2>&1
echo "Cockpit allow root user"
echo "" >/etc/cockpit/disallowed-users 1>/dev/null 2>&1
fi
if [ "${os_type}" == 'CentOS' ] || [ "$os_type" == 'OracleLinux' ]; then
sudo yum install cockpit -y
sudo yum install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>&1
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --permanent --zone=public --add-service=cockpit
sudo firewall-cmd --reload
fi
if [ "$os_type" == 'Fedora' ]; then
sudo dnf install cockpit -y
sudo dnf install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>&1
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --add-service=cockpit
sudo firewall-cmd --add-service=cockpit --permanent
fi
if [ "$os_type" == 'Redhat' ] ; then
sudo subscription-manager repos --enable rhel-7-server-extras-rpms 1>/dev/null 2>&1
sudo yum install cockpit -y
sudo yum install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>&1
sudo setenforce 0 1>/dev/null 2>&1
sudo sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 1>/dev/null 2>&1
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --add-service=cockpit
sudo firewall-cmd --add-service=cockpit --permanent
fi
if [ "$os_type" == 'CentOS Stream' ]; then
sudo subscription-manager repos --enable rhel-7-server-extras-rpms 1>/dev/null 2>&1
sudo yum install cockpit -y
sudo yum install cockpit-pcp -y 1>/dev/null 2>&1
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --add-service=cockpit
sudo firewall-cmd --add-service=cockpit --permanent
sudo setenforce 0 1>/dev/null 2>&1
sudo sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 1>/dev/null 2>&1
fi
file="/etc/cockpit/disallowed-users"
if [ -f "$file" ]; then
echo "" > "$file"
else
echo "$file is not exist"
fi
echo "Set cockpit port to 9000 ..."
sudo sed -i 's/ListenStream=9090/ListenStream=9000/' /lib/systemd/system/cockpit.socket
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
}
Check_OS
Install_PackageKit
Install_Cockpit

View file

@ -26,7 +26,7 @@ export PATH
############################################################
# This script is
# $force_value is define at install.sh
# $force_install is define at install.sh
############################################################
docker_packages="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"

View file

@ -11,10 +11,18 @@ export PATH
# --force <y|n>
# Use the --force option to ignore all interactive choices. default is n, for example:
#
# $ sudo sh install.sh --force n
#
# --port <9000>
# Use the --port option to set Websoft9 cosole port. default is 9000, for example:
#
# $ sudo sh install.sh --port 9001
#
# --channel <release|dev>
# Use the --channel option to install a release(production) or dev distribution. default is release, for example:
#
# $ sudo sh install.sh --channel release
#
# ==============================================================================
#!/bin/bash
@ -22,6 +30,7 @@ export PATH
# 设置参数的默认值
force="n"
port="9000"
channel="release"
# 获取参数值
while [[ $# -gt 0 ]]; do
@ -34,6 +43,10 @@ while [[ $# -gt 0 ]]; do
port="$2"
shift 2
;;
--channel)
channel="$2"
shift 2
;;
*)
shift
;;
@ -41,10 +54,13 @@ while [[ $# -gt 0 ]]; do
done
# 输出参数值
echo "Force: $force"
echo "Port: $port"
echo "Your installation parameters are as follows: "
echo "--force: $force"
echo "--port: $port"
echo "--channel: $channel"
# Define global vars
# export var can send it to subprocess
export http_port=80
export https_port=443
@ -53,16 +69,12 @@ export force_install=$force
export install_path="/data/websoft9/source"
export source_zip="websoft9-latest.zip"
export source_unzip="websoft9"
export source_github_pages="https://websoft9.github.io/websoft9"
export tools_yum="git curl wget yum-utils jq bc unzip"
export tools_apt="git curl wget jq bc unzip"
export docker_network="websoft9"
export urls="https://w9artifact.blob.core.windows.net/release/websoft9"
if [[ "$1" == "dev" ]]; then
echo "update by dev artifact"
export urls="https://w9artifact.blob.core.windows.net/dev/websoft9"
fi
export urls="https://w9artifact.blob.core.windows.net/$channel/websoft9"
echo Install from url: $urls
# Define common functions
@ -78,14 +90,14 @@ install_tools(){
if [ $dnf_status -eq 0 ]; then
dnf install $tools_yum -y
elif [ $yum_status -eq 0 ]; then
yum $tools_yum -y
yum install $tools_yum -y
elif [ $apt_status -eq 0 ]; then
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
echo "Waiting for other software managers to finish..."
sleep 5
done
sudo apt update -y 1>/dev/null 2>&1
apt $tools_apt -y --assume-yes
apt install $tools_apt -y --assume-yes
else
echo "None of the required package managers are installed."
fi
@ -95,13 +107,14 @@ install_tools(){
download_source() {
echo "Download Websoft9 source code..."
rm -rf websoft9-latest.zip*
if [ -d "$install_path" ]; then
echo "Directory $install_path already exists."
else
mkdir -p "$install_path"
fi
wget "$urls/$source_package"
wget "$urls/$source_zip"
if [ $? -ne 0 ]; then
echo "Failed to download source package."
exit 1
@ -113,8 +126,13 @@ download_source() {
exit 1
fi
mv -fn "$install_path/$source_unzip/*" "$install_path"
rm -rf "$source_package" "$install_path/$source_unzip"
mv -fn $install_path/$source_unzip/* "$install_path"
if [ $? -ne 0 ]; then
echo "Move directory failed"
exit 1
fi
rm -rf "$source_zip" "$install_path/$source_unzip"
}
@ -132,7 +150,7 @@ check_ports() {
echo "All ports are available"
}
install_compose() {
install_backends() {
echo "Install backend docker services"
cd "$install_path/docker"
if [ $? -ne 0 ]; then
@ -151,7 +169,8 @@ install_compose() {
fi
fi
sudo docker-compose -p websoft9 up -d
sudo docker compose -p websoft9 pull
sudo docker compose -p websoft9 up -d
if [ $? -ne 0 ]; then
echo "Failed to start docker services."
exit 1
@ -195,10 +214,10 @@ check_ports $http_port $https_port $cockpit_port
install_tools
download_source
bash install_docker.sh
bash install_cockpit.sh
bash install_plugins.sh
bash $install_path/install/install_docker.sh
bash $install_path/install/install_cockpit.sh
bash $install_path/install/install_plugins.sh
install_compose
install_backends
install_systemd
echo "-- Install success! Access Websoft9 console by: http://Internet IP:9000 and using Linux user for login ------"
echo "-- Install success! Access Websoft9 console by: http://Internet IP:$cockpit_port and using Linux user for login ------"

View file

@ -116,13 +116,6 @@ sudo docker restart websoft9-nginxproxymanager
sudo docker cp websoft9-appmanage:/usr/src/app/db/database.sqlite /usr
}
EditMenu(){
echo "Start to Edit Cockpit Menu ..."
# uninstall plugins
rm -rf /usr/share/cockpit/apps /usr/share/cockpit/selinux /usr/share/cockpit/kdump /usr/share/cockpit/sosreport /usr/share/cockpit/packagekit
cp -r /data/apps/websoft9/cockpit/menu_override/* /etc/cockpit
}
InstallPlugins

View file

@ -16,6 +16,7 @@
},
"OS_SUPPORT": {
"Fedora": [
"38",
"37"
],
"RedHat": [