blob: b6c931939743283a6415b53e1231aea961680e46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#!/bin/bash
#Arch Linux setup after fresh install.
# Check for root privileges
[ "$(id -u)" -ne 0 ] && echo "This script must be run as root. Try using sudo." && exit 1
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
# Function for logging sections
log_section() {
echo "=============== $1 ==============="
}
# Function to handle errors
handle_error() {
echo "Error: $1" >&2
exit 1
}
cd
log_section "WSL Settings"
# Check if wsl.conf exists and create/modify it accordingly
if [ -f "/etc/wsl.conf" ]; then
# Check if entries already exist to avoid duplication
echo -e "\n[user]\ndefault=admin" >> /etc/wsl.conf
echo -e "\n[interop]\nenabled=true" >> /etc/wsl.conf
# Set up root password.
echo "Setting root password..."
passwd
# Uncomment en_US.UTF-8 locale in locale.gen
sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
# Generate the locale
locale-gen
# Set the system locale
echo "LANG=en_US.UTF-8" > /etc/locale.conf
fi
log_section "Basic Package Installation"
$SCRIPT_DIR/archpackages.sh || handle_error "Package installation failed"
#Additional packages for WSL
if [ -f "/etc/wsl.conf" ]; then
pacman -S --noconfirm \
mesa vulkan-dzn
fi
pacman -Rns $(pacman -Qtdq) --noconfirm
systemctl start cronie
systemctl enable cronie
log_section "Zsh Configuration"
# Create plugins directory if it doesn't exist
mkdir -p /usr/share/zsh/plugins/{zsh-users/zsh-syntax-highlighting,zsh-autosuggestions}
# Clone zsh plugins if they don't exist
git clone https://github.com/zsh-users/zsh-syntax-highlighting /usr/share/zsh/plugins/zsh-syntax-highlighting/
git clone https://github.com/zsh-users/zsh-autosuggestions /usr/share/zsh/plugins/zsh-autosuggestions/
# Setup zsh history for root
mkdir -p /root/.cache/zsh && touch /root/.cache/zsh/history
log_section "Admin Sudo User Creation"
# Create admin user if it doesn't exist
if ! id -u admin &>/dev/null; then
useradd -m -s /bin/zsh admin || handle_error "Failed to create admin user"
echo "User 'admin' created."
else
echo "User 'admin' already exists, continuing..."
fi
# Create zsh history directory for admin
mkdir -p /home/admin/.cache/zsh && touch /home/admin/.cache/zsh/history
chown -R admin:admin /home/admin/.cache
# Add admin to wheel group if not already added
if ! groups admin | grep -q wheel; then
usermod -aG wheel admin || handle_error "Failed to add user to wheel group"
echo "Added 'admin' to wheel group."
fi
# Configure sudo access more safely
log_section "Configuring sudo access"
if ! grep -q "^%wheel\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL" /etc/sudoers; then
echo "%wheel ALL=(ALL) ALL" | EDITOR='tee -a' visudo || handle_error "Failed to modify sudoers file"
echo "Added wheel group to sudoers file."
else
echo "Wheel group already enabled in sudoers."
fi
# Set password for admin user
echo "Setting password for user 'admin'..."
passwd admin || handle_error "Failed to set password for admin user"
log_section "Dotfiles Setup"
# Clone dotfiles if they don't exist
if [ ! -d "/home/admin/dotfiles" ]; then
git clone https://git.optics-design.com/lindotfiles /home/admin/dotfiles || handle_error "Failed to clone dotfiles"
chown -R admin:admin /home/admin/dotfiles
fi
su - admin -c "git config --global alias.ac 'commit -am'" || handle_error "Failed to set git alias"
# Apply dotfiles
rm /home/admin/.bashrc
rm /root/.config/go/telemetry/mode
cd /home/admin/dotfiles && stow -t /root . || handle_error "Failed to stow dotfiles for root"
su - admin -c "cd ~/dotfiles && stow ." || handle_error "Failed to stow dotfiles for admin"
echo -e "export USERPROFILE=\nexport SYNC=" >> /home/admin/.env_variables
echo "Setup completed successfully!"
|