Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1105443
  • 博文数量: 121
  • 博客积分: 8910
  • 博客等级: 上将
  • 技术积分: 2915
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-18 09:36
文章分类

全部博文(121)

文章存档

2011年(3)

2010年(100)

2008年(18)

分类:

2010-03-15 16:11:32

启动远程下载安装packages的命令:

            pkg_add -r  软件包名

pkg_add -r 首先会查询 PACKAGESITE 环境变量,若无,接着查找 PACKAGEROOT 环境变量,若无,程序内部根据uname的结果组装对应版本的默认的远程下载路径,最后添加 /Latest/

程序片段:usr.sbin/pkg_install/add/main.c

static char * getpackagesite(void)
{
    int reldate, i;
    static char sitepath[MAXPATHLEN];
    struct utsname u;

    if (getenv("PACKAGESITE")) {
    if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath))
        >= sizeof(sitepath))
        return NULL;
    return sitepath;
    }

    if (getenv("PACKAGEROOT")) {
    if (strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath))
        >= sizeof(sitepath))
        return NULL;
    } else {
    if (strlcat(sitepath, "ftp://ftp.freebsd.org", sizeof(sitepath))
        >= sizeof(sitepath))
        return NULL;
    }

    if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))
    >= sizeof(sitepath))
    return NULL;

    uname(&u);
    if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath))
    return NULL;

    reldate = getosreldate();
    for(i = 0; releases[i].directory != NULL; i++) {
    if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) {
        if (strlcat(sitepath, releases[i].directory, sizeof(sitepath))
        >= sizeof(sitepath))
        return NULL;
        break;
    }
    }

    if (strlcat(sitepath, "/Latest/", sizeof(sitepath)) >= sizeof(sitepath))
    return NULL;

    return sitepath;

}

阅读(2817) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~