Update init service for FreeBSD

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2025-10-18 11:23:57 +02:00
parent 3faf3dec42
commit 541eae5311
No known key found for this signature in database
4 changed files with 26 additions and 31 deletions

View File

@ -320,13 +320,12 @@ fn install_service(allocator: std.mem.Allocator, patch_map: PatchMap) !void {
try installText(patched_service, service_dir, service_path, "ly", .{ .mode = 0o755 }); try installText(patched_service, service_dir, service_path, "ly", .{ .mode = 0o755 });
}, },
.freebsd => { .freebsd => {
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/rc.d" }); const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin" });
std.fs.cwd().makePath(service_path) catch {}; var executable_dir = std.fs.cwd().openDir(exe_path, .{}) catch unreachable;
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable; defer executable_dir.close();
defer service_dir.close();
const patched_service = try patchFile(allocator, "res/ly-freebsd", patch_map); const patched_wrapper = try patchFile(allocator, "res/ly-freebsd-wrapper", patch_map);
try installText(patched_service, service_dir, service_path, "ly", .{ .mode = 0o755 }); try installText(patched_wrapper, executable_dir, exe_path, "ly_wrapper", .{ .mode = 0o755 });
}, },
} }
} }

View File

@ -180,10 +180,22 @@ To disable TTY 2, go to `/etc/inittab` and comment out the line containing `tty2
``` ```
# zig build installexe -Dprefix_directory=/usr/local -Dinit_system=freebsd # zig build installexe -Dprefix_directory=/usr/local -Dinit_system=freebsd
# sysrc lightdm_enable="NO" # sysrc lightdm_enable="NO"
# sysrc ly_enable="YES"
``` ```
To disable TTY 2, go to `/etc/ttys` and comment out the line starting with `ttyv1` (TTYs start at 0 in FreeBSD). To enable Ly, add the following entry to `/etc/gettytab`:
```
Ly:\
:lo=/usr/local/bin/ly_wrapper:\
:al=root:
```
Then, modify the command field of the `ttyv1` terminal entry in `/etc/ttys`
(TTYs in FreeBSD start at 0):
```
ttyv1 "/usr/libexec/getty Ly" xterm on secure
```
### Updating ### Updating

View File

@ -1,23 +0,0 @@
#!/bin/sh
#
# PROVIDE: ly
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name=ly
rcvar=ly_enable
command="/usr/local/bin/ly"
load_rc_config $name
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
# SET THEM IN THE /etc/rc.conf FILE
#
ly_enable=${ly_enable-"NO"}
pidfile=${ly_pidfile-"/var/run/ly.pid"}
run_rc_command "$1"

7
res/ly-freebsd-wrapper Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# On FreeBSD, even if we override the default login program, getty will still
# try to append "login -fp root" as arguments to Ly, which is not supported.
# To avoid this, we use a wrapper script that ignores these arguments before
# actually executing Ly.
exec $PREFIX_DIRECTORY/bin/$EXECUTABLE_NAME