mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 22:34:02 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
193 lines
5.9 KiB
Bash
Executable File
193 lines
5.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# sudoers, lightdm autologin, i3 session and misc configuration writers.
|
|
#
|
|
# Sourced by setup_passwordless_system.sh, which owns the ordering and the
|
|
# safety checks; this file defines functions only.
|
|
|
|
# Function to configure passwordless sudo
|
|
configure_passwordless_sudo() {
|
|
echo ""
|
|
echo "1. Configuring Passwordless Sudo..."
|
|
echo "=================================="
|
|
|
|
local sudoers_file="/etc/sudoers.d/99-passwordless-${TARGET_USER}"
|
|
|
|
# Create sudoers configuration for passwordless access
|
|
cat > "$sudoers_file" << EOF
|
|
# Passwordless sudo configuration for user: ${TARGET_USER}
|
|
# Created by setup_passwordless_system.sh on $(date)
|
|
# WARNING: This allows the user to run any command without password
|
|
|
|
# Allow user to run all commands without password
|
|
${TARGET_USER} ALL=(ALL) NOPASSWD: ALL
|
|
|
|
# Ensure user can run sudo without TTY (useful for scripts)
|
|
Defaults:${TARGET_USER} !requiretty
|
|
|
|
# Keep environment variables for user convenience
|
|
Defaults:${TARGET_USER} env_keep += "HOME PATH DISPLAY XAUTHORITY"
|
|
EOF
|
|
|
|
# Set proper permissions for sudoers file
|
|
chmod 440 "$sudoers_file"
|
|
|
|
# Verify the sudoers file syntax
|
|
if visudo -c -f "$sudoers_file"; then
|
|
echo "✓ Passwordless sudo configured for user: $TARGET_USER"
|
|
echo "✓ Sudoers file created: $sudoers_file"
|
|
else
|
|
echo "✗ Error: Invalid sudoers syntax. Removing file for safety."
|
|
rm -f "$sudoers_file"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to configure lightdm auto-login
|
|
configure_lightdm_autologin() {
|
|
echo ""
|
|
echo "2. Configuring LightDM Auto-Login..."
|
|
echo "==================================="
|
|
|
|
local lightdm_conf="/etc/lightdm/lightdm.conf"
|
|
local lightdm_conf_dir="/etc/lightdm/lightdm.conf.d"
|
|
local custom_conf="$lightdm_conf_dir/50-autologin.conf"
|
|
|
|
# Create lightdm config directory if it doesn't exist
|
|
mkdir -p "$lightdm_conf_dir"
|
|
|
|
# Backup existing lightdm configuration
|
|
backup_file "$lightdm_conf"
|
|
|
|
# Check if lightdm is installed
|
|
if ! command -v lightdm &> /dev/null; then
|
|
echo "Warning: LightDM not found. Installing lightdm..."
|
|
pacman -S --noconfirm lightdm lightdm-gtk-greeter
|
|
fi
|
|
|
|
# Method 1: Update the main lightdm.conf file directly
|
|
sed -i "/^#autologin-user=/c\autologin-user=${TARGET_USER}" "$lightdm_conf"
|
|
sed -i "/^#autologin-user-timeout=/c\autologin-user-timeout=0" "$lightdm_conf"
|
|
sed -i "/^#autologin-session=/c\autologin-session=i3" "$lightdm_conf"
|
|
sed -i "/^#autologin-in-background=/c\autologin-in-background=false" "$lightdm_conf"
|
|
|
|
# Also set user-session to i3 as fallback
|
|
sed -i "/^#user-session=/c\user-session=i3" "$lightdm_conf"
|
|
|
|
echo "✓ LightDM auto-login configured in main config file"
|
|
|
|
# Method 2: Also create the separate config file for redundancy
|
|
cat > "$custom_conf" << EOF
|
|
# LightDM Auto-Login Configuration
|
|
# Created by setup_passwordless_system.sh on $(date)
|
|
|
|
[Seat:*]
|
|
# Enable auto-login
|
|
autologin-user=${TARGET_USER}
|
|
autologin-user-timeout=0
|
|
autologin-session=i3
|
|
|
|
# Disable user switching and guest account
|
|
allow-user-switching=false
|
|
allow-guest=false
|
|
|
|
# Set session defaults
|
|
user-session=i3
|
|
greeter-session=lightdm-gtk-greeter
|
|
|
|
# Disable screen lock timeout during login
|
|
autologin-in-background=false
|
|
EOF
|
|
|
|
echo "✓ LightDM auto-login also configured in separate config file: $custom_conf"
|
|
|
|
# Enable lightdm service
|
|
systemctl enable lightdm.service
|
|
echo "✓ LightDM service enabled"
|
|
|
|
# Restart lightdm to apply changes only if --logout flag is provided
|
|
if [[ $ALLOW_LOGOUT == true ]]; then
|
|
echo "Restarting LightDM to apply auto-login settings..."
|
|
systemctl restart lightdm.service
|
|
echo "✓ LightDM restarted"
|
|
else
|
|
echo "✓ LightDM configuration complete (restart lightdm or reboot to activate auto-login)"
|
|
fi
|
|
}
|
|
|
|
# Function to configure i3 session
|
|
configure_i3_session() {
|
|
echo ""
|
|
echo "3. Configuring i3 Session..."
|
|
echo "==========================="
|
|
|
|
local xsessions_dir="/usr/share/xsessions"
|
|
local i3_desktop="$xsessions_dir/i3.desktop"
|
|
|
|
# Create xsessions directory if it doesn't exist
|
|
mkdir -p "$xsessions_dir"
|
|
|
|
# Check if i3.desktop exists, create if not
|
|
if [[ ! -f $i3_desktop ]]; then
|
|
cat > "$i3_desktop" << EOF
|
|
[Desktop Entry]
|
|
Name=i3
|
|
Comment=improved dynamic tiling window manager
|
|
Exec=i3
|
|
TryExec=i3
|
|
Type=Application
|
|
X-LightDM-DesktopName=i3
|
|
DesktopNames=i3
|
|
Keywords=tiling;wm;windowmanager;window;manager;
|
|
EOF
|
|
echo "✓ Created i3 desktop session file: $i3_desktop"
|
|
else
|
|
echo "✓ i3 desktop session file already exists"
|
|
fi
|
|
|
|
# Ensure user has i3 config directory
|
|
local user_home="/home/${TARGET_USER}"
|
|
local i3_config_dir="$user_home/.config/i3"
|
|
|
|
if [[ ! -d $i3_config_dir ]]; then
|
|
sudo -u "$TARGET_USER" mkdir -p "$i3_config_dir"
|
|
echo "✓ Created i3 config directory for user: $TARGET_USER"
|
|
fi
|
|
}
|
|
|
|
# Function to configure additional auto-login settings
|
|
configure_additional_settings() {
|
|
echo ""
|
|
echo "4. Configuring Additional Settings..."
|
|
echo "===================================="
|
|
|
|
# Add user to autologin group if it exists
|
|
if getent group autologin &> /dev/null; then
|
|
usermod -a -G autologin "$TARGET_USER"
|
|
echo "✓ Added $TARGET_USER to autologin group"
|
|
else
|
|
# Create autologin group
|
|
groupadd -r autologin
|
|
usermod -a -G autologin "$TARGET_USER"
|
|
echo "✓ Created autologin group and added $TARGET_USER"
|
|
fi
|
|
|
|
# Configure pam for auto-login (if needed)
|
|
local pam_lightdm="/etc/pam.d/lightdm-autologin"
|
|
if [[ ! -f $pam_lightdm ]]; then
|
|
cat > "$pam_lightdm" << EOF
|
|
#%PAM-1.0
|
|
# LightDM auto-login PAM configuration
|
|
# Created by setup_passwordless_system.sh on $(date)
|
|
|
|
auth required pam_unix.so nullok
|
|
auth optional pam_permit.so
|
|
auth optional pam_gnome_keyring.so
|
|
account include system-local-login
|
|
password include system-local-login
|
|
session include system-local-login
|
|
session optional pam_gnome_keyring.so auto_start
|
|
EOF
|
|
echo "✓ Created PAM configuration for auto-login"
|
|
fi
|
|
}
|