-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.sh
62 lines (52 loc) · 1.3 KB
/
helpers.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
#
# Utility functions used by the scripts.
#
check_root() {
if ((EUID)); then
echo -e "${RED}This script must be run as root.${NC}"
exit 1
fi
}
check_internet_connection() {
if ! wget -q --spider https://google.com ; then
echo -e "${RED}Not connected to the Internet.${NC}"
exit 1
fi
}
check_uefi() {
if ! [ -d /sys/firmware/efi ] ; then
echo -e "${RED}This script requires the system to boot in UEFI mode.${NC}"
exit 1
fi
}
has_nvidia_gpu() {
lspci | grep -qie "VGA.*NVIDIA"
return $?
}
arch_chroot() {
arch-chroot /mnt /bin/bash -c "${1}"
}
installation_canceled() {
echo -e "${RED}Installation canceled.${NC}"
exit 1
}
# Wrap one or more commands around `begin_checked_section` and
# `end_checked_section` to exit the script early if any of the commands fail.
#
# Example:
# $ ls --badoption <-- Will fail, but script will continue
# $ begin_checked_section
# $ ls
# $ ls --badoption <-- Will fail, then script will exit
# $ end_checked_section
#
# echo an error message before exiting
trap '[ $? -gt 0 ] && echo "Previous command failed with exit code $?."' EXIT
# Exit script if any subsequent commands fail
begin_checked_section() {
set -e
}
# Restore default behavior
end_checked_section() {
set +e
}