/**
 * 
 */
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 LinuxServerInfo implements IServerInfo {

	@Override
	public String getCPUSerial() throws Exception {
		//序列号
        String serialNumber = "000";
        //使用dmidecode命令获取CPU序列号
        String[] shell = {"/bin/bash","-c","dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"};
        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";
        //使用dmidecode命令获取主板序列号
        String[] shell = {"/bin/bash","-c","dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"};
        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;
	}

}
