tonarchy
tonarchy
https://git.tonybtw.com/tonarchy.git
git://git.tonybtw.com/tonarchy.git
Added nvme test mode to Makefile, fixed squashfs error.
Diff
diff --cc Makefile
index 73bdba3,73bdba3..4a9f484
--- a/Makefile
+++ b/Makefile
@@@ -8,7 -8,7 +8,7 @@@ SRC = src/tonarchy.
LATEST_ISO = $(shell ls -t out/*.iso 2>/dev/null | head -1)
TEST_DISK = test-disk.qcow2
--.PHONY: all clean install static build build-container test test-nix test-disk clean-iso clean-vm
++.PHONY: all clean install static build build-container test test-nix test-disk test-nvme clean-iso clean-vm
all: $(TARGET)
@@@ -65,6 -65,6 +65,39 @@@ test
-device virtio-net-pci,netdev=net0 \
-boot menu=on
++test-nvme:
++ @if [ -z "$(LATEST_ISO)" ]; then echo "No ISO found. Run 'make build' first"; exit 1; fi
++ @if [ ! -f "$(TEST_DISK)" ]; then \
++ echo "Creating test disk..."; \
++ qemu-img create -f qcow2 "$(TEST_DISK)" 20G; \
++ fi
++ @OVMF_CODE=$$(find /usr/share/edk2 /usr/share/OVMF -name "OVMF_CODE*.fd" 2>/dev/null | grep x64 | head -1); \
++ if [ -z "$$OVMF_CODE" ]; then \
++ echo "Error: OVMF not found. Install with: sudo pacman -S edk2-ovmf"; \
++ exit 1; \
++ fi; \
++ OVMF_VARS=$$(find /usr/share/edk2 /usr/share/OVMF -name "OVMF_VARS*.fd" 2>/dev/null | grep x64 | head -1); \
++ if [ ! -f ./OVMF_VARS.fd ]; then \
++ cp "$$OVMF_VARS" ./OVMF_VARS.fd; \
++ fi; \
++ echo "Starting UEFI VM with NVMe disk: $(LATEST_ISO)"; \
++ qemu-system-x86_64 \
++ -cpu host -enable-kvm -machine q35,accel=kvm \
++ -smp $$(nproc) \
++ -m 8192 \
++ -drive file=$(TEST_DISK),format=qcow2,if=none,id=nvme0 \
++ -device nvme,serial=deadbeef,drive=nvme0 \
++ -drive if=pflash,format=raw,readonly=on,file=$$OVMF_CODE \
++ -drive if=pflash,format=raw,file=./OVMF_VARS.fd \
++ -drive file="$(LATEST_ISO)",media=cdrom,readonly=on,cache=none \
++ -boot order=d \
++ -vga virtio \
++ -display gtk \
++ -usb -device usb-tablet \
++ -netdev user,id=net0,hostfwd=tcp::2222-:22 \
++ -device virtio-net-pci,netdev=net0 \
++ -boot menu=on
++
test-disk:
@if [ ! -f "$(TEST_DISK)" ]; then \
echo "No test disk found. Run 'make test' first to install."; \
diff --cc iso/airootfs/root/.automated_script.sh
index 155c836,155c836..6916f08
--- a/iso/airootfs/root/.automated_script.sh
+++ b/iso/airootfs/root/.automated_script.sh
@@@ -6,4 -6,4 +6,5 @@@ if [[ $(tty) == "/dev/tty1" ]]; the
pacman-key --populate archlinux
clear
/usr/local/bin/tonarchy
++ exec /bin/bash
fi
diff --cc src/tonarchy.c
index 3cb68d1,10bb1a1..5eada4d
--- a/src/tonarchy.c
+++ b/src/tonarchy.c
@@@ -367,133 -376,6 +376,133 @@@ void show_message(const char *message)
sleep(2);
}
+static int check_internet_connection(void) {
+ int result = system("ping -c 1 -W 2 1.1.1.1 > /dev/null 2>&1");
+ return result == 0;
+}
+
+static int list_wifi_networks(char networks[][256], char ssids[][128], int max_networks) {
+ FILE *fp = popen("nmcli -t -f SSID,SIGNAL,SECURITY device wifi list | head -20", "r");
+ if (!fp) {
+ return 0;
+ }
+
+ int count = 0;
+ char line[512];
+ while (count < max_networks && fgets(line, sizeof(line), fp) != NULL) {
+ line[strcspn(line, "\n")] = '\0';
+
+ char ssid[128], signal[32], security[64];
+ char *token = strtok(line, ":");
+ if (token) strncpy(ssid, token, sizeof(ssid) - 1);
+ token = strtok(NULL, ":");
+ if (token) strncpy(signal, token, sizeof(signal) - 1);
+ token = strtok(NULL, ":");
+ if (token) strncpy(security, token, sizeof(security) - 1);
+
+ if (strlen(ssid) > 0 && strcmp(ssid, "--") != 0) {
- strncpy(ssids[count], ssid, 127);
++ snprintf(ssids[count], 128, "%s", ssid);
+ snprintf(networks[count], 255, "%s (%s%%) [%s]", ssid, signal,
+ strlen(security) > 0 ? security : "Open");
+ count++;
+ }
+ }
+ pclose(fp);
+ return count;
+}
+
+static int connect_to_wifi(const char *ssid) {
+ int rows, cols;
+ get_terminal_size(&rows, &cols);
+
+ clear_screen();
+ draw_logo(cols);
+
+ int logo_start = (cols - 70) / 2;
+ printf("\033[%d;%dH\033[37mConnecting to: %s\033[0m", 10, logo_start, ssid);
+ printf("\033[%d;%dH\033[37mEnter password (leave empty if open): \033[0m", 12, logo_start);
+ fflush(stdout);
+
+ char password[256] = "";
+ struct termios old_term;
+ tcgetattr(STDIN_FILENO, &old_term);
+ struct termios new_term = old_term;
+ new_term.c_lflag &= ~ECHO;
+ new_term.c_lflag |= ICANON;
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &new_term);
+
+ if (fgets(password, sizeof(password), stdin) != NULL) {
+ password[strcspn(password, "\n")] = '\0';
+ }
+
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &old_term);
+
+ clear_screen();
+ draw_logo(cols);
+ printf("\033[%d;%dH\033[37mConnecting...\033[0m", 10, logo_start);
+ fflush(stdout);
+
+ char cmd[512];
+ if (strlen(password) > 0) {
+ snprintf(cmd, sizeof(cmd), "nmcli device wifi connect '%s' password '%s' > /dev/null 2>&1", ssid, password);
+ } else {
+ snprintf(cmd, sizeof(cmd), "nmcli device wifi connect '%s' > /dev/null 2>&1", ssid);
+ }
+
+ int result = system(cmd);
+ sleep(2);
+
+ if (result == 0 && check_internet_connection()) {
+ show_message("Connected successfully!");
+ return 1;
+ } else {
+ show_message("Connection failed. Please try again.");
+ return 0;
+ }
+}
+
+static int setup_wifi_if_needed(void) {
+ if (check_internet_connection()) {
+ return 1;
+ }
+
+ int rows, cols;
+ get_terminal_size(&rows, &cols);
+
+ clear_screen();
+ draw_logo(cols);
+
+ int logo_start = (cols - 70) / 2;
+ printf("\033[%d;%dH\033[37mNo internet connection detected.\033[0m", 10, logo_start);
+ printf("\033[%d;%dH\033[37mScanning for WiFi networks...\033[0m", 11, logo_start);
+ fflush(stdout);
+
+ system("nmcli radio wifi on > /dev/null 2>&1");
+ sleep(1);
+
+ char networks[32][256];
+ char ssids[32][128];
+ int network_count = list_wifi_networks(networks, ssids, 32);
+
+ if (network_count == 0) {
+ show_message("No WiFi networks found. Please check your connection.");
+ return 0;
+ }
+
+ const char *network_ptrs[32];
+ for (int i = 0; i < network_count; i++) {
+ network_ptrs[i] = networks[i];
+ }
+
+ int selected = select_from_menu(network_ptrs, network_count);
+ if (selected < 0) {
+ show_message("WiFi setup cancelled. Installation requires internet.");
+ return 0;
+ }
+
+ return connect_to_wifi(ssids[selected]);
+}
+
static void draw_form(
const char *username,
const char *password,
@@@ -870,6 -739,11 +866,11 @@@ static int partition_disk(const char *d
int logo_start = (cols - 70) / 2;
int uefi = is_uefi_system();
- char p1[64], p2[64], p3[64];
- part_path(p1, sizeof(p1), disk, 1);
- part_path(p2, sizeof(p2), disk, 2);
- part_path(p3, sizeof(p3), disk, 3);
++ char part1[64], part2[64], part3[64];
++ part_path(part1, sizeof(part1), disk, 1);
++ part_path(part2, sizeof(part2), disk, 2);
++ part_path(part3, sizeof(part3), disk, 3);
+
printf("\033[%d;%dH\033[37mPartitioning /dev/%s (%s mode)...\033[0m", 10, logo_start, disk, uefi ? "UEFI" : "BIOS");
fflush(stdout);
@@@ -922,41 -796,41 +923,41 @@@
fflush(stdout);
if (uefi) {
- snprintf(cmd, sizeof(cmd), "mkfs.fat -F32 /dev/%s 2>> /tmp/tonarchy-install.log", part1);
- snprintf(cmd, sizeof(cmd), "mkfs.fat -F32 %s 2>> /tmp/tonarchy-install.log", p1);
++ snprintf(cmd, sizeof(cmd), "mkfs.fat -F32 %s 2>> /tmp/tonarchy-install.log", part1);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to format EFI partition: /dev/%s", part1);
- LOG_ERROR("Failed to format EFI partition: %s", p1);
++ LOG_ERROR("Failed to format EFI partition: %s", part1);
show_message("Failed to format EFI partition");
return 0;
}
LOG_INFO("Formatted EFI partition");
- snprintf(cmd, sizeof(cmd), "mkswap /dev/%s 2>> /tmp/tonarchy-install.log", part2);
- snprintf(cmd, sizeof(cmd), "mkswap %s 2>> /tmp/tonarchy-install.log", p2);
++ snprintf(cmd, sizeof(cmd), "mkswap %s 2>> /tmp/tonarchy-install.log", part2);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to format swap: /dev/%s", part2);
- LOG_ERROR("Failed to format swap: %s", p2);
++ LOG_ERROR("Failed to format swap: %s", part2);
show_message("Failed to format swap partition");
return 0;
}
LOG_INFO("Formatted swap partition");
- snprintf(cmd, sizeof(cmd), "mkfs.ext4 -F /dev/%s 2>> /tmp/tonarchy-install.log", part3);
- snprintf(cmd, sizeof(cmd), "mkfs.ext4 -F %s 2>> /tmp/tonarchy-install.log", p3);
++ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -F %s 2>> /tmp/tonarchy-install.log", part3);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to format root: /dev/%s", part3);
- LOG_ERROR("Failed to format root: %s", p3);
++ LOG_ERROR("Failed to format root: %s", part3);
show_message("Failed to format root partition");
return 0;
}
LOG_INFO("Formatted root partition");
} else {
- snprintf(cmd, sizeof(cmd), "mkswap /dev/%s 2>> /tmp/tonarchy-install.log", part1);
- snprintf(cmd, sizeof(cmd), "mkswap %s 2>> /tmp/tonarchy-install.log", p1);
++ snprintf(cmd, sizeof(cmd), "mkswap %s 2>> /tmp/tonarchy-install.log", part1);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to format swap: /dev/%s", part1);
- LOG_ERROR("Failed to format swap: %s", p1);
++ LOG_ERROR("Failed to format swap: %s", part1);
show_message("Failed to format swap partition");
return 0;
}
LOG_INFO("Formatted swap partition");
- snprintf(cmd, sizeof(cmd), "mkfs.ext4 -F /dev/%s 2>> /tmp/tonarchy-install.log", part2);
- snprintf(cmd, sizeof(cmd), "mkfs.ext4 -F %s 2>> /tmp/tonarchy-install.log", p2);
++ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -F %s 2>> /tmp/tonarchy-install.log", part2);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to format root: /dev/%s", part2);
- LOG_ERROR("Failed to format root: %s", p2);
++ LOG_ERROR("Failed to format root: %s", part2);
show_message("Failed to format root partition");
return 0;
}
@@@ -967,9 -841,9 +968,9 @@@
fflush(stdout);
if (uefi) {
- snprintf(cmd, sizeof(cmd), "mount /dev/%s /mnt 2>> /tmp/tonarchy-install.log", part3);
- snprintf(cmd, sizeof(cmd), "mount %s /mnt 2>> /tmp/tonarchy-install.log", p3);
++ snprintf(cmd, sizeof(cmd), "mount %s /mnt 2>> /tmp/tonarchy-install.log", part3);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to mount root: /dev/%s", part3);
- LOG_ERROR("Failed to mount root: %s", p3);
++ LOG_ERROR("Failed to mount root: %s", part3);
show_message("Failed to mount root partition");
return 0;
}
@@@ -978,32 -852,32 +979,32 @@@
snprintf(cmd, sizeof(cmd), "mkdir -p /mnt/boot 2>> /tmp/tonarchy-install.log");
system(cmd);
- snprintf(cmd, sizeof(cmd), "mount /dev/%s /mnt/boot 2>> /tmp/tonarchy-install.log", part1);
- snprintf(cmd, sizeof(cmd), "mount %s /mnt/boot 2>> /tmp/tonarchy-install.log", p1);
++ snprintf(cmd, sizeof(cmd), "mount %s /mnt/boot 2>> /tmp/tonarchy-install.log", part1);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to mount EFI: /dev/%s", part1);
- LOG_ERROR("Failed to mount EFI: %s", p1);
++ LOG_ERROR("Failed to mount EFI: %s", part1);
show_message("Failed to mount EFI partition");
return 0;
}
LOG_INFO("Mounted EFI partition");
- snprintf(cmd, sizeof(cmd), "swapon /dev/%s 2>> /tmp/tonarchy-install.log", part2);
- snprintf(cmd, sizeof(cmd), "swapon %s 2>> /tmp/tonarchy-install.log", p2);
++ snprintf(cmd, sizeof(cmd), "swapon %s 2>> /tmp/tonarchy-install.log", part2);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to enable swap: /dev/%s", part2);
- LOG_ERROR("Failed to enable swap: %s", p2);
++ LOG_ERROR("Failed to enable swap: %s", part2);
show_message("Failed to enable swap");
return 0;
}
} else {
- snprintf(cmd, sizeof(cmd), "mount /dev/%s /mnt 2>> /tmp/tonarchy-install.log", part2);
- snprintf(cmd, sizeof(cmd), "mount %s /mnt 2>> /tmp/tonarchy-install.log", p2);
++ snprintf(cmd, sizeof(cmd), "mount %s /mnt 2>> /tmp/tonarchy-install.log", part2);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to mount root: /dev/%s", part2);
- LOG_ERROR("Failed to mount root: %s", p2);
++ LOG_ERROR("Failed to mount root: %s", part2);
show_message("Failed to mount root partition");
return 0;
}
LOG_INFO("Mounted root partition");
- snprintf(cmd, sizeof(cmd), "swapon /dev/%s 2>> /tmp/tonarchy-install.log", part1);
- snprintf(cmd, sizeof(cmd), "swapon %s 2>> /tmp/tonarchy-install.log", p1);
++ snprintf(cmd, sizeof(cmd), "swapon %s 2>> /tmp/tonarchy-install.log", part1);
if (system(cmd) != 0) {
- LOG_ERROR("Failed to enable swap: /dev/%s", part1);
- LOG_ERROR("Failed to enable swap: %s", p1);
++ LOG_ERROR("Failed to enable swap: %s", part1);
show_message("Failed to enable swap");
return 0;
}
@@@ -1598,21 -1467,18 +1599,24 @@@ int main(void)
draw_logo(cols);
int logo_start = (cols - 70) / 2;
- printf("\033[%d;%dH\033[1;32mInstallation complete!\033[0m", 10, logo_start);
- printf("\033[%d;%dH\033[37mPress Enter to reboot...\033[0m", 12, logo_start);
+ printf("\033[%d;%dH\033[1;32mInstallation complete!\033[0m\n", 10, logo_start);
- printf("\033[%d;%dH\033[37mPress Enter or Q to quit. Then, manually reboot.\033[0m\n", 12, logo_start);
++ printf("\033[%d;%dH\033[37mPress Enter to reboot...\033[0m\n", 12, logo_start);
fflush(stdout);
- enable_raw_mode();
char c;
- read(STDIN_FILENO, &c, 1);
+ enable_raw_mode();
+ while (read(STDIN_FILENO, &c, 1) == 1) {
- if (c == '\r' || c == '\n' || c == 'q' || c == 'Q') {
++ if (c == '\r' || c == '\n') {
+ break;
+ }
+ }
disable_raw_mode();
- system("eject -m /dev/sr0 2>/dev/null");
- system("reboot");
- LOG_INFO("Tonarchy installer finished - exiting cleanly");
- LOG_INFO("Tonarchy installer finished");
++ LOG_INFO("Tonarchy installer finished - scheduling reboot");
logger_close();
- return 0;
+
- return 0;
++ sync();
++ system("sleep 2 && reboot &");
++
++ exit(0);
}