-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoinstall.sh
More file actions
executable file
·296 lines (233 loc) · 9.18 KB
/
Copy pathautoinstall.sh
File metadata and controls
executable file
·296 lines (233 loc) · 9.18 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
# https://github.com/ramirocabral/dotfiles
# Inspired by Luke Smith LARBS script
### VARIABLES ###
aurhelper="paru"
USERNAME="$1"
[ -z "$USERNAME" ] && echo "Error: Username not provided." && exit 1
HOMEDIR="/home/$USERNAME"
REPODIR="$HOMEDIR/.local/src"
CONFIG_FILE="/tmp/arch_install_config"
PROGSFILE="$HOMEDIR/progs.csv"
# Store failed installations
failed_items=()
### FUNCTIONS ###
error(){
clear
echo -e "ERROR : $1"
exit 1
}
configuration_wizard() {
dialog --title "Hardware Configuration" \
--form "Set environment variables for ~/.config/zsh/.local" \
15 60 4 \
"LAN Interface:" 1 1 "wlo1" 1 20 20 0 \
"System Class:" 2 1 "laptop" 2 20 20 0 \
2> "$CONFIG_FILE.vars"
# Read form results
LAN_IF=$(sed -n 1p "$CONFIG_FILE.vars")
SYS_CLASS=$(sed -n 2p "$CONFIG_FILE.vars")
# Select Features (Checklist)
cmd=(dialog --separate-output --checklist "Select features to configure/install:" 22 76 16)
options=(
"SMB" "Mount NAS Server (Samba)" off
"CUPS" "Install & Configure Printer" off
"TMUX" "Install Tmux Plugins (TPM)" on
"ZSH" "Set ZSH as default shell" on
)
features_choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
clear
}
generate_local_env() {
echo "Generating .local environment file..."
sudo -u "$USERNAME" mkdir -p "$HOMEDIR/.config/zsh"
cat <<EOF > "$HOMEDIR/.config/zsh/.local"
# File generated automatically by autoinstall.sh
export LAN_INTERFACE="$LAN_IF"
export SYSTEM_CLASS="$SYS_CLASS"
EOF
chown "$USERNAME:$USERNAME" "$HOMEDIR/.config/zsh/.local"
echo "Saved env vars: LAN=$LAN_IF, CLASS=$SYS_CLASS"
}
setup_smb() {
SMB_USER=$(dialog --title "Samba Setup" --inputbox "Enter Samba Server User:" 8 40 --output-fd 1)
SMB_PASS=$(dialog --title "Samba Setup" --passwordbox "Enter Samba Server Password:" 8 40 --output-fd 1)
[ -z "$SMB_USER" ] && echo "Skipping SMB setup (empty user)." && return
echo "username=$SMB_USER" >> "$HOMEDIR/.credentials"
echo "password=$SMB_PASS" >> "$HOMEDIR/.credentials"
echo "domain=WORKGROUP" >> "$HOMEDIR/.credentials"
chmod 600 "$HOMEDIR/.credentials"
chown "$USERNAME:$USERNAME" "$HOMEDIR/.credentials"
sudo mkdir -p /mnt/nas/ramiro /mnt/nas/public
echo "//nas.lan/public /mnt/nas/public cifs credentials=$HOMEDIR/.credentials,uid=1000,gid=100,dir_mode=0770,file_mode=0660 0 2" >> /etc/fstab
echo "//nas.lan/ramiro /mnt/nas/ramiro cifs credentials=$HOMEDIR/.credentials,uid=1000,gid=100,dir_mode=0770,file_mode=0660 0 3" >> /etc/fstab
echo "Samba configured."
}
# --- INSTALLATION FUNCTIONS ---
install_aur(){
sudo -u "$USERNAME" mkdir -p "$REPODIR/$1"
sudo -u "$USERNAME" git -C "$REPODIR" clone --depth 1 --no-tags -q "https://aur.archlinux.org/$1.git" "$REPODIR/$1"
cd "$REPODIR/$1" || return 1
sudo -u "$USERNAME" makepkg --noconfirm -si "$REPODIR/$1" >/dev/null 2>&1
return $?
}
installpkg(){
pacman --noconfirm --needed -S "$1" >/dev/null 2>&1
return $?
}
aurinstall(){
echo "$aurinstalled" | grep -q "^$1$" && return 0
sudo -u "$USERNAME" $aurhelper -S --noconfirm "$1" >/dev/null 2>&1
return $?
}
gitinstall(){
progname="${1##*/}"
echo "$gitinstalled" | grep -q "^$progname$" && return 0
progname="${progname%.git}"
dir="$REPODIR/$progname"
sudo -u "$USERNAME" git -C "$REPODIR" clone --depth 1 --single-branch \
--no-tags -q "$1" "$dir" ||
{
cd "$dir" || return 1
sudo -u "$USERNAME" git pull --force origin master
}
cd "$dir" || return 1
}
pipinstall(){
[ -x "$(command -v "pip")" ] || installpkg python-pip >/dev/null 2>&1
echo "$pipinstalled" | grep -q "^$1$" && return 0
pip install --break-system-packages $1 >/dev/null 2>&1
return $?
}
install_tmux_plugins(){
echo "Installing Tmux plugins..."
sudo -u "$USERNAME" git clone https://github.com/tmux-plugins/tpm "$HOMEDIR/.config/tmux/plugins/tpm" || {
echo "Failed to clone tpm"
return 1
}
[ -d "$HOMEDIR/.config/tmux/plugins/tpm" ] && \
sudo -u "$USERNAME" "$HOMEDIR/.config/tmux/plugins/tpm/bin/install_plugins"
}
# --- MAIN INSTALL LOOP ---
installationloop(){
# Check if file exists
if [ ! -f "$PROGSFILE" ]; then
echo "Programs file not found at $PROGSFILE"
return
fi
aurinstalled="$(pacman -Qqm 2>/dev/null)"
gitinstalled="$(ls "$REPODIR" 2>/dev/null)"
pipinstalled="$(pip list 2>/dev/null | awk '{print $1}' | tail -n +3)"
options=()
while IFS=, read -r -u 9 tag program desc; do
# Cleanup variables (Trim spaces & remove Windows carriage returns)
tag=$(echo "$tag" | xargs | tr -d '\r')
program=$(echo "$program" | xargs | tr -d '\r')
desc=$(echo "$desc" | xargs | tr -d '\r')
[[ "$tag" =~ ^#.*$ ]] && continue
[[ -z "$program" ]] && continue
options+=("$program" "$desc" "on")
done 9< "$PROGSFILE"
# --separate-output ensures clean newlines instead of quoted strings
selected_programs=$(dialog --title "Software Selector" \
--separate-output \
--checklist "Space: Select/Deselect | Enter: Confirm" \
25 80 15 \
"${options[@]}" \
3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then
echo "Program selection cancelled by user."
return
fi
clear
echo "##### Starting Installation #####"
while IFS=, read -r -u 9 tag program desc; do
# Cleanup again to ensure matching
tag=$(echo "$tag" | xargs | tr -d '\r')
program=$(echo "$program" | xargs | tr -d '\r')
[[ "$tag" =~ ^#.*$ ]] && continue
[[ -z "$program" ]] && continue
# grep -F (fixed string) -x (exact line match) -q (quiet)
if echo "$selected_programs" | grep -F -x -q "$program"; then
echo "--> Installing: $program"
success=0
# Execute installer closing stdin (< /dev/null)
case "$tag" in
"p") installpkg "$program" < /dev/null || success=1 ;;
"g") gitinstall "$program" < /dev/null || success=1 ;;
"a") aurinstall "$program" < /dev/null || success=1 ;;
"i") pipinstall "$program" < /dev/null || success=1 ;;
*) echo "Unknown tag '$tag' for $program"; success=1 ;;
esac
if [ $success -ne 0 ]; then
echo " [X] FAILED: $program"
failed_items+=("$program")
else
echo " [OK] Success"
fi
fi
done 9< "$PROGSFILE"
}
### SCRIPT EXECUTION ###
configuration_wizard
# Apply Hardware Config (generate .local)
generate_local_env
# Sudo Setup
[ -f /etc/sudoers.pacnew ] && cp /etc/sudoers.pacnew /etc/sudoers
trap 'rm -f /etc/sudoers.d/larbs-temp' HUP INT QUIT TERM PWR EXIT
echo "%wheel ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/larbs-temp
# Install AUR Helper
echo "Installing AUR Helper ($aurhelper)..."
install_aur "${aurhelper}" || error "Failed to install AUR helper"
# Run Installation Loop
installationloop
# Apply Feature Configs
if echo "$features_choices" | grep -q "ZSH"; then
echo "Setting ZSH as default shell..."
chsh -s /bin/zsh "$USERNAME" >/dev/null 2>&1
sudo -u "$USERNAME" mkdir -p "$HOMEDIR/.cache/zsh/"
fi
if echo "$features_choices" | grep -q "TMUX"; then
install_tmux_plugins
fi
if echo "$features_choices" | grep -q "CUPS"; then
echo "Enabling CUPS service..."
systemctl enable --now cups.service
fi
if echo "$features_choices" | grep -q "SMB"; then
setup_smb
fi
echo "Creating user directories..."
sudo -u "$USERNAME" mkdir -p "$HOMEDIR/Screenshots" "$HOMEDIR/Desktop" "$HOMEDIR/Documents" "$HOMEDIR/projects"
if [ -f "$HOMEDIR/librewolf.overrides.cfg" ]; then
sudo -u "$USERNAME" mkdir -p "$HOMEDIR/.librewolf"
ln -sf "$HOMEDIR/librewolf.overrides.cfg" "$HOMEDIR/.librewolf/librewolf.overrides.cfg"
fi
#point ~/.kube/kubie.yaml to .config/kubie/kubie.yaml
echo "Configuring kubie..."
if [ -f "$HOMEDIR/.config/kubie/kubie.yaml" ]; then
sudo -u "$USERNAME" mkdir -p "$HOMEDIR/.kube"
ln -sf "$HOMEDIR/.config/kubie/kubie.yaml" "$HOMEDIR/.kube/kubie.yaml"
fi
systemctl enable lightdm
brave --enable-features=WebRTCPipeWireCapturer
# 8. FINAL REPORT
clear
echo "########################################"
echo " INSTALLATION COMPLETE"
echo "########################################"
if [ ${#failed_items[@]} -ne 0 ]; then
msg="The following packages FAILED to install:\n\n"
for item in "${failed_items[@]}"; do
msg+="- $item\n"
done
msg+="\nPlease check the logs manually."
dialog --title "Installation Warnings" --colors --msgbox "\Z1$msg" 20 60
# Also print to terminal just in case
echo -e "\nWARNING: The following packages failed to install:"
printf '%s\n' "${failed_items[@]}"
else
dialog --title "Success" --msgbox "All selected programs were installed successfully!" 10 50
echo "All systems operational."
fi
echo -e "\nDONE! Please reboot your system."