mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
refactor: allow scripts to control checkEnv search parameters
This commit is contained in:
parent
e5ddd2ee48
commit
d8600e8d64
|
@ -8,23 +8,26 @@ YELLOW='\033[33m'
|
||||||
GREEN='\033[32m'
|
GREEN='\033[32m'
|
||||||
|
|
||||||
command_exists() {
|
command_exists() {
|
||||||
which $1 >/dev/null 2>&1
|
which "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
|
checkCommandRequirements() {
|
||||||
## Check for requirements.
|
## Check for requirements.
|
||||||
REQUIREMENTS='curl groups sudo'
|
REQUIREMENTS=$1
|
||||||
for req in ${REQUIREMENTS}; do
|
for req in ${REQUIREMENTS}; do
|
||||||
if ! command_exists ${req}; then
|
if ! command_exists "${req}"; then
|
||||||
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
echo "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
## Check Package Handler
|
checkPackageManager() {
|
||||||
PACKAGEMANAGER='apt-get dnf pacman zypper'
|
## Check Package Manager
|
||||||
|
PACKAGEMANAGER=$1
|
||||||
for pgm in ${PACKAGEMANAGER}; do
|
for pgm in ${PACKAGEMANAGER}; do
|
||||||
if command_exists ${pgm}; then
|
if command_exists "${pgm}"; then
|
||||||
PACKAGER=${pgm}
|
PACKAGER=${pgm}
|
||||||
echo "Using ${pgm}"
|
echo "Using ${pgm}"
|
||||||
break
|
break
|
||||||
|
@ -35,11 +38,13 @@ checkEnv() {
|
||||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
echo -e "${RED}Can't find a supported package manager${RC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSuperUser() {
|
||||||
## Check SuperUser Group
|
## Check SuperUser Group
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
SUPERUSERGROUP='wheel sudo root'
|
||||||
for sug in ${SUPERUSERGROUP}; do
|
for sug in ${SUPERUSERGROUP}; do
|
||||||
if groups | grep -q ${sug}; then
|
if groups | grep -q "${sug}"; then
|
||||||
SUGROUP=${sug}
|
SUGROUP=${sug}
|
||||||
echo "Super user group ${SUGROUP}"
|
echo "Super user group ${SUGROUP}"
|
||||||
break
|
break
|
||||||
|
@ -47,15 +52,33 @@ checkEnv() {
|
||||||
done
|
done
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
## Check if member of the sudo group.
|
||||||
if ! groups | grep -q ${SUGROUP}; then
|
if ! groups | grep -q "${SUGROUP}"; then
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!${RC}"
|
echo "${RED}You need to be a member of the sudo group to run me!${RC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCurrentDirectoryWritable() {
|
||||||
|
## Check if the current directory is writable.
|
||||||
|
GITPATH="$(dirname "$(realpath "$0")")"
|
||||||
|
if [ ! -w "$GITPATH" ]; then
|
||||||
|
echo "${RED}Can't write to $GITPATH${RC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
checkDistro() {
|
||||||
DTYPE="unknown" # Default to unknown
|
DTYPE="unknown" # Default to unknown
|
||||||
# Use /etc/os-release for modern distro identification
|
# Use /etc/os-release for modern distro identification
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
DTYPE=$ID
|
DTYPE=$ID
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageHandler 'apt-get dnf pacman zypper'
|
||||||
|
checkSuperUser
|
||||||
|
checkDistro
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageManager 'apt-get dnf pacman zypper'
|
||||||
|
checkSuperUser
|
||||||
|
checkDistro
|
||||||
|
}
|
||||||
|
|
||||||
setupAlacritty() {
|
setupAlacritty() {
|
||||||
echo "Install Alacritty if not already installed..."
|
echo "Install Alacritty if not already installed..."
|
||||||
if ! command_exists alacritty; then
|
if ! command_exists alacritty; then
|
||||||
|
@ -24,4 +31,4 @@ setupAlacritty() {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
setupAlacritty
|
setupAlacritty
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageManager 'apt-get dnf pacman zypper'
|
||||||
|
checkSuperUser
|
||||||
|
checkDistro
|
||||||
|
}
|
||||||
|
|
||||||
setupKitty() {
|
setupKitty() {
|
||||||
echo "Install Kitty if not already installed..."
|
echo "Install Kitty if not already installed..."
|
||||||
if ! command_exists kitty; then
|
if ! command_exists kitty; then
|
||||||
case ${PACKAGER} in
|
case ${PACKAGER} in
|
||||||
pacman)
|
pacman)
|
||||||
sudo ${PACKAGER} -S --noconfirm kitty
|
sudo "${PACKAGER}" -S --noconfirm kitty
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
sudo ${PACKAGER} install -y kitty
|
sudo "${PACKAGER}" install -y kitty
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
|
@ -16,12 +23,12 @@ setupKitty() {
|
||||||
fi
|
fi
|
||||||
echo "Copy Kitty config files"
|
echo "Copy Kitty config files"
|
||||||
if [ -d "${HOME}/.config/kitty" ]; then
|
if [ -d "${HOME}/.config/kitty" ]; then
|
||||||
cp -r ${HOME}/.config/kitty ${HOME}/.config/kitty-bak
|
cp -r "${HOME}"/.config/kitty "${HOME}"/.config/kitty-bak
|
||||||
fi
|
fi
|
||||||
mkdir -p ${HOME}/.config/kitty/
|
mkdir -p "${HOME}"/.config/kitty/
|
||||||
wget -O ${HOME}/.config/kitty/kitty.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/kitty.conf
|
wget -O "${HOME}"/.config/kitty/kitty.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/kitty.conf
|
||||||
wget -O ${HOME}/.config/kitty/nord.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/nord.conf
|
wget -O "${HOME}"/.config/kitty/nord.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/nord.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
setupKitty
|
setupKitty
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageManager 'apt-get dnf pacman zypper'
|
||||||
|
checkSuperUser
|
||||||
|
checkDistro
|
||||||
|
}
|
||||||
|
|
||||||
setupRofi() {
|
setupRofi() {
|
||||||
echo "Install Rofi if not already installed..."
|
echo "Install Rofi if not already installed..."
|
||||||
if ! command_exists rofi; then
|
if ! command_exists rofi; then
|
||||||
|
@ -29,4 +36,4 @@ setupRofi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
setupRofi
|
setupRofi
|
||||||
|
|
|
@ -22,6 +22,13 @@ fi
|
||||||
|
|
||||||
cd "$LINUXTOOLBOXDIR/linux-setup" || exit
|
cd "$LINUXTOOLBOXDIR/linux-setup" || exit
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageHandler 'apt yum dnf pacman zypper'
|
||||||
|
checkCurrentDirectoryWritable
|
||||||
|
checkSuperUser
|
||||||
|
}
|
||||||
|
|
||||||
installDepend() {
|
installDepend() {
|
||||||
## Check for dependencies.
|
## Check for dependencies.
|
||||||
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
|
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
|
||||||
|
@ -51,30 +58,30 @@ installDepend() {
|
||||||
echo "No AUR helper found. Please install yay or paru."
|
echo "No AUR helper found. Please install yay or paru."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
"$AUR_HELPER" --noconfirm -S $DEPENDENCIES
|
"$AUR_HELPER" --noconfirm -S "$DEPENDENCIES"
|
||||||
;;
|
;;
|
||||||
apt)
|
apt)
|
||||||
COMPILEDEPS='build-essential'
|
COMPILEDEPS='build-essential'
|
||||||
sudo "$PACKAGER" update
|
sudo "$PACKAGER" update
|
||||||
sudo dpkg --add-architecture i386
|
sudo dpkg --add-architecture i386
|
||||||
sudo "$PACKAGER" update
|
sudo "$PACKAGER" update
|
||||||
sudo "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
|
sudo "$PACKAGER" install -y "$DEPENDENCIES" $COMPILEDEPS
|
||||||
;;
|
;;
|
||||||
dnf)
|
dnf)
|
||||||
COMPILEDEPS='@development-tools'
|
COMPILEDEPS='@development-tools'
|
||||||
sudo "$PACKAGER" update
|
sudo "$PACKAGER" update
|
||||||
sudo "$PACKAGER" config-manager --set-enabled powertools
|
sudo "$PACKAGER" config-manager --set-enabled powertools
|
||||||
sudo "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
|
sudo "$PACKAGER" install -y "$DEPENDENCIES" $COMPILEDEPS
|
||||||
sudo "$PACKAGER" install -y glibc-devel.i686 libgcc.i686
|
sudo "$PACKAGER" install -y glibc-devel.i686 libgcc.i686
|
||||||
;;
|
;;
|
||||||
zypper)
|
zypper)
|
||||||
COMPILEDEPS='patterns-devel-base-devel_basis'
|
COMPILEDEPS='patterns-devel-base-devel_basis'
|
||||||
sudo "$PACKAGER" refresh
|
sudo "$PACKAGER" refresh
|
||||||
sudo "$PACKAGER" --non-interactive install $DEPENDENCIES $COMPILEDEPS
|
sudo "$PACKAGER" --non-interactive install "$DEPENDENCIES" $COMPILEDEPS
|
||||||
sudo "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit
|
sudo "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
sudo "$PACKAGER" install -y $DEPENDENCIES
|
sudo "$PACKAGER" install -y "$DEPENDENCIES"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
@ -101,4 +108,4 @@ install_additional_dependencies() {
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
installDepend
|
installDepend
|
||||||
install_additional_dependencies
|
install_additional_dependencies
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageManager 'apt-get yum dnf pacman zypper'
|
||||||
|
checkCurrentDirectoryWritable
|
||||||
|
checkSuperUser
|
||||||
|
}
|
||||||
|
|
||||||
installDepend() {
|
installDepend() {
|
||||||
## Check for dependencies.
|
## Check for dependencies.
|
||||||
echo -e "${YELLOW}Installing dependencies...${RC}"
|
echo -e "${YELLOW}Installing dependencies...${RC}"
|
||||||
|
@ -83,4 +90,4 @@ install_additional_dependencies() {
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
installDepend
|
installDepend
|
||||||
install_additional_dependencies
|
install_additional_dependencies
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
checkEnv() {
|
||||||
|
checkCommandRequirements 'curl groups sudo'
|
||||||
|
checkPackageManager 'apt-get nala dnf pacman zypper yum xbps-install'
|
||||||
|
checkSuperUser
|
||||||
|
checkDistro
|
||||||
|
}
|
||||||
|
|
||||||
fastUpdate() {
|
fastUpdate() {
|
||||||
case ${PACKAGER} in
|
case ${PACKAGER} in
|
||||||
pacman)
|
pacman)
|
||||||
|
@ -68,15 +75,15 @@ updateSystem() {
|
||||||
echo -e "${GREEN}Updating system${RC}"
|
echo -e "${GREEN}Updating system${RC}"
|
||||||
case ${PACKAGER} in
|
case ${PACKAGER} in
|
||||||
nala|apt-get)
|
nala|apt-get)
|
||||||
sudo ${PACKAGER} update -y
|
sudo "${PACKAGER}" update -y
|
||||||
sudo ${PACKAGER} upgrade -y
|
sudo "${PACKAGER}" upgrade -y
|
||||||
;;
|
;;
|
||||||
yum|dnf)
|
yum|dnf)
|
||||||
sudo ${PACKAGER} update -y
|
sudo "${PACKAGER}" update -y
|
||||||
sudo ${PACKAGER} upgrade -y
|
sudo "${PACKAGER}" upgrade -y
|
||||||
;;
|
;;
|
||||||
pacman)
|
pacman)
|
||||||
sudo ${PACKAGER} -Syu --noconfirm
|
sudo "${PACKAGER}" -Syu --noconfirm
|
||||||
;;
|
;;
|
||||||
zypper)
|
zypper)
|
||||||
sudo ${PACKAGER} ref
|
sudo ${PACKAGER} ref
|
||||||
|
|
Loading…
Reference in New Issue
Block a user