/**
 * 
 */
package org.springblade.core.license.system;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.springblade.core.license.IServerInfo;

import cn.hutool.core.util.StrUtil;

/**
 * @author wookvn
 *
 */
public class MacServerInfo implements IServerInfo {

	@Override
	public String getCPUSerial() throws Exception {
		//序列号
        String serialNumber = "000";
        //获取Hardware UUID作为CPU序列号使用
        String[] shell = {"/bin/bash","-c","system_profiler SPHardwareDataType | fgrep 'UUID' | awk '{print $NF}'"};
        Process process = Runtime.getRuntime().exec(shell);
        process.getOutputStream().close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = reader.readLine().trim();
        if(StrUtil.isNotBlank(line)){
            serialNumber = line;
        }
        reader.close();
        return serialNumber;
	}

	@Override
	public String getMainBoardSerial() throws Exception {
		//序列号
        String serialNumber = "111";
        //使用system_profiler命令获取Serial Number (system)作为主板序列号
        String[] shell = {"/bin/bash","-c","system_profiler SPHardwareDataType | fgrep 'Serial' | awk '{print $NF}'"};
        Process process = Runtime.getRuntime().exec(shell);
        process.getOutputStream().close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = reader.readLine().trim();
        if(StrUtil.isNotBlank(line)){
            serialNumber = line;
        }
        reader.close();
        return serialNumber;
	}
}
