#include <syslog.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <systemd/sd-bus.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
    syslog(LOG_INFO, "copy");
    FILE *file = fopen("/etc/restore.txt", "r");
    if (file == NULL)
    {
        printf("无法打开文件");
        return 1;
    }

    char line_etc[256];
    char *result_etc[100]; // 假设最多有100个结果
    int count = 0;
    syslog(LOG_INFO,"-----273");
    while (fgets(line_etc, sizeof(line_etc), file))
    {
        char *copy_data = strstr(line_etc, "COPY-ETC=");
        if (copy_data != NULL)
        {
            char *token = strtok(copy_data + strlen("COPY-ETC="), ";");
            while (token != NULL && count < 100)
            {
                result_etc[count] = token;
                count++;
                token = strtok(NULL, ";");
            }
        }
    }
    char line_var[256];
    char *result_var[100]; // 假设最多有100个结果
    syslog(LOG_INFO,"-----273");
    while (fgets(line_var, sizeof(line_var), file))
    {
        char *copy_data = strstr(line_var, "COPY-VAR");
        if (copy_data != NULL)
        {
            char *token = strtok(copy_data + strlen("COPY-VAR"), ";");
            while (token != NULL && count < 100)
            {
                result_var[count] = token;
                count++;
                token = strtok(NULL, ";");
            }
        }
    }
    fclose(file);
    // 输出结果
    for (int i = 0; i < count; i++)
    {
        syslog(LOG_INFO, "%s\n", result_etc[i]);
        char command[255] = {};
        // snprintf(command,sizeof(command),"%s %s %s %s", "/etc/ostree-extra-developer/developer.sh", value,config,log);
        snprintf(command, sizeof(command), "%s %s %s", "/usr/ost-ex.d/copy.sh", result_etc[i],result_var[i]);
        if (system(command) == 0)
        {
            syslog(LOG_INFO, "copy success");
        }
    }
    syslog(LOG_INFO, "------restort end-----");
    return 0;
}