-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_computer.sh
More file actions
101 lines (79 loc) · 2.33 KB
/
init_computer.sh
File metadata and controls
101 lines (79 loc) · 2.33 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
#!/bin/bash
# Sets up the computer to how I like it. Installs dotfiles, sets up AUR, installs needed software from list, and more.
PROGNAME=${0##*/}
SCRIPT_DIR=$(dirname $0)
if [[ $EUID -eq 0 ]]; then
echo "This script must NOT be run as root" 1>&2
exit 1
fi
err() {
echo "$1" >&2
exit 1
}
need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
then err "need '$1' (command not found). Please install it and re-run the script."
fi
}
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
"$@"
need_ok "command failed: $*"
}
install_yay() {
if command -v yay > /dev/null 2>&1; then
echo "yay already installed. Nothing to do here."
return 0
fi
echo "Installing yay..."
# Install yay
(git clone https://aur.archlinux.org/yay.git /tmp/yay && cd /tmp/yay/ && makepkg -si)
echo "yay installed."
}
install_packages() {
echo "Installing packages"
# xargs < "${SCRIPT_DIR}/arch_packages.txt" pacaur -S --needed # This doesn't install all packages in the list for some weird reason.
# This will install all packages listed in the file arch_packages.txt (or ignore it if it's already installed)
for package_name in $(cat "${SCRIPT_DIR}/arch_packages.txt"); do
echo "Installing: ${package_name}"
yay -S --needed "${package_name}"
done
echo "Packages installed."
}
install_fonts() {
echo "Installing fonts"
stow "fonts" -t ~
echo "Updating font cache"
fc-cache -fv fonts/.fonts
echo "Fonts installed."
}
install_dotfiles() {
echo "Installing dotfiles"
if bash "install_dotfiles.sh"; then
echo "Dotfiles installed."
else
err "install_dotfiles.sh's exit code was not 0. There may have been an error. You should probably investigate."
fi
}
trap '
trap - INT # restore default INT handler
kill -s INT "$$"
' INT
echo "Initiating computer."
need_cmd git
sudo pacman -Syu
ensure install_yay
ensure install_packages
install_fonts
install_dotfiles
if [ $? -eq 0 ]; then
source ~/.bash_profile
echo "Computer ready for action. (But you should probably reboot to be sure.)"
else
err "There was an error somewhere (sorry). You should investigate."
fi