Get CPU arch

This commit is contained in:
Aoran Zeng 2024-06-21 10:55:43 +08:00
parent 984aa6b323
commit fcb74cb2ef
2 changed files with 39 additions and 8 deletions

View File

@ -7,7 +7,7 @@
* Contributors : Null Nil <null@nil.com> * Contributors : Null Nil <null@nil.com>
* | * |
* Created on : <2023-08-29> * Created on : <2023-08-29>
* Last modified : <2024-06-14> * Last modified : <2024-06-21>
* *
* chsrc * chsrc
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
@ -710,6 +710,37 @@ chsrc_backup (const char *path)
} }
static char *
chsrc_get_cpuarch ()
{
char *ret;
bool exist;
if (xy_on_windows)
{
xy_unimplement;
}
exist = chsrc_check_program ("arch");
if (exist)
{
ret = xy_run ("arch", 0, NULL);
return ret;
}
exist = chsrc_check_program ("uname");
if (exist)
{
ret = xy_run ("uname -p", 0, NULL);
return ret;
}
else
{
chsrc_error ("无法检测到CPU类型");
exit (Exit_UserCause);
}
}
/* Target Info */ /* Target Info */
typedef struct TargetInfo_t { typedef struct TargetInfo_t {

View File

@ -14,7 +14,7 @@
* chsrc: Change Source * chsrc: Change Source
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
#define Chsrc_Version "v0.1.7.pre5-2024/06/21" #define Chsrc_Version "v0.1.7.rc1-2024/06/21"
#define Chsrc_Maintain_URL "https://gitee.com/RubyMetric/chsrc" #define Chsrc_Maintain_URL "https://gitee.com/RubyMetric/chsrc"
#include "chsrc.h" #include "chsrc.h"
@ -940,7 +940,7 @@ os_ubuntu_setsrc_for_deb822 (char *option)
chsrc_backup (ETC_APT_DEB822_Ubuntu_Sources); chsrc_backup (ETC_APT_DEB822_Ubuntu_Sources);
char *arch = xy_run ("arch", 0, NULL); char *arch = chsrc_get_cpuarch ();
char *cmd = NULL; char *cmd = NULL;
if (strncmp (arch, "x86_64", 6)==0) if (strncmp (arch, "x86_64", 6)==0)
{ {
@ -983,9 +983,9 @@ os_ubuntu_setsrc (char *option)
chsrc_backup (ETC_APT_SOURCELIST); chsrc_backup (ETC_APT_SOURCELIST);
} }
char *arch = xy_run ("arch", 0, NULL); char *arch = chsrc_get_cpuarch ();
char *cmd = NULL; char *cmd = NULL;
if (strncmp (arch, "x86_64", 6)==0) if (0==strncmp (arch, "x86_64", 6))
{ {
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " ETC_APT_SOURCELIST); cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " ETC_APT_SOURCELIST);
} }
@ -1384,7 +1384,7 @@ os_arch_setsrc (char *option)
bool arch_flag = false; bool arch_flag = false;
char *new_file = NULL; char *new_file = NULL;
char *arch = xy_run ("arch", 0, NULL); char *arch = chsrc_get_cpuarch ();
if (strncmp(arch, "x86_64", 6)==0) if (strncmp(arch, "x86_64", 6)==0)
{ {
@ -1858,14 +1858,14 @@ os_netbsd_setsrc (char *option)
chsrc_backup ("/usr/pkg/etc/pkgin/repositories.conf"); chsrc_backup ("/usr/pkg/etc/pkgin/repositories.conf");
char *arch = xy_run("arch", 0, NULL); char *arch = chsrc_get_cpuarch ();
char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\""; char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\"";
char *version = xy_run (vercmd, 0, NULL); char *version = xy_run (vercmd, 0, NULL);
char *url = xy_strjoin (5, source.url, arch, "/", version, "/All"); char *url = xy_strjoin (5, source.url, arch, "/", version, "/All");
chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf"); chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf");
chsrc_say_lastly(&source, ChsrcTypeUntested); chsrc_say_lastly (&source, ChsrcTypeUntested);
} }