#!/bin/bash
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
    directory_path_etc="/sysroot/ostree/pkgs/ovl-${deploy_name}/etc-ovl/etc-tmpupper"
    directory_path_var="/sysroot/ostree/pkgs/ovl-${deploy_name}/var-ovl/var-tmpupper"
    # 指定要将修改后的路径保存到的文件
    output_file_etc="/etc/ostree/ost-ex.d/ostree-maintian-keep-etc"

    # 检查目录是否存在
    if [ -d "$directory_path_etc" ]; then
    # 检查目录是否为空
        if [ "$(ls -A $directory_path_etc)" ]; then
            echo "Directory is not empty: $directory_path"
            # 如果目录不为空，将路径写入到文件中
            echo $directory_path_etc >> $output_file_etc
            else
            echo "Directory is empty: $directory_path_etc"
        fi
    else
        echo "Directory does not exist: $directory_path_etc"
    fi
     # 检查目录是否存在
    if [ -d "$directory_path_var" ]; then
    # 检查目录是否为空
        if [ "$(ls -A $directory_path_var)" ]; then
            echo "Directory is not empty: $directory_path_var"
            # 如果目录不为空，将路径写入到文件中
            echo $directory_path_var >> $output_file_var
            else
            echo "Directory is empty: $directory_path_var"
        fi
    else
        echo "Directory does not exist: $directory_path_var"
    fi
else
    echo "无法获取当前的部署commit"
    exit 1
fi
}

current_develop