input_file="/etc/.kylin-osinfo"

etc_path_ln="/etc"
usr_share_ln="/usr/share"
bin_ln_V11="/opt/system/bin"
bin_ln_not_V11="/usr/bin"

etc_path="/opt/system/conf"
usr_share="/opt/system/resource"
bin_path="/opt/kaiming-tools/bin"

is_V11=0

if [ -e "$input_file" ]; then
    # 逐行读取输入文件
    while read -r line; do
        # 检查当前行是否包含特定字段
        if echo "$line" | grep -q "$specific_field"; then
            if echo "$line" | grep -q "V11"; then
                is_V11=1
            fi
        fi
    done < "$input_file"
fi

if [ $is_V11 -eq 0 ]; then

    if [ ! -e "${etc_path_ln}/bash_completion.d/kaiming-builder_completion.sh" ]; then
        if [ ! -d "${etc_path_ln}/bash_completion.d" ]; then
            mkdir -p "${etc_path_ln}/bash_completion.d"
        fi
        ln -s "${etc_path}/bash_completion.d/kaiming-builder_completion.sh" "${etc_path_ln}/bash_completion.d/kaiming-builder_completion.sh" 
    fi

    if [ ! -e "${usr_share_ln}/locale/zh_CN/LC_MESSAGES/kaiming-builder.mo" ]; then
        if [ ! -d "${usr_share_ln}/locale/zh_CN/LC_MESSAGES" ]; then
            mkdir -p "${usr_share_ln}/locale/zh_CN/LC_MESSAGES"
        fi
        ln -s "${usr_share}/locale/zh_CN/LC_MESSAGES/kaiming-builder.mo" "${usr_share_ln}/locale/zh_CN/LC_MESSAGES/kaiming-builder.mo"
    fi

    if [ ! -e "${bin_ln_not_V11}/kaiming-builder" ]; then
        ln -s "${bin_path}/kaiming-builder" "${bin_ln_not_V11}/kaiming-builder"
    fi
else
    if [ ! -e "${bin_ln_V11}/kaiming-builder" ]; then
        if [ ! -d "${bin_ln_V11}" ]; then
            mkdir -p "${bin_ln_V11}"
        fi
        ln -s "${bin_path}/kaiming-builder" "${bin_ln_V11}/kaiming-builder"
    fi
fi