#!/bin/bash

copy_file() {
    source_path=$1
    target_path=$2
    # 检查源文件或目录是否存在
    if [ ! -e "$source_path" ]; then
        echo "$source_path not exist, no copy file."
        return
    fi
    # 分离目标路径的目录部分
    target_dir=$(dirname "$target_path")
    
    # 检查目标目录是否存在，如果不存在则创建
    if [ ! -d "$target_dir" ]; then
        mkdir -p "$target_dir"
        echo "$target_dir not exist, have created the directory."
    fi
    
    # 执行mv操作
    cp -r $source_path $target_path
    echo $source_path copy to $target_path
}

# 生成initrd
update_initrd() {
    VKERNEL=$(uname -r)
    # Array of available initrd creation commands
    commands="update-initramfs dracut mkinitrd"

    for cmd in $commands; do
        if [ -n "$cmd" ] && command -v "$cmd" >/dev/null 2>&1; then
            case "$cmd" in
                update-initramfs)
                    "$cmd" -u -k "$VKERNEL"
                    ;;
                dracut)
                    "$cmd" -f "/boot/initrd.img-$VKERNEL" "$VKERNEL"
                    ;;
                *)
                    # For any other initrd tool
                    "$cmd" -f "/boot/initrd.img-$VKERNEL" "$VKERNEL"
                    ;;
            esac
            return
        fi
    done

    # If none of the commands are found, print a message
    echo "No suitable initrd creation command found. Initrd not updated."
}

# 当前用户
curuser=$(who | awk '{print $1}')
echo "当前用户名：$curuser"
# 切换GTK主题
su -c 'gsettings set org.cartoon.interface gtk-theme "Cartoons"' $curuser
# 切换ICON主题
su -c 'gsettings set org.cartoon.interface icon-theme "Flat-Remix-Blue"' $curuser
# 切换marco主题
su -c 'gsettings set org.cartoon.Marco.general theme "Cartoons"' $curuser

# 切换cartoon-panel样式
su -c 'gsettings set org.cartoon.panel default-layout "default"' $curuser
su -c 'cartoon-panel --reset' $curuser

export PATH=$PATH:/sbin

# 修改默认主题使其生效
glib-compile-schemas /usr/share/glib-2.0/schemas/

# 切换plymouth主题
plymouth-set-default-theme loongnix
# Array of available initrd creation commands
update_initrd
