forked from ChrisTitusTech/mybash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_setup.sh
executable file
·134 lines (124 loc) · 4.7 KB
/
compile_setup.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
#!/bin/sh -e
# Define color variables for output
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
RED='\033[1;31m'
BLUE='\033[1;34m'
RC='\033[0m' # Reset color
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Define package manager and escalation tool
PACKAGER=""
ESCALATION_TOOL=""
# Function to check the environment
checkEnv() {
echo "${BLUE}Checking environment...${RC}"
# Check for supported package managers
if command_exists pacman; then
PACKAGER="pacman"
elif command_exists apt-get; then
PACKAGER="apt-get"
elif command_exists nala; then
PACKAGER="nala"
elif command_exists dnf; then
PACKAGER="dnf"
elif command_exists zypper; then
PACKAGER="zypper"
else
echo "${RED}No supported package manager found.${RC}"
exit 1
fi
# Determine the escalation tool
if command_exists sudo; then
ESCALATION_TOOL="sudo"
elif command_exists doas; then
ESCALATION_TOOL="doas"
else
ESCALATION_TOOL="su -c"
fi
echo "${GREEN}Using $PACKAGER as package manager and $ESCALATION_TOOL for privilege escalation.${RC}"
}
# Function to check if an AUR helper is available
checkAURHelper() {
if [ "$PACKAGER" = "pacman" ]; then
if command_exists yay; then
AUR_HELPER="yay"
elif command_exists paru; then
AUR_HELPER="paru"
else
echo "${RED}No AUR helper found. Please install yay or paru.${RC}"
exit 1
fi
else
AUR_HELPER=""
fi
}
# Install dependencies based on the package manager
installDepend() {
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
echo "${YELLOW}Installing dependencies...${RC}"
case $PACKAGER in
pacman)
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
echo "${BLUE}Enabling multilib repository...${RC}"
echo "[multilib]" | $ESCALATION_TOOL tee -a /etc/pacman.conf
echo "Include = /etc/pacman.d/mirrorlist" | $ESCALATION_TOOL tee -a /etc/pacman.conf
$ESCALATION_TOOL "$PACKAGER" -Syu
else
echo "${GREEN}Multilib is already enabled.${RC}"
fi
echo "${BLUE}Installing dependencies using AUR helper...${RC}"
$AUR_HELPER -S --needed --noconfirm "$DEPENDENCIES"
;;
apt-get)
COMPILEDEPS='build-essential'
echo "${BLUE}Updating package lists...${RC}"
$ESCALATION_TOOL "$PACKAGER" update
echo "${BLUE}Adding i386 architecture and installing dependencies...${RC}"
$ESCALATION_TOOL dpkg --add-architecture i386
$ESCALATION_TOOL "$PACKAGER" update
if ! $ESCALATION_TOOL "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS; then
echo "${RED}Unable to locate packages. Please check your sources list and try again.${RC}"
exit 1
fi
;;
nala)
COMPILEDEPS='build-essential'
echo "${BLUE}Updating package lists...${RC}"
$ESCALATION_TOOL "$PACKAGER" update
echo "${BLUE}Adding i386 architecture and installing dependencies...${RC}"
$ESCALATION_TOOL dpkg --add-architecture i386
$ESCALATION_TOOL "$PACKAGER" update
if ! $ESCALATION_TOOL "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS; then
echo "${RED}Unable to locate packages. Please check your sources list and try again.${RC}"
exit 1
fi
;;
dnf)
COMPILEDEPS='@development-tools'
echo "${BLUE}Updating package lists...${RC}"
$ESCALATION_TOOL "$PACKAGER" update
echo "${BLUE}Enabling powertools and installing dependencies...${RC}"
$ESCALATION_TOOL "$PACKAGER" config-manager --set-enabled powertools
$ESCALATION_TOOL "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
$ESCALATION_TOOL "$PACKAGER" install -y glibc-devel.i686 libgcc.i686
;;
zypper)
COMPILEDEPS='patterns-devel-base-devel_basis'
echo "${BLUE}Refreshing repositories and installing dependencies...${RC}"
$ESCALATION_TOOL "$PACKAGER" refresh
$ESCALATION_TOOL "$PACKAGER" --non-interactive install $DEPENDENCIES $COMPILEDEPS
$ESCALATION_TOOL "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit
;;
*)
echo "${BLUE}Installing dependencies using $PACKAGER...${RC}"
$ESCALATION_TOOL "$PACKAGER" install -y $DEPENDENCIES
;;
esac
}
# Execute functions
checkEnv
checkAURHelper
installDepend