forked from ChrisTitusTech/mybash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastfetch.sh
executable file
·128 lines (113 loc) · 3.69 KB
/
fastfetch.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
#!/bin/sh -e
# Define color variables
RC='\033[0m' # Reset
RED='\033[31m' # Red
GREEN='\033[32m' # Green
YELLOW='\033[33m' # Yellow
CYAN='\033[36m' # Cyan
# Function to check if a command exists
command_exists() {
command -v "$1" > /dev/null 2>&1
}
checkEnv() {
## Check for requirements.
REQUIREMENTS='curl groups sudo'
for req in $REQUIREMENTS; do
if ! command_exists "$req"; then
printf "${RED}To run me, you need: $REQUIREMENTS${RC}\n"
exit 1
fi
done
## Check Package Handler
PACKAGEMANAGER='apt dnf pacman'
for pgm in $PACKAGEMANAGER; do
if command_exists "$pgm"; then
PACKAGER="$pgm"
printf "Using $pgm\n"
break
fi
done
if [ -z "$PACKAGER" ]; then
printf "${RED}Can't find a supported package manager${RC}\n"
exit 1
fi
if command_exists sudo; then
SUDO_CMD="sudo"
elif command_exists doas && [ -f "/etc/doas.conf" ]; then
SUDO_CMD="doas"
else
SUDO_CMD="su -c"
fi
printf "Using $SUDO_CMD as privilege escalation software\n"
## Check if the current directory is writable.
GITPATH=$(dirname "$(realpath "$0")")
if [ ! -w "$GITPATH" ]; then
printf "${RED}Can't write to $GITPATH${RC}\n"
exit 1
fi
## Check SuperUser Group
SUPERUSERGROUP='wheel sudo root'
for sug in $SUPERUSERGROUP; do
if groups | grep -q "$sug"; then
SUGROUP="$sug"
printf "Super user group $SUGROUP\n"
break
fi
done
## Check if member of the sudo group.
if ! groups | grep -q "$SUGROUP"; then
printf "${RED}You need to be a member of the sudo group to run me!${RC}\n"
exit 1
fi
}
checkEscalationTool() {
## Check for escalation tools.
if [ -z "$ESCALATION_TOOL_CHECKED" ]; then
ESCALATION_TOOLS='sudo doas'
for tool in ${ESCALATION_TOOLS}; do
if command_exists "${tool}"; then
ESCALATION_TOOL=${tool}
printf "%b\n" "${CYAN}Using ${tool} for privilege escalation${RC}"
ESCALATION_TOOL_CHECKED=true
return 0
fi
done
printf "%b\n" "${RED}Can't find a supported escalation tool${RC}"
exit 1
fi
}
installFastfetch() {
if ! command_exists fastfetch; then
printf "%b\n" "${YELLOW}Installing Fastfetch...${RC}"
case "$PACKAGER" in
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm fastfetch
;;
apt|apt-get)
"$ESCALATION_TOOL" "$PACKAGER" update
"$ESCALATION_TOOL" "$PACKAGER" install -y wget
wget -O fastfetch.deb https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-amd64.deb
"$ESCALATION_TOOL" dpkg -i fastfetch.deb
"$ESCALATION_TOOL" "$PACKAGER" install -f
rm fastfetch.deb
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y fastfetch
;;
esac
else
printf "%b\n" "${GREEN}Fastfetch is already installed.${RC}"
fi
}
setupFastfetchConfig() {
printf "%b\n" "${YELLOW}Copying Fastfetch config files...${RC}"
if [ -d "${HOME}/.config/fastfetch" ] && [ ! -d "${HOME}/.config/fastfetch-bak" ]; then
cp -r "${HOME}/.config/fastfetch" "${HOME}/.config/fastfetch-bak"
fi
mkdir -p "${HOME}/.config/fastfetch/"
curl -sSLo "${HOME}/.config/fastfetch/config.jsonc" https://raw.githubusercontent.com/ChrisTitusTech/mybash/main/config.jsonc
}
checkEnv
checkEscalationTool
installFastfetch
setupFastfetchConfig