This commit is contained in:
2025-02-09 08:52:42 +01:00
parent 690b1b68c3
commit 1d631fec21
55 changed files with 2560 additions and 930 deletions

View File

@@ -109,12 +109,12 @@ pub fn profile_path_source() !string {
}
pp := profile_path()!
if os.exists(pp) {
res := os.execute('source ${pp}')
res := os.execute('/bin/sh ${pp}')
if res.exit_code != 0 {
console.print_stderr('WARNING: your profile is corrupt: ${pp}')
console.print_stderr('WARNING: your profile is corrupt, did:\nsource ${pp}\n${res}')
return error('profile corrupt')
} else {
return 'source ${pp}'
return '. ${pp}'
}
}
return ''
@@ -300,7 +300,7 @@ pub fn profile_paths_preferred() ![]string {
for file in toadd {
if os.exists(file) {
println('${file} exists')
//println('${file} exists')
profile_files2 << file
}
}
@@ -308,9 +308,9 @@ pub fn profile_paths_preferred() ![]string {
}
pub fn profile_path() !string {
if core.is_osx()! {
return '${os.home_dir()}/.zprofile'
} else {
return '${os.home_dir()}/.bash_profile'
mut preferred := profile_paths_preferred()!
if preferred.len==0{
return error("can't find profile_path, found none")
}
return preferred[0]
}

View File

@@ -109,7 +109,7 @@ pub fn (mut sm StartupManager) new(args zinit.ZProcessNewArgs) ! {
zinitfactory.new(args)!
}
else {
panic('to implement, startup manager only support screen & systemd for now')
panic('to implement, startup manager only support screen & systemd for now: ${mycat}')
}
}
// if args.start {
@@ -222,7 +222,7 @@ pub fn (mut sm StartupManager) delete(name string) ! {
}
}
else {
panic('to implement, startup manager only support screen & systemd for now')
panic('to implement, startup manager only support screen & systemd for now ${mycat}')
}
}
}
@@ -280,7 +280,7 @@ pub fn (mut sm StartupManager) status(name string) !ProcessStatus {
}
}
else {
panic('to implement, startup manager only support screen & systemd for now')
panic('to implement, startup manager only support screen & systemd for now ${mycat}')
}
}
}
@@ -303,7 +303,7 @@ pub fn (mut sm StartupManager) output(name string) !string {
return systemd.journalctl(service: name)!
}
else {
panic('to implement, startup manager only support screen & systemd for now')
panic('to implement, startup manager only support screen & systemd for now ${mycat}')
}
}
}
@@ -326,7 +326,7 @@ pub fn (mut sm StartupManager) exists(name string) !bool {
return zinitfactory.exists(name)
}
else {
panic('to implement. startup manager only support screen & systemd for now')
panic('to implement. startup manager only support screen & systemd for now ${mycat}')
}
}
}
@@ -347,7 +347,7 @@ pub fn (mut sm StartupManager) list() ![]string {
return zinitfactory.names()
}
else {
panic('to implement. startup manager only support screen & systemd for now')
panic('to implement. startup manager only support screen & systemd for now: ${mycat}')
}
}
}

62
lib/osal/tun/readme.md Normal file
View File

@@ -0,0 +1,62 @@
# TUN Interface Management
This module provides functionality to manage TUN (network tunnel) interfaces on Linux and macOS systems.
## Functions
### available() !bool
Checks if TUN/TAP functionality is available on the system:
- Linux: Verifies `/dev/net/tun` exists and is a character device
- macOS: Checks for `utun` interfaces using `ifconfig` and `sysctl`
### free() !string
Returns the name of an available TUN interface:
- Linux: Returns first available interface from tun0-tun10
- macOS: Returns next available utun interface number
## Example Usage
```v
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.osal.tun
// Check if TUN is available
if available := tun.available() {
if available {
println('TUN is available on this system')
// Get a free TUN interface name
if interface_name := tun.free() {
println('Found free TUN interface: ${interface_name}')
// Example: Now you could use this interface name
// to set up your tunnel
} else {
println('Error finding free interface: ${err}')
}
} else {
println('TUN is not available on this system')
}
} else {
println('Error checking TUN availability: ${err}')
}
```
## Platform Support
The module automatically detects the platform (Linux/macOS) and uses the appropriate methods:
- On Linux: Uses `/dev/net/tun` and `ip link` commands
- On macOS: Uses `utun` interfaces via `ifconfig`
## Error Handling
Both functions return a Result type, so errors should be handled appropriately:
- Unsupported platform errors
- Interface availability errors
- System command execution errors

65
lib/osal/tun/tun.v Normal file
View File

@@ -0,0 +1,65 @@
module tun
import os
import freeflowuniverse.herolib.core
// available checks if TUN/TAP is available on the system
pub fn available() !bool {
if core.is_linux()! {
// Check if /dev/net/tun exists and is a character device
if !os.exists('/dev/net/tun') {
return false
}
// Try to get file info to verify it's a character device
res := os.execute('test -c /dev/net/tun')
return res.exit_code == 0
} else if core.is_osx()! {
// On macOS, check for utun interfaces
res := os.execute('ifconfig | grep utun')
if res.exit_code == 0 && res.output.len > 0 {
return true
}
// Also try sysctl as alternative check
res2 := os.execute('sysctl -a | grep net.inet.ip.tun')
return res2.exit_code == 0 && res2.output.len > 0
}
return error('Unsupported platform')
}
// free returns the name of an available TUN interface e.g. returns 'utun1'
pub fn free() !string {
if core.is_linux()! {
// Try tun0 through tun10
for i in 1 .. 11 {
name := 'tun${i}'
res := os.execute('ip link show ${name}')
if res.exit_code != 0 {
// Interface doesn't exist, so it's free
return name
}
}
return error('No free tun interface found')
} else if core.is_osx()! {
// On macOS, list existing utun interfaces to find highest number
res := os.execute('ifconfig | grep utun')
if res.exit_code != 0 {
// No utun interfaces exist, so utun0 would be next
return 'utun0'
}
// Find highest utun number
mut max_num := -1
lines := res.output.split('\n')
for line in lines {
if line.starts_with('utun') {
mynum := line[4..].all_before(':').int()
if mynum > max_num {
max_num = mynum
}
}
}
// Next available number
return 'utun${max_num + 1}'
}
return error('Unsupported platform')
}