2024-07-14 03:02:24 +01:00
|
|
|
#!/bin/sh
|
|
|
|
RC='\033[0m'
|
|
|
|
RED='\033[31m'
|
|
|
|
YELLOW='\033[33m'
|
|
|
|
GREEN='\033[32m'
|
2024-07-13 02:57:34 +01:00
|
|
|
|
|
|
|
# Check if the home directory and linuxtoolbox folder exist, create them if they don't
|
|
|
|
LINUXTOOLBOXDIR="$HOME/linuxtoolbox"
|
|
|
|
|
2024-07-14 03:02:24 +01:00
|
|
|
if [ ! -d "$LINUXTOOLBOXDIR" ]; then
|
|
|
|
echo "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
mkdir -p "$LINUXTOOLBOXDIR"
|
2024-07-14 03:02:24 +01:00
|
|
|
echo "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
fi
|
|
|
|
|
2024-07-14 03:02:24 +01:00
|
|
|
if [ ! -d "$LINUXTOOLBOXDIR/linux-setup" ]; then
|
|
|
|
echo "${YELLOW}Cloning linux-setup repository into: $LINUXTOOLBOXDIR/linux-setup${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
git clone https://github.com/ChrisTitusTech/linux-setup "$LINUXTOOLBOXDIR/linux-setup"
|
2024-07-14 03:02:24 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "${GREEN}Successfully cloned linux-setup repository${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
else
|
2024-07-14 03:02:24 +01:00
|
|
|
echo "${RED}Failed to clone linux-setup repository${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$LINUXTOOLBOXDIR/linux-setup" || exit
|
|
|
|
|
|
|
|
command_exists() {
|
2024-07-14 03:02:24 +01:00
|
|
|
command -v "$1" >/dev/null 2>&1
|
2024-07-13 02:57:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv() {
|
|
|
|
## Check for requirements.
|
|
|
|
REQUIREMENTS='curl groups sudo'
|
2024-07-14 03:02:24 +01:00
|
|
|
for req in $REQUIREMENTS; do
|
|
|
|
if ! command_exists "$req"; then
|
|
|
|
echo "${RED}To run me, you need: $REQUIREMENTS${RC}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2024-07-13 02:57:34 +01:00
|
|
|
|
2024-07-14 03:02:24 +01:00
|
|
|
## Check Package Manager
|
2024-07-13 02:57:34 +01:00
|
|
|
PACKAGEMANAGER='apt yum dnf pacman zypper'
|
2024-07-14 03:02:24 +01:00
|
|
|
for pgm in $PACKAGEMANAGER; do
|
|
|
|
if command_exists "$pgm"; then
|
|
|
|
PACKAGER="$pgm"
|
|
|
|
echo "Using $pgm"
|
|
|
|
break
|
2024-07-13 02:57:34 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-07-14 03:02:24 +01:00
|
|
|
if [ -z "$PACKAGER" ]; then
|
|
|
|
echo "${RED}Can't find a supported package manager${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Check if the current directory is writable.
|
|
|
|
GITPATH="$(dirname "$(realpath "$0")")"
|
2024-07-14 03:02:24 +01:00
|
|
|
if [ ! -w "$GITPATH" ]; then
|
|
|
|
echo "${RED}Can't write to $GITPATH${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Check SuperUser Group
|
|
|
|
SUPERUSERGROUP='wheel sudo root'
|
2024-07-14 03:02:24 +01:00
|
|
|
for sug in $SUPERUSERGROUP; do
|
|
|
|
if groups | grep -q "$sug"; then
|
|
|
|
SUGROUP="$sug"
|
|
|
|
echo "Super user group $SUGROUP"
|
|
|
|
break
|
2024-07-13 02:57:34 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
## Check if member of the sudo group.
|
2024-07-14 03:02:24 +01:00
|
|
|
if ! groups | grep -q "$SUGROUP"; then
|
|
|
|
echo "${RED}You need to be a member of the sudo group to run me!${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
installDepend() {
|
|
|
|
## Check for dependencies.
|
|
|
|
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
|
2024-07-14 03:02:24 +01:00
|
|
|
echo "${YELLOW}Installing dependencies...${RC}"
|
2024-07-13 02:57:34 +01:00
|
|
|
case $PACKAGER in
|
|
|
|
pacman)
|
|
|
|
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
|
|
|
|
echo "[multilib]" | sudo tee -a /etc/pacman.conf
|
|
|
|
echo "Include = /etc/pacman.d/mirrorlist" | sudo tee -a /etc/pacman.conf
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" -Sy
|
2024-07-13 02:57:34 +01:00
|
|
|
else
|
|
|
|
echo "Multilib is already enabled."
|
|
|
|
fi
|
|
|
|
if ! command_exists yay && ! command_exists paru; then
|
|
|
|
echo "Installing yay as AUR helper..."
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" --noconfirm -S base-devel
|
|
|
|
cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R "$USER":"$USER" ./yay-git
|
2024-07-13 02:57:34 +01:00
|
|
|
cd yay-git && makepkg --noconfirm -si
|
|
|
|
else
|
|
|
|
echo "Aur helper already installed"
|
|
|
|
fi
|
|
|
|
if command_exists yay; then
|
|
|
|
AUR_HELPER="yay"
|
|
|
|
elif command_exists paru; then
|
|
|
|
AUR_HELPER="paru"
|
|
|
|
else
|
|
|
|
echo "No AUR helper found. Please install yay or paru."
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-07-14 03:02:24 +01:00
|
|
|
"$AUR_HELPER" --noconfirm -S $DEPENDENCIES
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
apt)
|
|
|
|
COMPILEDEPS='build-essential'
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" update
|
2024-07-13 02:57:34 +01:00
|
|
|
sudo dpkg --add-architecture i386
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" update
|
|
|
|
sudo "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
COMPILEDEPS='@development-tools'
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" update
|
|
|
|
sudo "$PACKAGER" config-manager --set-enabled powertools
|
|
|
|
sudo "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
|
|
|
|
sudo "$PACKAGER" install -y glibc-devel.i686 libgcc.i686
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
COMPILEDEPS='patterns-devel-base-devel_basis'
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" refresh
|
|
|
|
sudo "$PACKAGER" --non-interactive install $DEPENDENCIES $COMPILEDEPS
|
|
|
|
sudo "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
*)
|
2024-07-14 03:02:24 +01:00
|
|
|
sudo "$PACKAGER" install -y $DEPENDENCIES
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
install_additional_dependencies() {
|
|
|
|
case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in
|
|
|
|
*apt)
|
2024-07-14 03:02:24 +01:00
|
|
|
# Add additional dependencies for apt if needed
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
*zypper)
|
2024-07-14 03:02:24 +01:00
|
|
|
# Add additional dependencies for zypper if needed
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
*dnf)
|
2024-07-14 03:02:24 +01:00
|
|
|
# Add additional dependencies for dnf if needed
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
*pacman)
|
2024-07-14 03:02:24 +01:00
|
|
|
# Add additional dependencies for pacman if needed
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
*)
|
2024-07-14 03:02:24 +01:00
|
|
|
# Add additional dependencies for other package managers if needed
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv
|
|
|
|
installDepend
|
|
|
|
install_additional_dependencies
|