#!/bin/bash
if [ $# -ne 1 ]; then
    echo "Usage: $0 <file_path>"
    exit 1
fi


current_develop(){
ostree_status=$(ostree admin status | grep '\*')
if [ $? -eq 0 ]; then
    echo "获取到当前的部署"
else
    echo "无法获取当前的部署"
    exit 1
fi
deploy_name=$(echo "$ostree_status" | awk '{print $2}')
if [ $? -eq 0 ]; then
    echo "获取到当前的部署名称$deploy_name"
else
    echo "无法获取当前的部署名称"
    exit 1
    
fi
deploy_commit=$(echo "$ostree_status" | awk '{print $3}')
if [ $? -eq 0 ]; then
    echo "获取到当前的部署commit$deploy_commit"
    commit=$(echo "$deploy_commit" | cut -d '.' -f 1)
    echo $commit
    boot_path="/sysroot/ostree/deploy/openkylin/deploy/${deploy_commit}/boot/"
    if [ "$1" == "in" ];then
	    if [ "$(ls -A $boot_path)" ]; then
            echo "目录不为空"
        else
            echo "目录为空"
            cp -rf /boot/* $boot_path
        fi
    else
	    if [ "$(ls -A $boot_path)" ]; then
            echo "目录不为空"
            cp -rf $boot_path* /boot/
            if [ $? -eq 0 ]; then
                echo "boot目录拷贝成功"
                rm -rf $boot_path*
                if [ $? -ne 0 ]; then
                    echo "删除成功"
                fi
            fi
        else
            echo "目录为空"
        fi
    fi
else
    echo "无法获取当前的部署commit"
    exit 1
fi
}
mode=$1
current_develop $mode
# if [ -e "$file_path" ]; then
#     echo "File exists, performing checkout..."
#     # 在这里执行checkout动作，例如：
#     # git checkout $file_path
#     current_develop $file_path
# else
#     echo "File does not exist."
# fi


