2024-07-15 20:00:04 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2024-07-21 21:19:03 +01:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
|
2024-07-14 03:16:02 +01:00
|
|
|
RC='\033[0m'
|
|
|
|
RED='\033[31m'
|
|
|
|
YELLOW='\033[33m'
|
2024-09-18 18:53:47 +01:00
|
|
|
CYAN='\033[36m'
|
2024-07-14 03:16:02 +01:00
|
|
|
GREEN='\033[32m'
|
2024-07-13 22:44:09 +01:00
|
|
|
|
|
|
|
command_exists() {
|
2024-09-19 02:46:41 +01:00
|
|
|
command -v "$1" >/dev/null 2>&1
|
2024-07-13 22:44:09 +01:00
|
|
|
}
|
|
|
|
|
2024-09-02 02:50:48 +01:00
|
|
|
checkAURHelper() {
|
|
|
|
## Check & Install AUR helper
|
|
|
|
if [ "$PACKAGER" = "pacman" ]; then
|
2024-09-06 00:23:24 +01:00
|
|
|
if [ -z "$AUR_HELPER_CHECKED" ]; then
|
|
|
|
AUR_HELPERS="yay paru"
|
|
|
|
for helper in ${AUR_HELPERS}; do
|
|
|
|
if command_exists "${helper}"; then
|
|
|
|
AUR_HELPER=${helper}
|
2024-09-19 18:36:35 +01:00
|
|
|
printf "%b\n" "Using ${helper} as AUR helper"
|
2024-09-06 00:23:24 +01:00
|
|
|
AUR_HELPER_CHECKED=true
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-09-19 01:39:03 +01:00
|
|
|
printf "%b\n" "${YELLOW}Installing yay as AUR helper...${RC}"
|
2024-09-19 01:03:32 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm base-devel
|
|
|
|
cd /opt && "$ESCALATION_TOOL" git clone https://aur.archlinux.org/yay-bin.git && "$ESCALATION_TOOL" chown -R "$USER":"$USER" ./yay-bin
|
2024-09-18 19:40:31 +01:00
|
|
|
cd yay-bin && makepkg --noconfirm -si
|
2024-09-06 00:23:24 +01:00
|
|
|
|
|
|
|
if command_exists yay; then
|
|
|
|
AUR_HELPER="yay"
|
|
|
|
AUR_HELPER_CHECKED=true
|
|
|
|
else
|
2024-09-19 01:02:30 +01:00
|
|
|
printf "%b\n" "${RED}Failed to install AUR helper.${RC}"
|
2024-09-06 00:23:24 +01:00
|
|
|
exit 1
|
2024-09-02 02:50:48 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-08-23 14:12:47 +01:00
|
|
|
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}
|
2024-09-19 18:36:35 +01:00
|
|
|
printf "%b\n" "Using ${tool} for privilege escalation"
|
2024-08-23 14:12:47 +01:00
|
|
|
ESCALATION_TOOL_CHECKED=true
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${RED}Can't find a supported escalation tool${RC}"
|
2024-08-23 14:12:47 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2024-07-15 22:26:03 +01:00
|
|
|
|
|
|
|
checkCommandRequirements() {
|
2024-07-13 22:44:09 +01:00
|
|
|
## Check for requirements.
|
2024-07-15 22:26:03 +01:00
|
|
|
REQUIREMENTS=$1
|
2024-07-14 03:16:02 +01:00
|
|
|
for req in ${REQUIREMENTS}; do
|
2024-07-15 22:26:03 +01:00
|
|
|
if ! command_exists "${req}"; then
|
2024-09-19 01:39:03 +01:00
|
|
|
printf "%b\n" "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
2024-07-14 03:16:02 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2024-07-15 22:26:03 +01:00
|
|
|
}
|
2024-07-13 22:44:09 +01:00
|
|
|
|
2024-07-15 22:26:03 +01:00
|
|
|
checkPackageManager() {
|
|
|
|
## Check Package Manager
|
|
|
|
PACKAGEMANAGER=$1
|
2024-07-13 22:44:09 +01:00
|
|
|
for pgm in ${PACKAGEMANAGER}; do
|
2024-07-15 22:26:03 +01:00
|
|
|
if command_exists "${pgm}"; then
|
2024-07-13 22:44:09 +01:00
|
|
|
PACKAGER=${pgm}
|
2024-09-19 18:36:35 +01:00
|
|
|
printf "%b\n" "Using ${pgm}"
|
2024-07-14 03:16:02 +01:00
|
|
|
break
|
2024-07-13 22:44:09 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-09-17 13:23:23 +01:00
|
|
|
if [ -z "$PACKAGER" ]; then
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${RED}Can't find a supported package manager${RC}"
|
2024-07-13 22:44:09 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-07-15 22:26:03 +01:00
|
|
|
}
|
2024-07-13 22:44:09 +01:00
|
|
|
|
2024-07-15 22:26:03 +01:00
|
|
|
checkSuperUser() {
|
2024-07-13 22:44:09 +01:00
|
|
|
## Check SuperUser Group
|
|
|
|
SUPERUSERGROUP='wheel sudo root'
|
|
|
|
for sug in ${SUPERUSERGROUP}; do
|
2024-07-15 22:26:03 +01:00
|
|
|
if groups | grep -q "${sug}"; then
|
2024-07-13 22:44:09 +01:00
|
|
|
SUGROUP=${sug}
|
2024-09-19 18:36:35 +01:00
|
|
|
printf "%b\n" "Super user group ${SUGROUP}"
|
2024-07-14 03:16:02 +01:00
|
|
|
break
|
2024-07-13 22:44:09 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
## Check if member of the sudo group.
|
2024-07-15 22:26:03 +01:00
|
|
|
if ! groups | grep -q "${SUGROUP}"; then
|
2024-09-19 01:39:03 +01:00
|
|
|
printf "%b\n" "${RED}You need to be a member of the sudo group to run me!${RC}"
|
2024-07-13 22:44:09 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-07-15 22:26:03 +01:00
|
|
|
}
|
2024-07-13 22:44:09 +01:00
|
|
|
|
2024-07-15 22:26:03 +01:00
|
|
|
checkCurrentDirectoryWritable() {
|
|
|
|
## Check if the current directory is writable.
|
|
|
|
GITPATH="$(dirname "$(realpath "$0")")"
|
|
|
|
if [ ! -w "$GITPATH" ]; then
|
2024-09-19 01:39:03 +01:00
|
|
|
printf "%b\n" "${RED}Can't write to $GITPATH${RC}"
|
2024-07-15 22:26:03 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkDistro() {
|
2024-07-13 22:44:09 +01:00
|
|
|
DTYPE="unknown" # Default to unknown
|
2024-07-14 03:16:02 +01:00
|
|
|
# Use /etc/os-release for modern distro identification
|
|
|
|
if [ -f /etc/os-release ]; then
|
|
|
|
. /etc/os-release
|
|
|
|
DTYPE=$ID
|
|
|
|
fi
|
2024-07-15 22:26:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv() {
|
|
|
|
checkCommandRequirements 'curl groups sudo'
|
2024-09-16 15:04:15 +01:00
|
|
|
checkPackageManager 'nala apt-get dnf pacman zypper yum xbps-install nix-env'
|
2024-07-25 23:01:11 +01:00
|
|
|
checkCurrentDirectoryWritable
|
2024-07-15 22:26:03 +01:00
|
|
|
checkSuperUser
|
|
|
|
checkDistro
|
2024-08-23 14:12:47 +01:00
|
|
|
checkEscalationTool
|
2024-09-06 00:23:24 +01:00
|
|
|
checkAURHelper
|
2024-07-15 22:26:03 +01:00
|
|
|
}
|