
sudo systemctl stop cockpit.socket

THEMES_REPO="https://ckp.tyleo.dev/themes/"
THEME=$1
TITLE=$2

THEME_URI=$THEMES_REPO$THEME
LOCAL_THEME="/usr/share/custom/cockpit-branding/custom"
LOCAL_STORE="/usr/share/custom/cockpit-branding"

SCRIPT_SOURCE="https://ckp.tyleo.dev/script/res/bin/"
INSTALL_SOURCE="https://ckp.tyleo.dev/script/install.sh"
BRANDING_SOURCE="https://ckp.tyleo.dev/script/res/style/branding.css"

sudo rm -rfv /usr/share/cockpit/branding/*
sudo rm -rfv $LOCAL_THEME
sudo mkdir -p -v $LOCAL_THEME

sudo wget "$THEME_URI/apple-touch-icon.png" -O "$LOCAL_THEME/apple-touch-icon.png"
sudo wget "$THEME_URI/back.png" -O "$LOCAL_THEME/back.png"
sudo wget "$THEME_URI/bg-plain.png" -O "$LOCAL_THEME/bg-plain.png"
sudo wget "$THEME_URI/brand-large.png" -O "$LOCAL_THEME/brand-large.png"
sudo wget "$THEME_URI/branding.css" -O "$LOCAL_THEME/branding.css"
sudo wget "$THEME_URI/favicon.ico" -O "$LOCAL_THEME/favicon.ico"
sudo wget "$THEME_URI/logo.png" -O "$LOCAL_THEME/logo.png"
sudo wget "$BRANDING_SOURCE" -O $LOCAL_STORE/branding_model.css

sudo wget "$SCRIPT_SOURCE/cockpit-custom-background-setup-by-code" -O /usr/bin/cockpit-custom-background-setup-by-code
sudo wget "$SCRIPT_SOURCE/cockpit-custom-background-setup-from-url" -O /usr/bin/cockpit-custom-background-setup-from-url
sudo wget "$SCRIPT_SOURCE/cockpit-custom-background-setup-from-file" -O /usr/bin/cockpit-custom-background-setup-from-file
sudo wget "$SCRIPT_SOURCE/cockpit-custom-refresh" -O /usr/bin/cockpit-custom-refresh
sudo wget "$SCRIPT_SOURCE/cockpit-custom-edit" -O /usr/bin/cockpit-custom-edit
sudo wget "$SCRIPT_SOURCE/cockpit-custom-random-color" -O /usr/bin/cockpit-custom-random-color
sudo wget "$INSTALL_SOURCE" -O /usr/bin/cockpit-custom-reinstall

sudo chmod +x -v /usr/bin/cockpit-custom-*

sudo rm -rfv /usr/share/cockpit/branding/{default,arch,debian,fedora,opensuse,centos,scientific,rhel,ubuntu}
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/default
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/arch
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/debian
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/fedora
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/opensuse
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/rhel
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/centos
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/default
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/ubuntu
sudo cp -rfv /usr/share/custom/cockpit-branding/custom /usr/share/cockpit/branding/scientific
sudo chmod 755 -Rv /usr/share/cockpit/branding/

sudo systemctl start cockpit.socket