convert bash to sh

This commit is contained in:
Chris Titus 2024-07-13 21:02:24 -05:00
parent 00ba0aade1
commit f47a9077df
2 changed files with 60 additions and 62 deletions

View File

@ -1,26 +1,25 @@
#!/bin/bash #!/bin/sh
RC='\033[0m'
RC='\e[0m' RED='\033[31m'
RED='\e[31m' YELLOW='\033[33m'
YELLOW='\e[33m' GREEN='\033[32m'
GREEN='\e[32m'
# Check if the home directory and linuxtoolbox folder exist, create them if they don't # Check if the home directory and linuxtoolbox folder exist, create them if they don't
LINUXTOOLBOXDIR="$HOME/linuxtoolbox" LINUXTOOLBOXDIR="$HOME/linuxtoolbox"
if [[ ! -d "$LINUXTOOLBOXDIR" ]]; then if [ ! -d "$LINUXTOOLBOXDIR" ]; then
echo -e "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}" echo "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}"
mkdir -p "$LINUXTOOLBOXDIR" mkdir -p "$LINUXTOOLBOXDIR"
echo -e "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}" echo "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}"
fi fi
if [[ ! -d "$LINUXTOOLBOXDIR/linux-setup" ]]; then if [ ! -d "$LINUXTOOLBOXDIR/linux-setup" ]; then
echo -e "${YELLOW}Cloning linux-setup repository into: $LINUXTOOLBOXDIR/linux-setup${RC}" echo "${YELLOW}Cloning linux-setup repository into: $LINUXTOOLBOXDIR/linux-setup${RC}"
git clone https://github.com/ChrisTitusTech/linux-setup "$LINUXTOOLBOXDIR/linux-setup" git clone https://github.com/ChrisTitusTech/linux-setup "$LINUXTOOLBOXDIR/linux-setup"
if [[ $? -eq 0 ]]; then if [ $? -eq 0 ]; then
echo -e "${GREEN}Successfully cloned linux-setup repository${RC}" echo "${GREEN}Successfully cloned linux-setup repository${RC}"
else else
echo -e "${RED}Failed to clone linux-setup repository${RC}" echo "${RED}Failed to clone linux-setup repository${RC}"
exit 1 exit 1
fi fi
fi fi
@ -28,72 +27,75 @@ fi
cd "$LINUXTOOLBOXDIR/linux-setup" || exit cd "$LINUXTOOLBOXDIR/linux-setup" || exit
command_exists() { command_exists() {
command -v $1 >/dev/null 2>&1 command -v "$1" >/dev/null 2>&1
} }
checkEnv() { checkEnv() {
## Check for requirements. ## Check for requirements.
REQUIREMENTS='curl groups sudo' REQUIREMENTS='curl groups sudo'
if ! command_exists ${REQUIREMENTS}; then for req in $REQUIREMENTS; do
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" if ! command_exists "$req"; then
exit 1 echo "${RED}To run me, you need: $REQUIREMENTS${RC}"
fi exit 1
## Check Package Handeler
PACKAGEMANAGER='apt yum dnf pacman zypper'
for pgm in ${PACKAGEMANAGER}; do
if command_exists ${pgm}; then
PACKAGER=${pgm}
echo -e "Using ${pgm}"
fi fi
done done
if [ -z "${PACKAGER}" ]; then ## Check Package Manager
echo -e "${RED}Can't find a supported package manager" PACKAGEMANAGER='apt yum dnf pacman zypper'
for pgm in $PACKAGEMANAGER; do
if command_exists "$pgm"; then
PACKAGER="$pgm"
echo "Using $pgm"
break
fi
done
if [ -z "$PACKAGER" ]; then
echo "${RED}Can't find a supported package manager${RC}"
exit 1 exit 1
fi fi
## Check if the current directory is writable. ## Check if the current directory is writable.
GITPATH="$(dirname "$(realpath "$0")")" GITPATH="$(dirname "$(realpath "$0")")"
if [[ ! -w ${GITPATH} ]]; then if [ ! -w "$GITPATH" ]; then
echo -e "${RED}Can't write to ${GITPATH}${RC}" echo "${RED}Can't write to $GITPATH${RC}"
exit 1 exit 1
fi fi
## 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 ${sug}; then if groups | grep -q "$sug"; then
SUGROUP=${sug} SUGROUP="$sug"
echo -e "Super user group ${SUGROUP}" echo "Super user group $SUGROUP"
break
fi fi
done done
## Check if member of the sudo group. ## Check if member of the sudo group.
if ! groups | grep ${SUGROUP} >/dev/null; then if ! groups | grep -q "$SUGROUP"; then
echo -e "${RED}You need to be a member of the sudo group to run me!" echo "${RED}You need to be a member of the sudo group to run me!${RC}"
exit 1 exit 1
fi fi
} }
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'
echo -e "${YELLOW}Installing dependencies...${RC}" echo "${YELLOW}Installing dependencies...${RC}"
case $PACKAGER in case $PACKAGER in
pacman) pacman)
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
echo "[multilib]" | sudo tee -a /etc/pacman.conf echo "[multilib]" | sudo tee -a /etc/pacman.conf
echo "Include = /etc/pacman.d/mirrorlist" | sudo tee -a /etc/pacman.conf echo "Include = /etc/pacman.d/mirrorlist" | sudo tee -a /etc/pacman.conf
sudo ${PACKAGER} -Sy sudo "$PACKAGER" -Sy
else else
echo "Multilib is already enabled." echo "Multilib is already enabled."
fi fi
if ! command_exists yay && ! command_exists paru; then if ! command_exists yay && ! command_exists paru; then
echo "Installing yay as AUR helper..." echo "Installing yay as AUR helper..."
sudo ${PACKAGER} --noconfirm -S base-devel 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 cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R "$USER":"$USER" ./yay-git
cd yay-git && makepkg --noconfirm -si cd yay-git && makepkg --noconfirm -si
else else
echo "Aur helper already installed" echo "Aur helper already installed"
@ -106,30 +108,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} # non-interactive is the equivalent of -y for opensuse also install could be in (for install) sudo "$PACKAGER" --non-interactive install $DEPENDENCIES $COMPILEDEPS
sudo ${PACKAGER} --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit # non-interactive is the equivalent of -y for opensuse sudo "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit
;; ;;
*) *)
sudo ${PACKAGER} install -y ${DEPENDENCIES} sudo "$PACKAGER" install -y $DEPENDENCIES
;; ;;
esac esac
} }
@ -137,19 +139,19 @@ installDepend() {
install_additional_dependencies() { install_additional_dependencies() {
case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in
*apt) *apt)
# Add additional dependencies for apt if needed
;; ;;
*zypper) *zypper)
# Add additional dependencies for zypper if needed
;; ;;
*dnf) *dnf)
# Add additional dependencies for dnf if needed
;; ;;
*pacman) *pacman)
# Add additional dependencies for pacman if needed
;; ;;
*) *)
# Add additional dependencies for other package managers if needed
;; ;;
esac esac
} }

View File

@ -35,10 +35,6 @@ impl CustomList {
name: "root", name: "root",
command: "" command: ""
} => { } => {
ListNode {
name: "Full bash",
command: "bash"
},
ListNode { ListNode {
name: "Full System Update", name: "Full System Update",
command: "bash -c \"sudo pacman -Syu\"" command: "bash -c \"sudo pacman -Syu\""