
# 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"

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

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

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

chmod +x -v /usr/bin/cockpit-custom-background-setup-by-code
chmod +x -v /usr/bin/cockpit-custom-background-setup-from-url
chmod +x -v /usr/bin/cockpit-custom-background-setup-from-file
chmod +x -v /usr/bin/cockpit-custom-edit
chmod +x -v /usr/bin/cockpit-custom-refresh
chmod +x -v /usr/bin/cockpit-custom-reinstall

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

# systemctl start cockpit.socket