Ejemplo n.º 1
0
Archivo: main.go Proyecto: jsli/gtbox
func testCopyFile() {
	src := "/home/manson/temp/test/tmp/radio.img"
	dest := "/home/manson/temp/test/tmp/cp_radio.img"
	//	dest := "/home/manson/temp/test/tmp/sss/"
	//	dest := "/home/manson/temp/test/tmp/sss/cp.img"
	//	dest := "/home/manson/temp/test/tmp/sss/cp/"
	//	dest := "/home/manson/temp/test/tmp/sss/cp/cp.img"
	_, err := file.CopyFile(src, dest)
	checkErr(err, "file.CopyFile")
}
Ejemplo n.º 2
0
func GenerateOtaPackage(dal *models.Dal, task *models.ReleaseCreationTask, root_path string) (*models.RadioOtaRelease, error) {
	//0.parse request from json string which stored in DB.
	update_request, err := ParseRequest(task.UpdateRequest)
	if err != nil {
		return nil, err
	}
	update_request.Cps = SortCps(update_request)

	//1.create all paths
	zip_path := fmt.Sprintf("%s%s", root_path, ota_constant.ZIP_DIR_NAME)
	pathutil.MkDir(zip_path)
	template_path := ota_constant.MODEL_TO_TEMPLATE[update_request.Device.Model]
	update_pkg_path := fmt.Sprintf("%s%s", root_path, ota_constant.UPDATE_PKG_NAME)
	radio_ota_path := fmt.Sprintf("%s%s", root_path, ota_constant.RADIO_OTA_PACKAGE_NAME)
	radio_dtim_path := fmt.Sprintf("%s%s", root_path, ota_constant.RADIO_DTIM_NAME)
	radio_image_path := fmt.Sprintf("%s%s", root_path, ota_constant.RADIO_IMAGE_NAME)

	//2.copy template files
	err = file.CopyDir(template_path, zip_path)
	if err != nil {
		return nil, err
	}

	//3.create Radio.dtim, Radio.img
	err = file.WriteBytes2File(task.Data, radio_dtim_path)
	if err != nil {
		return nil, err
	}

	image_list_final := make([]string, 0, 5)
	image_list := GenerateImageList(update_request)
	for _, image_rel_path := range image_list {
		dest_path := root_path + image_rel_path
		_, err := file.CopyFile(ota_constant.CP_RELEASE_ROOT_FINAL+image_rel_path, dest_path)
		if err != nil {
			return nil, err
		}
		image_list_final = append(image_list_final, dest_path)
	}

	err = gzipCpImage(image_list_final)
	if err != nil {
		revel.INFO.Printf("zip image error : %s\n", err)
		return nil, err
	}
	for _, image_path := range image_list_final {
		file.CopyFile(image_path+".gz", image_path)
	}

	err = generateRadioImage(radio_dtim_path, radio_image_path, image_list_final)
	if err != nil {
		return nil, err
	}
	_, err = file.CopyFile(radio_image_path, fmt.Sprintf("%s%s", zip_path, ota_constant.RADIO_IMAGE_NAME))

	//	4. archive all files
	err = archive.ArchiveZipFile(zip_path, update_pkg_path)
	if err != nil {
		return nil, err
	}

	//5.generate update.zip (updatetool + update_pkg.zip)
	params := make([]string, 5)
	params[0] = ota_constant.OTA_CMD_PARAM_PLATFORM_PREFIX + update_request.Device.Platform
	params[1] = ota_constant.OTA_CMD_PARAM_PRODUCT_PREFIX + update_request.Device.Model
	params[2] = ota_constant.OTA_CMD_PARAM_OEM_PREFIX
	params[3] = ota_constant.OTA_CMD_PARAM_OUTPUT_PREFIX + radio_ota_path
	params[4] = ota_constant.OTA_CMD_PARAM_INPUT_PREFIX + update_pkg_path
	err = generateOtaPackage(params)
	if err != nil {
		return nil, err
	}

	//6.insert db
	release := &models.RadioOtaRelease{}
	release.Flag = ota_constant.FLAG_AVAILABLE
	release.FingerPrint = task.FingerPrint
	release.ReleaseNote = "empty"
	release.CreatedTs = time.Now().Unix()
	release.ModifiedTs = release.CreatedTs
	release.Model = update_request.Device.Model
	release.Platform = update_request.Device.Platform
	release.Md5, err = file.Md5SumFile(radio_ota_path)
	release.Versions = GenerateOtaPackageVersions(update_request)
	release.Images = strings.Join(image_list, " ")
	if err != nil {
		return nil, err
	}
	release.Size, err = file.GetFileSize(radio_ota_path)
	if err != nil {
		return nil, err
	}

	release.Delete(dal)
	file.DeleteDir(fmt.Sprintf("%s%s", ota_constant.RADIO_OTA_RELEASE_ROOT, release.FingerPrint))
	id, err := release.Save(dal)
	if id < 0 || err != nil {
		return nil, err
	}
	release.Id = id

	//	7.copy final file to public directory, checksum
	final_dir := fmt.Sprintf("%s%s/", ota_constant.RADIO_OTA_RELEASE_ROOT, release.FingerPrint)
	pathutil.MkDir(final_dir)
	final_path := fmt.Sprintf("%s%s", final_dir, ota_constant.RADIO_OTA_PACKAGE_NAME)
	checksum_path := fmt.Sprintf("%s%s", final_dir, ota_constant.CHECKSUM_TXT_NAME)
	_, err = file.CopyFile(radio_ota_path, final_path)
	if err != nil {
		return nil, err
	}
	RecordMd5(final_path, checksum_path)

	return release, nil
}