From 6fbbb4eff0857ae32802ae216f99d4f66813d206 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Mon, 5 Aug 2024 00:58:29 +0200 Subject: [PATCH] Consolidate xsetup.sh & wsetup.sh into one file Signed-off-by: AnErrupTion --- build.zig | 9 ++-- res/config.ini | 7 +-- res/setup.sh | 107 ++++++++++++++++++++++++++++++++++++++++ src/auth.zig | 8 +-- src/config/Config.zig | 3 +- src/config/migrator.zig | 4 +- 6 files changed, 120 insertions(+), 18 deletions(-) create mode 100755 res/setup.sh diff --git a/build.zig b/build.zig index 2686f09..f0e9074 100644 --- a/build.zig +++ b/build.zig @@ -269,11 +269,8 @@ fn install_ly(allocator: std.mem.Allocator, install_config: bool) !void { try patch_map.put("$CONFIG_DIRECTORY", config_directory); - const patched_xsetup = try patchFile(allocator, "res/xsetup.sh", patch_map); - const patched_wsetup = try patchFile(allocator, "res/wsetup.sh", patch_map); - - try installText(patched_xsetup, config_dir, ly_config_directory, "xsetup.sh", .{ .mode = 0o755 }); - try installText(patched_wsetup, config_dir, ly_config_directory, "wsetup.sh", .{ .mode = 0o755 }); + const patched_setup = try patchFile(allocator, "res/setup.sh", patch_map); + try installText(patched_setup, config_dir, ly_config_directory, "setup.sh", .{ .mode = 0o755 }); } } @@ -317,7 +314,7 @@ fn install_ly(allocator: std.mem.Allocator, install_config: bool) !void { pub fn uninstallall(step: *std.Build.Step, _: ProgressNode) !void { const allocator = step.owner.allocator; - try deleteTree(allocator, config_directory, "/ly", "ly data directory not found"); + try deleteTree(allocator, config_directory, "/ly", "ly config directory not found"); const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin/", executable_name }); var success = true; diff --git a/res/config.ini b/res/config.ini index 64dbb3d..8650bf0 100644 --- a/res/config.ini +++ b/res/config.ini @@ -149,8 +149,8 @@ numlock = false # Service name (set to ly to use the provided pam config file) service_name = ly -# Wayland setup command -wayland_cmd = $CONFIG_DIRECTORY/ly/wsetup.sh +# Setup command +setup_cmd = $CONFIG_DIRECTORY/ly/setup.sh # Wayland desktop environments waylandsessions = $PREFIX_DIRECTORY/share/wayland-sessions @@ -162,9 +162,6 @@ xinitrc = ~/.xinitrc # Xorg server command x_cmd = $PREFIX_DIRECTORY/bin/X -# Xorg setup command -x_cmd_setup = $CONFIG_DIRECTORY/ly/xsetup.sh - # Xorg xauthority edition tool xauth_cmd = $PREFIX_DIRECTORY/bin/xauth diff --git a/res/setup.sh b/res/setup.sh new file mode 100755 index 0000000..549994a --- /dev/null +++ b/res/setup.sh @@ -0,0 +1,107 @@ +#!/bin/sh +# Shell environment setup after login +# Copyright (C) 2015-2016 Pier Luigi Fiorini + +# This file is extracted from kde-workspace (kdm/kfrontend/genkdmconf.c) +# Copyright (C) 2001-2005 Oswald Buddenhagen + +# Copyright (C) 2024 The Fairy Glade +# This work is free. You can redistribute it and/or modify it under the +# terms of the Do What The Fuck You Want To Public License, Version 2, +# as published by Sam Hocevar. See the LICENSE file for more details. + +# Note that the respective logout scripts are not sourced. +case $SHELL in +*/bash) + [ -z "$BASH" ] && exec $SHELL "$0" "$@" + set +o posix + [ -f "$CONFIG_DIRECTORY"/profile ] && . "$CONFIG_DIRECTORY"/profile + if [ -f "$HOME"/.bash_profile ]; then + . "$HOME"/.bash_profile + elif [ -f "$HOME"/.bash_login ]; then + . "$HOME"/.bash_login + elif [ -f "$HOME"/.profile ]; then + . "$HOME"/.profile + fi + ;; +*/zsh) + [ -z "$ZSH_NAME" ] && exec $SHELL "$0" "$@" + [ -d "$CONFIG_DIRECTORY"/zsh ] && zdir="$CONFIG_DIRECTORY"/zsh || zdir="$CONFIG_DIRECTORY" + zhome=${ZDOTDIR:-"$HOME"} + # zshenv is always sourced automatically. + [ -f "$zdir"/zprofile ] && . "$zdir"/zprofile + [ -f "$zhome"/.zprofile ] && . "$zhome"/.zprofile + [ -f "$zdir"/zlogin ] && . "$zdir"/zlogin + [ -f "$zhome"/.zlogin ] && . "$zhome"/.zlogin + emulate -R sh + ;; +*/csh|*/tcsh) + # [t]cshrc is always sourced automatically. + # Note that sourcing csh.login after .cshrc is non-standard. + sess_tmp=$(mktemp /tmp/sess-env-XXXXXX) + $SHELL -c "if (-f $CONFIG_DIRECTORY/csh.login) source $CONFIG_DIRECTORY/csh.login; if (-f ~/.login) source ~/.login; /bin/sh -c 'export -p' >! $sess_tmp" + . "$sess_tmp" + rm -f "$sess_tmp" + ;; +*/fish) + [ -f "$CONFIG_DIRECTORY"/profile ] && . "$CONFIG_DIRECTORY"/profile + [ -f "$HOME"/.profile ] && . "$HOME"/.profile + sess_tmp=$(mktemp /tmp/sess-env-XXXXXX) + $SHELL --login -c "/bin/sh -c 'export -p' > $sess_tmp" + . "$sess_tmp" + rm -f "$sess_tmp" + ;; +*) # Plain sh, ksh, and anything we do not know. + [ -f "$CONFIG_DIRECTORY"/profile ] && . "$CONFIG_DIRECTORY"/profile + [ -f "$HOME"/.profile ] && . "$HOME"/.profile + ;; +esac + +if [ "$XDG_SESSION_TYPE" = "x11" ]; then + [ -f "$CONFIG_DIRECTORY"/xprofile ] && . "$CONFIG_DIRECTORY"/xprofile + [ -f "$HOME"/.xprofile ] && . "$HOME"/.xprofile + + # run all system xinitrc shell scripts. + if [ -d "$CONFIG_DIRECTORY"/X11/xinit/xinitrc.d ]; then + for i in "$CONFIG_DIRECTORY"/X11/xinit/xinitrc.d/* ; do + if [ -x "$i" ]; then + . "$i" + fi + done + fi + + # Load Xsession scripts + # OPTIONFILE, USERXSESSION, USERXSESSIONRC and ALTUSERXSESSION are required + # by the scripts to work + xsessionddir="$CONFIG_DIRECTORY"/X11/Xsession.d + export OPTIONFILE="$CONFIG_DIRECTORY"/X11/Xsession.options + export USERXSESSION="$HOME"/.xsession + export USERXSESSIONRC="$HOME"/.xsessionrc + export ALTUSERXSESSION="$HOME"/.Xsession + + if [ -d "$xsessionddir" ]; then + for i in $(ls "$xsessionddir"); do + script="$xsessionddir/$i" + echo "Loading X session script $script" + if [ -r "$script" ] && [ -f "$script" ] && expr "$i" : '^[[:alnum:]_-]\+$' > /dev/null; then + . "$script" + fi + done + fi + + if [ -d "$CONFIG_DIRECTORY"/X11/Xresources ]; then + for i in "$CONFIG_DIRECTORY"/X11/Xresources/*; do + [ -f "$i" ] && xrdb -merge "$i" + done + elif [ -f "$CONFIG_DIRECTORY"/X11/Xresources ]; then + xrdb -merge "$CONFIG_DIRECTORY"/X11/Xresources + fi + [ -f "$HOME"/.Xresources ] && xrdb -merge "$HOME"/.Xresources + [ -f "$XDG_CONFIG_HOME"/X11/Xresources ] && xrdb -merge "$XDG_CONFIG_HOME"/X11/Xresources + + if [ -f "$USERXSESSION" ]; then + . "$USERXSESSION" + fi +fi + +exec "$@" diff --git a/src/auth.zig b/src/auth.zig index ed28473..1abc39c 100644 --- a/src/auth.zig +++ b/src/auth.zig @@ -156,7 +156,7 @@ fn startSession( std.posix.chdirZ(pwd.pw_dir.?) catch return error.ChangeDirectoryFailed; switch (current_environment.display_server) { - .wayland => try executeWaylandCmd(pwd.pw_shell.?, config.wayland_cmd, current_environment.cmd), + .wayland => try executeWaylandCmd(pwd.pw_shell.?, config.setup_cmd, current_environment.cmd), .shell => try executeShellCmd(pwd.pw_shell.?), .xinitrc, .x11 => if (build_options.enable_x11_support) { var vt_buf: [5]u8 = undefined; @@ -377,9 +377,9 @@ fn executeShellCmd(shell: [*:0]const u8) !void { return std.posix.execveZ(shell, &args, std.c.environ); } -fn executeWaylandCmd(shell: [*:0]const u8, wayland_cmd: []const u8, desktop_cmd: []const u8) !void { +fn executeWaylandCmd(shell: [*:0]const u8, setup_cmd: []const u8, desktop_cmd: []const u8) !void { var cmd_buffer: [1024]u8 = undefined; - const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ wayland_cmd, desktop_cmd }); + const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ setup_cmd, desktop_cmd }); const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str }; return std.posix.execveZ(shell, &args, std.c.environ); } @@ -416,7 +416,7 @@ fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, config: Config, de xorg_pid = try std.posix.fork(); if (xorg_pid == 0) { var cmd_buffer: [1024]u8 = undefined; - const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ config.x_cmd_setup, desktop_cmd }) catch std.process.exit(1); + const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ config.setup_cmd, desktop_cmd }) catch std.process.exit(1); const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str }; std.posix.execveZ(shell, &args, std.c.environ) catch {}; std.process.exit(1); diff --git a/src/config/Config.zig b/src/config/Config.zig index beb8e41..55c8f9c 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -36,6 +36,7 @@ restart_cmd: []const u8 = "/sbin/shutdown -r now", restart_key: []const u8 = "F2", save: bool = true, service_name: [:0]const u8 = "ly", +setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh", shutdown_cmd: []const u8 = "/sbin/shutdown -a now", shutdown_key: []const u8 = "F1", sleep_cmd: ?[]const u8 = null, @@ -43,11 +44,9 @@ sleep_key: []const u8 = "F3", tty: u8 = build_options.tty, vi_mode: bool = false, vi_default_mode: ViMode = .normal, -wayland_cmd: []const u8 = build_options.config_directory ++ "/ly/wsetup.sh", waylandsessions: []const u8 = build_options.prefix_directory ++ "/share/wayland-sessions", x_cmd: []const u8 = build_options.prefix_directory ++ "/bin/X", xinitrc: ?[]const u8 = "~/.xinitrc", -x_cmd_setup: []const u8 = build_options.config_directory ++ "/ly/xsetup.sh", xauth_cmd: []const u8 = build_options.prefix_directory ++ "/bin/xauth", xsessions: []const u8 = build_options.prefix_directory ++ "/share/xsessions", brightness_down_key: []const u8 = "F5", diff --git a/src/config/migrator.zig b/src/config/migrator.zig index 93c470f..df028c4 100644 --- a/src/config/migrator.zig +++ b/src/config/migrator.zig @@ -76,7 +76,9 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie std.mem.eql(u8, field.key, "max_password_len") or std.mem.eql(u8, field.key, "mcookie_cmd") or std.mem.eql(u8, field.key, "term_reset_cmd") or - std.mem.eql(u8, field.key, "term_restore_cursor_cmd")) + std.mem.eql(u8, field.key, "term_restore_cursor_cmd") or + std.mem.eql(u8, field.key, "x_cmd_setup") or + std.mem.eql(u8, field.key, "wayland_cmd")) { // The options don't exist anymore mapped_config_fields = true;