コード例 #1
0
ファイル: afptool.c プロジェクト: wendal/rk2918_tools
int pack_update(const char* srcdir, const char* dstfile) {
    struct update_header header;
    FILE *fp;
    int i;
    char buf[PATH_MAX];

    printf("------ PACKAGE ------\n");
    memset(&header, 0, sizeof(header));

    snprintf(buf, sizeof(buf), "%s/%s", srcdir, "parameter");
    if (parse_parameter(buf))
        return -1;

    snprintf(buf, sizeof(buf), "%s/%s", srcdir, "package-file");
    if (get_packages(buf))
        return -1;

    fp = fopen(dstfile, "w");
    if (!fp)
        return -1;

    fwrite(&header, sizeof(header), 1, fp);

    for (i = 0; i < package_image.num_package; ++i) {
        strcpy(header.parts[i].name, package_image.packages[i].name);
        strcpy(header.parts[i].filename, package_image.packages[i].filename);
        header.parts[i].nand_addr = package_image.packages[i].nand_addr;
        header.parts[i].nand_size = package_image.packages[i].nand_size;

        if (strcmp(package_image.packages[i].filename, "SELF") == 0)
            continue;

        snprintf(buf, sizeof(buf), "%s/%s", srcdir, header.parts[i].filename);
        printf("Add file: %s\n", buf);
        import_package(fp, &header.parts[i], buf);
    }

    strcpy(header.magic, "RKAF");
    strcpy(header.manufacturer, package_image.manufacturer);
    strcpy(header.model, package_image.machine_model);
    strcpy(header.id, package_image.machine_id);
    header.length = ftell(fp);
    header.num_parts = package_image.num_package;
    header.version = package_image.version;

    for (i = header.num_parts - 1; i >= 0; --i)
    {
        if (strcmp(header.parts[i].filename, "SELF") == 0)
        {
            header.parts[i].size = header.length + 4;
            header.parts[i].padded_size = (header.parts[i].size + 511) / 512 *512;
        }
    }

    fseek(fp, 0, SEEK_SET);
    fwrite(&header, sizeof(header), 1, fp);
    fclose(fp);

    append_crc(dstfile);

    printf("------ OK ------\n");

    return 0;
}
コード例 #2
0
ファイル: usepackage.c プロジェクト: rpavlik/usepackage
int main(int argc, char *argv[])
{
   int first,i;
   char* f;
   group_t* group;
   int sh_override = -1;
   int list_packages = 0;

   for (i=1; i<argc && *argv[i] == '-'; i++)
   {
      for (f=argv[i]+1; *f; f++)
         switch (*f)
         {
            case 'v':
               debugging = 1;
               silent = 0;
               break;
            case 's':
               debugging = 0;
               silent = 1;
               break;
            case 'c':
               sh_override = 1;
               break;
            case 'b':
               sh_override = 0;
               break;
            case 'f':
               main_package_filename = argv[++i];
               break;
            case 'l':
               list_packages = 1;
               break;
            default:
               fprintf(stderr, "usepackage: unrecognised flag '%c'\n", *f);
               exit(1);
         }
   }

   if (!list_packages && (i >= argc))
   {
      fprintf(stderr, "\n%s %s, %s\n", PACKAGE_NAME, PACKAGE_VERSION, COPYRIGHT);
      fprintf(stderr, "Bug reports and comments to: %s\n", PACKAGE_BUGREPORT);
      fprintf(stderr, "Discussion/announcement list: %s\n\n", MAILING_LIST);
      fprintf(stderr, "usage: use [-vs] [-f <file>] <package> [<package>...]\n");
      fprintf(stderr, "       use -l\n\n");
      fprintf(stderr, "       -v : verbose\n");
      fprintf(stderr, "       -s : silence match warnings\n");
      fprintf(stderr, "       -f : use <file> as main packages file\n");
      fprintf(stderr, "       -l : list available packages\n\n");
      exit(1);
   }

   DEBUG(stderr, "%s\n", PACKAGE_NAME);
   DEBUG(stderr, "Version: %s\n", PACKAGE_VERSION);
   DEBUG(stderr, "%s\n", COPYRIGHT);

   uname(&the_host_info);
   DEBUG(stderr, "host: %s\n", the_host_info.nodename);
   DEBUG(stderr, "operating system: %s %s\n", the_host_info.sysname,
         the_host_info.release);
   DEBUG(stderr, "architecture: %s\n", the_host_info.machine);

   the_shell = get_user_shell();
   DEBUG(stderr, "shell: %s\n", the_shell);

   if (sh_override != -1)
      csh_user = sh_override;
   else
      csh_user = ((!strcmp(the_shell, "csh")) || (!strcmp(the_shell, "tcsh")));

   the_environment = new_list();
   the_scripts = new_list();
   
   if (get_packages(&the_packages, &the_groups, &the_annotations))
   {
      fprintf(stderr, "usepackage: couldn't load package information.\n");
      exit(2);
   }

   if (list_packages)
   {
      fprintf(stderr, "\nusepackage %s, %s\n\n", VERSION, COPYRIGHT);
      fprintf(stderr, "Available packages are:\n\n");
      list_annotations();
      fprintf(stderr, "\nAvailable groups are:\n\n");
      list_groups();
      fprintf(stderr, "\n");
      exit(0);
   }

   for (first = i, i = argc - 1 ; i >= first ; i--)
   {
      if (group = get_group(argv[i]))
         use_group(group);
      else
         use_package(argv[i]);
   }

   print_env();

   print_scripts();

   return(0);
}
コード例 #3
0
int pack_update(const char* srcdir, const char* dstfile) {
	struct update_header header;
	FILE *fp = NULL;
	unsigned int i;

	printf("------ PACKAGE ------\n");
	memset(&header, 0, sizeof(header));

	fp = fopen(dstfile, "wb+");
	if (!fp) {
		printf("Can't open destination file \"%s\": %s\n", dstfile, strerror(errno));
		return -1;
	}

	if (chdir(srcdir))
		return -1;

	if (parse_parameter("parameter"))
		return -1;

	if (get_packages("package-file"))
		return -1;

	fwrite(&header, sizeof(header), 1, fp);

	for (i = 0; i < package_image.num_package; ++i) {
		strcpy(header.parts[i].name, package_image.packages[i].name);
		strcpy(header.parts[i].filename, package_image.packages[i].filename);
		header.parts[i].nand_addr = package_image.packages[i].nand_addr;
		header.parts[i].nand_size = package_image.packages[i].nand_size;

		if (strcmp(package_image.packages[i].filename, "SELF") == 0)
			continue;

		printf("Add file: %s\n", header.parts[i].filename);
		import_package(fp, &header.parts[i], header.parts[i].filename);
	}

	memcpy(header.magic, RKAFP_MAGIC, sizeof(header.magic));
	strcpy(header.manufacturer, package_image.manufacturer);
	strcpy(header.model, package_image.machine_model);
	strcpy(header.id, package_image.machine_id);
	header.length = ftell(fp);
	header.num_parts = package_image.num_package;
	header.version = package_image.version;

	for (i = 0; i < header.num_parts; i++)
	{
		if (strcmp(header.parts[i].filename, "SELF") == 0)
		{
			header.parts[i].size = header.length + 4;
			header.parts[i].padded_size = (header.parts[i].size + 511) / 512 *512;
		}
	}

	fseek(fp, 0, SEEK_SET);
	fwrite(&header, sizeof(header), 1, fp);

	append_crc(fp);

	fclose(fp);

	printf("------ OK ------\n");

	return 0;
}