-
Notifications
You must be signed in to change notification settings - Fork 0
/
archrice.sh
executable file
·299 lines (265 loc) · 8.51 KB
/
archrice.sh
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
296
297
298
299
#!/bin/sh
# Custom script for automatic Arch Linux configuration after base install
# Created by: Kostas Ereksonas
# License: GPLv3
# ------------------
# | Global variables |
# ------------------
homedir=
username=
# ------
# | Misc |
# ------
function welcomeMsg() {
dialog --title "Arch auto config" --msgbox "Press Ok to start" 0 0
}
function exitMsg() {
dialog --title "Arch auto config" --msgbox "Setup done" 0 0
rm -r /root/Archrice/ && return 1
}
# --------
# | Errors |
# --------
function installError() {
title="Error Installing Package"
dialog --title "$title" --yesno "Could not install $1. Retry?" 0 0
if [ $? == 0 ]; then
dialog --title "$title" --infobox "Retrying to install $1 in 5 seconds." 0 0 && sleep 5 && return 0
else
dialog --title "$title" --msgbox "Package $1 not installed" 0 0 && return 1
fi
}
# ---------------
# | Configuration |
# ---------------
# Create and configure a new system user
function createUser() {
# Pick an username (cannot be empty)
while [ -z $name ]; do
name=$(dialog --stdout --title "User Creation" --inputbox "User Name:" 0 0)
if [ -z $name ]; then
dialog --title "User Creation" --msgbox "Username cannot be empty. Try again" 0 0
else
useradd -m $name && homedir=/home/$name && username=$name
fi
done
# Choose groups to add the user to
groups=$(dialog --stdout --title "User Creation" \
--checklist "Choose groups where the user $username should be added to:" 0 0 0 \
wheel wheel on \
adm adm off \
ftp ftp off \
games games off \
http http off \
log log off \
rfkill rfkill off \
sys sys off \
systemd-journal systemd-journal off \
uucp uucp off \
libvirt libvirt on \
dbus dbus off \
kmem kmem off \
locate locate off \
lp lp off \
mail mail off \
nobody nobody off \
proc proc off \
root root off \
smmsp smmsp off \
tty tty off \
utmp utmp off \
audio audio on \
disk disk off \
floppy floppy off \
input input off \
kvm kvm off \
video video on \
optical optical on \
storage storage on | sed 's/ /,/g') && usermod -aG $groups $name
# Create a password for new user
while [ $password != $passcheck ]; do
password=$(dialog --stdout --title "User Creation" --passwordbox "Enter password for user $name:" 0 0)
passcheck=$(dialog --stdout --title "User Creation" --passwordbox "Re-enter password for user $name:" 0 0)
if [ $password != $passcheck ]; then
unset $passcheck && userError $name || break
else
unset $passcheck && echo "$name:$password" | chpasswd
fi
done
}
function createDirectories() {
dialog --title "Creating Directories" --infobox "Creating directories" 0 0 && sleep 2
cd $homedir/
while read dirname others; do
mkdir -p "$dirname"
done < /root/Archrice/directories.txt
}
# Editing pacman configuration file
function configurePacman() {
dialog --title "Configuring Pacman" --infobox "Updating Pacman configuration file" 0 0 && sleep 2
cd /etc/ && sed -i '33s/#//' pacman.conf; sed -i '37s/#//' pacman.conf; sed -i '93s/#//' pacman.conf; sed -i '94s/#//' pacman.conf
}
# Install system fonts
function installFonts() {
title="Font Configuration"
dialog --title "$title" --infobox "Installing fonts" 0 0 && sleep 2
cd $homedir/.local/share/fonts/
dialog --title "$title" --infobox "Installing Hack Nerd Font" 0 0
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Hack.zip
7z x Hack.zip && rm Hack.zip
}
# Configure pass utility to store passwords
function configurePass () {
logfile=/var/log/archrice.log
title="Configuring Pass"
dialog --title "$title" --msgbox "Now you will be prompted to create a GPG keypair." 0 0
# Change terminal ownership to $username to get the passphrase for GPG key, as sugessted here:
# https://github.com/MISP/MISP/issues/3702#issuecomment-443371431
chown -R $username:$username /dev/tty1
runuser -u $username -- gpg --full-gen-key && sleep 5
email=$(grep @ $logfile | tail -1 | cut -d " " -f 25 | tr -d "<>")
dialog --title "$title" --infobox "Initializing password store for $email" 0 0 && sleep 2
runuser -u $username -- pass init $email
chown -R root:root /dev/tty1
rm $logfile
}
# Configure system scripts
function configureScripts() {
cp /root/Archrice/.local/bin/* $homedir/.local/bin/
cp /root/Archrice/dotfiles/system_scripts/* /usr/local/bin/
}
function cloneDotfiles() {
cd /root/Archrice/dotfiles/
cp .xinitrc .xprofile .bashrc $homedir/
cp -r .newsboat/ $homedir/
cp pixmaps/* /usr/share/pixmaps/
cp xorg.conf.d/* /etc/X11/xorg.conf.d/
dotfiles=(dunst gsimplecal mutt picom ranger)
for file in ${dotfiles[@]}; do
cp -r $file $homedir/.config/
done
}
function configureNeovim() {
mkdir $homedir/.config/nvim/
cp /root/Archrice/dotfiles/init.vim $homedir/.config/nvim/
cd $homedir/.config/nvim/
mkdir autoload/ bundle/ colors/
curl -LSso autoload/pathogen.vim https://tpo.pe/pathogen.vim
cd bundle/
vim_plugins=(preservim/nerdtree \
vim-airline/vim-airline \
vim-airline/vim-airline-themes \
altercation/vim-colors-solarized \
tmsvg/pear-tree)
for plugin in ${vim_plugins[@]}; do
git clone https://github.com/$plugin.git
done
cd ../colors/
themes_solarized=(solarized8 solarized8_flat solarized8_high solarized8_low)
for theme in ${themes_solarized[@]}; do
wget https://raw.githubusercontent.com/lifepillar/vim-solarized8/master/colors/$theme.vim
done
themes_gruvbox=(gruvbox8 gruvbox8_hard gruvbox8_soft)
for theme in ${themes_gruvbox[@]}; do
wget https://raw.githubusercontent.com/lifepillar/vim-gruvbox8/master/colors/$theme.vim
done
}
# Recursively set ownership of users' home directory
function configureOwnership() {
cd /home/ && chown -R $username:$username $homedir/
}
function configureVM() {
cd /var/lib/libvirt/images/
title="Local File Download"
ip=$(dialog --stdout --title "$title" --inputbox "Enter IP address to download from" 0 0)
port=$(dialog --stdout --title "$title" --inputbox "Enter port for downloading files" 0 0)
while [ $? == 0 ]; do
file=$(dialog --stdout --title "$title" --inputbox "Enter the name of a file you want to download" 0 0)
wget -nc http://$ip:$port/$file
dialog --title "$title" --yesno "Download another file?" 0 0
if [ $? != 0 ]; then break; fi
done
}
function installPureline() {
cd $homedir/Documents/git/
git clone https://github.com/chris-marsh/pureline.git
mkdir $homedir/pureline/
cd pureline/
cp -r pureline segments/ $homedir/pureline/
cp configs/powerline_full_256col.conf $homedir/.pureline.conf
}
# --------------
# | Installation |
# --------------
function installDependencies() {
echo "Installing dependencies"
pacman --no-confirm --needed -S - < /root/Archrice/package_lists/dependencies.txt
}
function updateSystem() {
pacman -Syyu
}
function install() {
pacman --noconfirm --needed -S $1
}
function installPackages() {
readarray -t packages < package_lists/pacman_packages.txt
for package in ${packages[@]}; do
until dialog --title "Installing packages" --infobox "Installing $package" 0 0 && install $package; do
installError $package || break
done
done
}
function installYAY() {
title="Installing AUR Helper" && isAUR="False" && isGIT="True" && MAKE="False"
cd $homedir/Documents/aur/ && git clone https://aur.archlinux.org/yay.git
chown -R $username:$username $homedir/Documents/aur/yay
dialog --title "$title" --infobox "Installing yay AUR helper" 0 0
cd $homedir/Documents/aur/yay/
sudo -u $username makepkg --noconfirm -si
dialog --title "$title" --infobox "AUR helper installed" 0 0 && sleep 1
}
function installAURPackages() {
yay --noconfirm --needed -S - < /root/Archrice/package_lists/aur_packages.txt
}
function installKernel() {
dialog --title "Kernel Install" --infobox "Installing linux-tkg kernel " 0 0 && sleep 1
cd $homedir/Documents/git/
git clone https://github.com/Frogging-Family/linux-tkg.git
cd linux-tkg/
./install.sh install
}
function installSD() {
dialog --title "Stable Diffusion Install" --infobox "Installing Automatic1111 UI for Stable Diffusion" 0 0 && sleep 1
chown -R $username:$username /usr/local/games/
cd /usr/local/games/
git clone https://github.com/KostasEreksonas/stable-diffusion-webui.git
}
function installLlama() {
curl -fsSL https://ollama.com/install.sh | sh
}
# -------------
# | Main Script |
# -------------
while [ $? == 0 ]; do
installDependencies
welcomeMsg
createUser
createDirectories
configurePacman
updateSystem
installPackages
installYAY
installAURPackages
installKernel
installSD
installLlama
installPureline
configureVM
installFonts
configurePass
configureScripts
cloneDotfiles
configureNeovim
configureOwnership
exitMsg
done