mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:07:04 +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
195 lines
5.8 KiB
Bash
Executable File
195 lines
5.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script to set up passwordless sudo and automatic login
|
|
# Configures lightdm for auto-login and sudo for passwordless access
|
|
# Handles sudo privileges automatically
|
|
# Usage: ./setup_passwordless_system.sh [--reboot] [--logout]
|
|
# --reboot: Offer to reboot after setup completion
|
|
# --logout: Allow restart of LightDM (which will logout the user)
|
|
|
|
set -e # Exit on any error
|
|
|
|
# shellcheck source=lib/passwordless_config.sh
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/passwordless_config.sh"
|
|
|
|
# Check for flags
|
|
OFFER_REBOOT=false
|
|
ALLOW_LOGOUT=false
|
|
for arg in "$@"; do
|
|
case $arg in
|
|
--reboot)
|
|
OFFER_REBOOT=true
|
|
shift
|
|
;;
|
|
--logout)
|
|
ALLOW_LOGOUT=true
|
|
shift
|
|
;;
|
|
*)
|
|
# Unknown option, keep it for sudo check
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Function to check and request sudo privileges
|
|
check_sudo() {
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script requires sudo privileges to modify system configurations."
|
|
echo "Requesting sudo access..."
|
|
exec sudo "$0" "$@"
|
|
fi
|
|
}
|
|
|
|
# Check for sudo privileges first
|
|
check_sudo "$@"
|
|
|
|
echo "Passwordless System Setup"
|
|
echo "========================"
|
|
echo "Current Date: $(date)"
|
|
echo "User: $USER"
|
|
echo "Original user: ${SUDO_USER:-$USER}"
|
|
|
|
# Verify we have a valid user
|
|
if [[ -z ${SUDO_USER} ]]; then
|
|
echo "Error: Could not determine the original user. Please run this script with sudo."
|
|
exit 1
|
|
fi
|
|
|
|
TARGET_USER="${SUDO_USER}"
|
|
echo "Target user for configuration: $TARGET_USER"
|
|
|
|
# Function to backup files
|
|
backup_file() {
|
|
local file="$1"
|
|
if [[ -f $file ]]; then
|
|
local backup timestamp
|
|
timestamp=$(date +%Y%m%d_%H%M%S)
|
|
backup="${file}.backup.$timestamp"
|
|
cp "$file" "$backup"
|
|
echo "✓ Backed up $file to $backup"
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Function to test configurations
|
|
test_configurations() {
|
|
echo ""
|
|
echo "5. Testing Configurations..."
|
|
echo "==========================="
|
|
|
|
# Test sudo configuration
|
|
echo "Testing passwordless sudo..."
|
|
if sudo -u "$TARGET_USER" sudo -n true 2> /dev/null; then
|
|
echo "✓ Passwordless sudo test passed"
|
|
else
|
|
echo "! Passwordless sudo test failed (may require logout/login)"
|
|
fi
|
|
|
|
# Test lightdm configuration
|
|
echo "Testing LightDM configuration..."
|
|
if lightdm --test-mode --debug 2> /dev/null | grep -q "seat"; then
|
|
echo "✓ LightDM configuration test passed"
|
|
else
|
|
echo "! LightDM configuration test completed (check logs if issues occur)"
|
|
fi
|
|
|
|
# Verify user is in autologin group
|
|
if groups "$TARGET_USER" | grep -q autologin; then
|
|
echo "✓ User is in autologin group"
|
|
else
|
|
echo "! User may not be in autologin group"
|
|
fi
|
|
}
|
|
|
|
# Function to show security warnings
|
|
show_security_warnings() {
|
|
echo ""
|
|
echo "⚠️ SECURITY WARNINGS ⚠️"
|
|
echo "========================"
|
|
echo ""
|
|
echo "The following security changes have been made:"
|
|
echo ""
|
|
echo "1. PASSWORDLESS SUDO:"
|
|
echo " • User '$TARGET_USER' can now run ANY command as root without password"
|
|
echo " • This includes system-critical operations and file modifications"
|
|
echo " • Malicious software running as this user can gain full system access"
|
|
echo ""
|
|
echo "2. AUTO-LOGIN:"
|
|
echo " • System automatically logs in user '$TARGET_USER' on boot"
|
|
echo " • No password required to access the desktop environment"
|
|
echo " • Physical access to the machine = full user access"
|
|
echo ""
|
|
echo "3. RECOMMENDATIONS:"
|
|
echo " • Use full disk encryption to protect against physical access"
|
|
echo " • Ensure the system is in a physically secure location"
|
|
echo " • Consider using this only on personal/development machines"
|
|
echo " • Regularly monitor system logs for unauthorized access"
|
|
echo " • Keep the system updated and use a firewall"
|
|
echo ""
|
|
echo "4. TO DISABLE THESE SETTINGS:"
|
|
echo " • Remove passwordless sudo: sudo rm /etc/sudoers.d/99-passwordless-${TARGET_USER}"
|
|
echo " • Disable auto-login: sudo rm /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
|
echo " • Restart LightDM: sudo systemctl restart lightdm"
|
|
echo ""
|
|
}
|
|
|
|
# Function to show final instructions
|
|
show_final_instructions() {
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "Passwordless System Setup Complete"
|
|
echo "=========================================="
|
|
echo "Summary:"
|
|
echo "✓ Passwordless sudo configured for user: $TARGET_USER"
|
|
echo "✓ LightDM auto-login configured"
|
|
echo "✓ i3 session configured"
|
|
echo "✓ Additional auto-login settings applied"
|
|
echo ""
|
|
echo "Changes will take effect after:"
|
|
echo "• Logout/login for sudo changes"
|
|
echo "• System reboot for auto-login"
|
|
echo ""
|
|
echo "To verify after reboot:"
|
|
echo " sudo whoami # Should not ask for password"
|
|
echo " systemctl status lightdm # Should show auto-login active"
|
|
echo ""
|
|
echo "Configuration files created:"
|
|
echo " /etc/sudoers.d/99-passwordless-${TARGET_USER}"
|
|
echo " /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
|
echo " /etc/pam.d/lightdm-autologin"
|
|
echo ""
|
|
echo "IMPORTANT: Reboot recommended to activate all changes!"
|
|
}
|
|
|
|
# Main execution
|
|
configure_passwordless_sudo
|
|
configure_lightdm_autologin
|
|
configure_i3_session
|
|
configure_additional_settings
|
|
test_configurations
|
|
show_security_warnings
|
|
show_final_instructions
|
|
|
|
# Only offer reboot if --reboot flag was provided
|
|
if [[ $OFFER_REBOOT == true ]]; then
|
|
echo ""
|
|
echo "Would you like to reboot now to activate all changes?"
|
|
read -p "Reboot system now? (y/N): " -n 1 -r
|
|
echo
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Rebooting system in 5 seconds..."
|
|
sleep 5
|
|
reboot
|
|
else
|
|
echo "Remember to reboot when convenient to activate all changes."
|
|
fi
|
|
else
|
|
echo ""
|
|
echo "Setup completed successfully."
|
|
echo "Remember to reboot when convenient to activate all changes."
|
|
echo "To automatically prompt for reboot in the future, use: $0 --reboot"
|
|
fi
|