Split freebsd out

This commit is contained in:
Aoran Zeng 2024-08-16 01:26:33 +08:00
parent 5bfdcdc564
commit 645f073b9f
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
4 changed files with 135 additions and 127 deletions

View File

@ -338,22 +338,6 @@ os_armbian_sources[] = {
},
/**
* @time 2023-09-27
*
* @note by:ccmywish {
* [2023-09-24] USTC, NJU, Netease freebsd-pkg freebsd-ports
* [2023-09-27] Nju前面有至少一个镜像 freebsd
* }
*/
os_freebsd_sources[] = {
{&Upstream, NULL},
{&Ustc, "mirrors.ustc.edu.cn"},
{&Nju, "mirror.nju.edu.cn"},
{&Netease, "mirrors.163.com"},
},
/**
* @time 2023-09-06
@ -528,8 +512,6 @@ def_sources_n(os_rocky); def_sources_n(os_alma);
def_sources_n(os_linuxlite); def_sources_n(os_raspberrypi);
def_sources_n(os_armbian);
def_sources_n(os_freebsd);
def_sources_n(os_ros);
def_sources_n(os_deepin); def_sources_n(os_openeuler); def_sources_n(os_openkylin);

View File

@ -752,114 +752,7 @@ os_openkylin_setsrc (char *option)
}
/**
* :
* 1. https://book.bsdcn.org/di-3-zhang-ruan-jian-yuan-ji-bao-guan-li-qi/di-3.2-jie-freebsd-huan-yuan-fang-shi.html
* 2. https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
*
* @ykla,
* FreeBSD pkgportsportportsnapupdate portsnap FreeBSD 14
*/
void
os_freebsd_setsrc (char *option)
{
// 据 @yklaFreeBSD不自带sudo但是我们依然要保证是root权限
chsrc_ensure_root ();
int index = use_specific_mirror_or_auto_select (option, os_freebsd);
SourceInfo source = os_freebsd_sources[index];
chsrc_confirm_source (&source);
chsrc_log2 ("1. 添加 freebsd-pkg 源 (二进制安装包)");
chsrc_ensure_dir ("/usr/local/etc/pkg/repos");
char *conf = xy_strjoin (3, "/usr/local/etc/pkg/repos/", source.mirror->code, ".conf");
char *pkg_content = xy_strjoin (4,
source.mirror->code, ": { \n"
" url: \"http://", source.url, "/freebsd-pkg/${ABI}/latest\",\n"
"}\n"
"FreeBSD: { enabled: no }"
);
chsrc_overwrite_file (pkg_content, conf);
chsrc_note2 (
xy_strjoin (3, "若要使用季度分支,请在", conf ,"中将latest改为quarterly"));
chsrc_note2 ("若要使用HTTPS源请先安装securtiy/ca_root_ns并将'http'改成'https',最后使用'pkg update -f'刷新缓存即可\n");
puts ("");
chsrc_log2 ("2. 修改 freebsd-ports 源");
// @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git
// 但是我认为由于使用Git还是要比非Git方便许多我们尽可能坚持使用Git
// 而 gitup 又要额外修改它自己的配置,比较麻烦
bool git_exist = query_program_exist (xy_str_to_quietcmd ("git version"), "git");
if (git_exist)
{
if (xy_streql("nju",source.mirror->code))
{
source = os_freebsd_sources[index-1]; // 使用NJU的前一个源即USTC源
}
char *git_cmd = xy_strjoin (3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports");
chsrc_run (git_cmd, RunOpt_Default);
source = os_freebsd_sources[index]; // 恢复至选中的源
chsrc_note2 ("下次更新请使用 git -C /usr/ports pull 而非使用 gitup");
}
else
{
char *fetch = xy_strjoin (3, "fetch https://", source.url, "/freebsd-ports/ports.tar.gz"); // 70多MB
char *unzip = "tar -zxvf ports.tar.gz -C /usr/ports";
char *delete = "rm ports.tar.gz";
chsrc_run (fetch, RunOpt_Default);
chsrc_run (unzip, RunOpt_Default);
chsrc_run (delete, RunOpt_Default);
chsrc_log2 ("下次更新请重新下载内容至 /usr/ports");
}
chsrc_log2 ("3. 指定 port 源");
// https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
chsrc_backup ("/etc/make.conf");
char *ports = xy_strjoin (3, "MASTER_SITE_OVERRIDE?=http://", source.url, "/freebsd-ports/distfiles/${DIST_SUBDIR}/");
chsrc_append_to_file (ports, "/etc/make.conf");
/* 不再换 portsnap */
/*
chsrc_backup ("/etc/portsnap.conf");
char *portsnap =xy_strjoin(3,"s@(.*)SERVERNAME=[\\.|a-z|A-Z]*@\\1SERVERNAME=", source.url,
"@g < /etc/portsnap.conf.bak");
chsrc_overwrite_file (portsnap, "/etc/portsnap.conf");
chsrc_log2 ("portsnap sources changed");
chsrc_log2 ("获取portsnap更新使用此命令: 'portsnap fetch extract'");
*/
// HELP: 暂时没有源提供
chsrc_note2 ("4. 抱歉,目前境内无 freebsd-update 源若存在请报告issue谢谢");
/*
chsrc_log2 ("3. 修改 freebsd-update 源");
char *update_cp = "cp /etc/freebsd-update.conf /etc/freebsd-update.conf.bak";
chsrc_run (update_cp, RunOpt_Default);
char *update =xy_strjoin (3,"s@(.*)SERVERNAME [\\.|a-z|A-Z]*@\\1SERVERNAME ",
source.url,
"@g < /etc/freebsd-update.conf.bak");
chsrc_overwrite_file (update, "/etc/freebsd-update.conf");
*/
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
}
#include "recipe/os/freebsd.c"
#include "recipe/os/netbsd.c"
#include "recipe/os/openbsd.c"

View File

@ -47,7 +47,6 @@ def_target(os_armbian);
def_target_noget(os_fedora);
def_target_noget(os_rocky);
def_target_noget(os_alma);
def_target_noget(os_freebsd);
def_target_noget(os_openeuler);
def_target_noget(os_anolis);
def_target_noget(os_ros);

134
src/recipe/os/freebsd.c Normal file
View File

@ -0,0 +1,134 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* | Heng Guo <2085471348@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-03>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2023-09-27
*
* @note by:ccmywish {
* [2023-09-24] USTC, NJU, Netease freebsd-pkg freebsd-ports
* [2023-09-27] Nju前面有至少一个镜像 freebsd
* }
*/
static SourceInfo
os_freebsd_sources[] = {
{&Upstream, NULL},
{&Ustc, "mirrors.ustc.edu.cn"},
{&Nju, "mirror.nju.edu.cn"},
{&Netease, "mirrors.163.com"},
};
def_sources_n(os_freebsd);
/**
* :
* 1. https://book.bsdcn.org/di-3-zhang-ruan-jian-yuan-ji-bao-guan-li-qi/di-3.2-jie-freebsd-huan-yuan-fang-shi.html
* 2. https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
*
* @ykla,
* FreeBSD pkgportsportportsnapupdate portsnap FreeBSD 14
*/
void
os_freebsd_setsrc (char *option)
{
// 据 @yklaFreeBSD不自带sudo但是我们依然要保证是root权限
chsrc_ensure_root ();
int index = use_specific_mirror_or_auto_select (option, os_freebsd);
SourceInfo source = os_freebsd_sources[index];
chsrc_confirm_source (&source);
chsrc_log2 ("1. 添加 freebsd-pkg 源 (二进制安装包)");
chsrc_ensure_dir ("/usr/local/etc/pkg/repos");
char *conf = xy_strjoin (3, "/usr/local/etc/pkg/repos/", source.mirror->code, ".conf");
char *pkg_content = xy_strjoin (4,
source.mirror->code, ": { \n"
" url: \"http://", source.url, "/freebsd-pkg/${ABI}/latest\",\n"
"}\n"
"FreeBSD: { enabled: no }"
);
chsrc_overwrite_file (pkg_content, conf);
chsrc_note2 (
xy_strjoin (3, "若要使用季度分支,请在", conf ,"中将latest改为quarterly"));
chsrc_note2 ("若要使用HTTPS源请先安装securtiy/ca_root_ns并将'http'改成'https',最后使用'pkg update -f'刷新缓存即可\n");
puts ("");
chsrc_log2 ("2. 修改 freebsd-ports 源");
// @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git
// 但是我认为由于使用Git还是要比非Git方便许多我们尽可能坚持使用Git
// 而 gitup 又要额外修改它自己的配置,比较麻烦
bool git_exist = query_program_exist (xy_str_to_quietcmd ("git version"), "git");
if (git_exist)
{
if (xy_streql("nju",source.mirror->code))
{
source = os_freebsd_sources[index-1]; // 使用NJU的前一个源即USTC源
}
char *git_cmd = xy_strjoin (3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports");
chsrc_run (git_cmd, RunOpt_Default);
source = os_freebsd_sources[index]; // 恢复至选中的源
chsrc_note2 ("下次更新请使用 git -C /usr/ports pull 而非使用 gitup");
}
else
{
char *fetch = xy_strjoin (3, "fetch https://", source.url, "/freebsd-ports/ports.tar.gz"); // 70多MB
char *unzip = "tar -zxvf ports.tar.gz -C /usr/ports";
char *delete = "rm ports.tar.gz";
chsrc_run (fetch, RunOpt_Default);
chsrc_run (unzip, RunOpt_Default);
chsrc_run (delete, RunOpt_Default);
chsrc_log2 ("下次更新请重新下载内容至 /usr/ports");
}
chsrc_log2 ("3. 指定 port 源");
// https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
chsrc_backup ("/etc/make.conf");
char *ports = xy_strjoin (3, "MASTER_SITE_OVERRIDE?=http://", source.url, "/freebsd-ports/distfiles/${DIST_SUBDIR}/");
chsrc_append_to_file (ports, "/etc/make.conf");
/* 不再换 portsnap */
/*
chsrc_backup ("/etc/portsnap.conf");
char *portsnap =xy_strjoin(3,"s@(.*)SERVERNAME=[\\.|a-z|A-Z]*@\\1SERVERNAME=", source.url,
"@g < /etc/portsnap.conf.bak");
chsrc_overwrite_file (portsnap, "/etc/portsnap.conf");
chsrc_log2 ("portsnap sources changed");
chsrc_log2 ("获取portsnap更新使用此命令: 'portsnap fetch extract'");
*/
// HELP: 暂时没有源提供
chsrc_note2 ("4. 抱歉,目前境内无 freebsd-update 源若存在请报告issue谢谢");
/*
chsrc_log2 ("3. 修改 freebsd-update 源");
char *update_cp = "cp /etc/freebsd-update.conf /etc/freebsd-update.conf.bak";
chsrc_run (update_cp, RunOpt_Default);
char *update =xy_strjoin (3,"s@(.*)SERVERNAME [\\.|a-z|A-Z]*@\\1SERVERNAME ",
source.url,
"@g < /etc/freebsd-update.conf.bak");
chsrc_overwrite_file (update, "/etc/freebsd-update.conf");
*/
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
}
def_target_noget(os_freebsd);