-
Notifications
You must be signed in to change notification settings - Fork 14
/
bootstrap.sh
executable file
·247 lines (192 loc) · 5.56 KB
/
bootstrap.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
# Arch Linux Bootstrap script
#
# Author: John Hammond
# Date: October 1st, 2019
#
# This script is meant to help set up and install all the tools
# and configuration that I need to get Arch Linux up and running
# quickly and easily.
NEW_USER=$1
# Define some colors for quick use...
COLOR_RED=$(tput setaf 1)
COLOR_GREEN=$(tput setaf 2)
COLOR_YELLOW=$(tput setaf 3)
COLOR_BLUE=$(tput setaf 4)
COLOR_MAGENTA=$(tput setaf 5)
COLOR_CYAN=$(tput setaf 6)
COLOR_WHITE=$(tput setaf 7)
BOLD=$(tput bold)
COLOR_RESET=$(tput sgr0)
function echo_red(){
echo "${COLOR_RED}${BOLD}$1${COLOR_RESET}"
}
function echo_green(){
echo "${COLOR_GREEN}${BOLD}$1${COLOR_RESET}"
}
function echo_yellow(){
echo "${COLOR_YELLOW}${BOLD}$1${COLOR_RESET}"
}
###############################################################
SUDO_DEPENDENCIES="sudo"
AUDIO_DEPENDENCES="pulseaudio pavucontrol"
GIT_DEPENDENCIES="git"
VIM_DEPENDENCIES="vim"
TMUX_DEPENDENCIES="tmux"
X_DEPENDENCIES="xorg-xinit xorg-server xorg-xrandr"
YAY_DEPENDENCINES="base-devel"
I3_DEPENDENCIES="i3 gnu-free-fonts"
TERMINATOR_DEPENDENCIES="terminator"
DMENU_DEPENDENCIES="dmenu"
FIREFOX_DEPENDENCIES="firefox"
DEPENDENCIES="\
$SUDO_DEPENDENCIES \
$AUDIO_DEPENDENCIES \
$GIT_DEPENDENCIES \
$VIM_DEPENDENCIES \
$TMUX_DEPENDENCIES \
$X_DEPENDENCIES \
$YAY_DEPENDENCIES \
$I3_DEPENDENCIES \
$TERMINATOR_DEPENDENCIES \
$DMENU_DEPENDENCIES \
$FIREFOX_DEPENDENCES \
"
#############################################################
POLYBAR_DEPENDENCIES="polybar"
YAY_INSTALL="\
$POLYBAR_DEPENDENCIES \
"
##############################################################
function create_new_user(){
pacman -Sy sudo --noconfirm
id -u $NEW_USER > /dev/null
if [ $? -eq 1 ]
then
echo_green "Creating new user $COLOR_BLUE$NEW_USER"
mkdir /home/$NEW_USER
useradd $NEW_USER
echo_yellow "Please set the password for $COLOR_BLUE$NEW_USER:"
passwd $NEW_USER
else
echo_green "New user already exists, using that account for everything"
fi
groupadd sudo
usermod -aG sudo $NEW_USER
sed -i 's/# %sudo/%sudo/g' /etc/sudoers
echo "$NEW_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
chown $NEW_USER:$NEW_USER /home/$NEW_USER
chown -R $NEW_USER:$NEW_USER $(pwd)
mv $(pwd) /home/$NEW_USER/archlinux
cd /home/$NEW_USER/archlinux
}
function cleanup(){
sed -i "s/$NEW_USER ALL=(ALL) NOPASSWD: ALL//g" /etc/sudoers
}
###############################################################
function configure_x(){
echo_green "Configuring X"
sudo -u $NEW_USER bash -c 'echo "exec i3" > ~/.xinitrc'
sudo -u $NEW_USER bash -c 'cp Xresources ~/.Xresources'
cp /etc/X11/xinit/.xinitrc
echo "needs_root_rights=yes" >> /etc/X11/Xwrapper.config
}
function configure_terminator(){
echo_green "Configuring Terminator"
sudo -u $NEW_USER bash -c 'mkdir -p ~/.config/terminator'
sudo -u $NEW_USER bash -c 'cp terminator_config ~/.config/terminator/config'
}
function configure_bashrc(){
echo_green "Getting default .bashrc"
sudo -u $NEW_USER bash -c 'cp bashrc ~/.bashrc'
sudo -u $NEW_USER bash -c '. ~/.bashrc'
cp bashrc /etc/bash.bashrc
}
function configure_tmux(){
sudo -u $NEW_USER bash -c "echo 'source \"\$HOME/.bashrc\"' > ~/.bash_profile"
sudo -u $NEW_USER bash -c 'cp tmux.conf ~/.tmux.conf'
}
function configure_vim(){
echo_green "Configuring vim..."
sudo -u $NEW_USER bash -c 'curl -sfLo ~/.vim/autoload/plug.vim --create-dirs "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"'
sudo -u $NEW_USER bash -c 'cp vimrc ~/.vimrc'
sudo -u $NEW_USER bash -c 'vim ~/.vimrc +PlugInstall +q +q'
sudo -u $NEW_USER bash -c 'rm ~/.vimrc'
# Add for the root user as well..
curl -sfLo ~/.vim/autoload/plug.vim --create-dirs "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
cp vimrc /etc/vimrc
vim /etc/vimrc +PlugInstall +q +q
}
function configure_git(){
sudo -u $NEW_USER bash -c 'git config --global core.editor "vim"'
sudo -u $NEW_USER bash -c 'git config --global user.email "[email protected]"'
sudo -u $NEW_USER bash -c 'git config --global user.name "John Hammond"'
}
function configure_pacman(){
cp mirrorlist /etc/pacman.d/mirrorlist
}
##############################################################
function prepare_opt(){
chown $NEW_USER:$NEW_USER /opt
}
function install_yay(){
pacman -Sy --needed base-devel --noconfirm
pushd /opt/
git clone https://aur.archlinux.org/yay.git
chown $NEW_USER:$NEW_USER /opt/yay
cd yay
sudo -u $NEW_USER bash -c 'cd /opt/yay/ && yes|makepkg -si'
popd
sudo -u $NEW_USER bash -c 'yes|yay'
}
###############################################################
function set_timezone(){
echo_green "Setting timezone to EST5EDT"
ln -sf /usr/share/zoneinfo/EST5EDT /etc/localtime
hwclock --systohc
}
function set_locale(){
echo_green "Setting locale"
sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
locale-gen
}
function set_hostname(){
echo_green "Setting hostname"
echo arch > /etc/hostname
cat <<EOF >/etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 arch.localdomain arch
EOF
}
function pre_install(){
set_timezone
set_locale
set_hostname
}
function install_niceties(){
pacman -Sy $DEPENDENCIES --noconfirm --color=always
}
function install_more_niceties(){
yay -Sy $YAY_INSTALL --noconfirm
}
if [ "$1" == "" ]
then
echo_red "You must supply a username to use."
echo "usage: $0 <new_username>"
exit
fi
pre_install
create_new_user
configure_pacman
install_niceties
configure_x
configure_terminator
configure_bashrc
configure_tmux
configure_vim
configure_git
prepare_opt
install_yay
install_more_niceties
cleanup