Skip to content

Commit 3ad62cf

Browse files
committed
feat: add arch index support
1 parent e94b041 commit 3ad62cf

5 files changed

Lines changed: 65 additions & 6 deletions

File tree

vuru/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "utils.h"
99

1010
#define INDEX_URL "https://vup-linux.github.io/vup/index.json"
11-
#define VERSION "0.3.5"
11+
#define VERSION "0.3.7"
1212

1313
static void print_version(void) {
1414
printf("vuru %s\n", VERSION);

vuru/src/utils.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdlib.h>
44
#include <string.h>
55
#include <errno.h>
6+
#include <sys/utsname.h>
67
#include "utils.h"
78

89
#define COLOR_RESET "\033[0m"
@@ -91,3 +92,33 @@ int write_file(const char *path, const char *content) {
9192

9293
return 1;
9394
}
95+
96+
const char *get_arch(void) {
97+
static char arch[128] = {0};
98+
99+
if (arch[0] != '\0') {
100+
return arch;
101+
}
102+
103+
struct utsname info;
104+
if (uname(&info) != 0) {
105+
return NULL;
106+
}
107+
108+
// Map machine name to XBPS arch names
109+
if (strcmp(info.machine, "x86_64") == 0) {
110+
snprintf(arch, sizeof(arch), "x86_64");
111+
} else if (strcmp(info.machine, "aarch64") == 0) {
112+
snprintf(arch, sizeof(arch), "aarch64");
113+
} else if (strcmp(info.machine, "armv7l") == 0) {
114+
snprintf(arch, sizeof(arch), "armv7l");
115+
} else if (strcmp(info.machine, "i686") == 0 ||
116+
strcmp(info.machine, "i386") == 0) {
117+
snprintf(arch, sizeof(arch), "i686");
118+
} else {
119+
// Use machine name as-is for other architectures
120+
snprintf(arch, sizeof(arch), "%s", info.machine);
121+
}
122+
123+
return arch;
124+
}

vuru/src/utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ char *read_file(const char *path);
3030
*/
3131
int write_file(const char *path, const char *content);
3232

33+
/**
34+
* Get the current system architecture name.
35+
* @return Static string with architecture (e.g., "x86_64", "aarch64"), or NULL on failure
36+
*/
37+
const char *get_arch(void);
38+
3339
#endif /* UTILS_H */

vuru/src/xbps/install.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,28 @@ int xbps_install_pkg(Index *idx, const char *pkg_name, int yes) {
5656
}
5757

5858
cJSON *cat = cJSON_GetObjectItem(pkg, "category");
59-
cJSON *url = cJSON_GetObjectItem(pkg, "repo_url");
59+
cJSON *repo_urls = cJSON_GetObjectItem(pkg, "repo_urls");
6060

6161
if (!cat || !cJSON_IsString(cat) || !cat->valuestring ||
62-
!url || !cJSON_IsString(url) || !url->valuestring) {
62+
!repo_urls || !cJSON_IsObject(repo_urls)) {
6363
log_error("Invalid package metadata for '%s'", pkg_name);
6464
return -1;
6565
}
66+
67+
// Get architecture-specific repo URL
68+
const char *arch = get_arch();
69+
if (!arch) {
70+
log_error("Failed to detect system architecture");
71+
return -1;
72+
}
73+
74+
cJSON *url = cJSON_GetObjectItem(repo_urls, arch);
75+
if (!url || !cJSON_IsString(url) || !url->valuestring) {
76+
log_error("Package '%s' is not available for architecture '%s'", pkg_name, arch);
77+
return -1;
78+
}
6679

67-
log_info("Found %s in category '%s'", pkg_name, cat->valuestring);
80+
log_info("Found %s in category '%s' for %s", pkg_name, cat->valuestring, arch);
6881

6982
// Fetch template for review
7083
log_info("Fetching template for review...");

vuru/src/xbps/upgrade.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,24 @@ int xbps_upgrade_all(Index *idx, int yes) {
278278
if (!info) continue;
279279

280280
cJSON *idx_ver = cJSON_GetObjectItem(info, "version");
281-
cJSON *repo_url = cJSON_GetObjectItem(info, "repo_url");
281+
cJSON *repo_urls = cJSON_GetObjectItem(info, "repo_urls");
282282
cJSON *category = cJSON_GetObjectItem(info, "category");
283283

284284
if (!idx_ver || !cJSON_IsString(idx_ver) || !idx_ver->valuestring ||
285-
!repo_url || !cJSON_IsString(repo_url) || !repo_url->valuestring ||
285+
!repo_urls || !cJSON_IsObject(repo_urls) ||
286286
!category || !cJSON_IsString(category) || !category->valuestring) {
287287
continue;
288288
}
289289

290+
// Get architecture-specific repo URL
291+
const char *arch = get_arch();
292+
if (!arch) continue;
293+
294+
cJSON *repo_url = cJSON_GetObjectItem(repo_urls, arch);
295+
if (!repo_url || !cJSON_IsString(repo_url) || !repo_url->valuestring) {
296+
continue; // Package not available for this architecture
297+
}
298+
290299
if (version_gt(idx_ver->valuestring, installed_ver)) {
291300
UpgradeInfo *u = &upgrades[upgrade_count];
292301
memset(u, 0, sizeof(*u));

0 commit comments

Comments
 (0)