From f47a9077dfc13ffa1bf7dd9c392c14c098457856 Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Sat, 13 Jul 2024 21:02:24 -0500 Subject: [PATCH] convert bash to sh --- src/commands/system-setup/1-compile-setup.sh | 118 ++++++++++--------- src/list.rs | 4 - 2 files changed, 60 insertions(+), 62 deletions(-) diff --git a/src/commands/system-setup/1-compile-setup.sh b/src/commands/system-setup/1-compile-setup.sh index 37c0113e..dc987d68 100755 --- a/src/commands/system-setup/1-compile-setup.sh +++ b/src/commands/system-setup/1-compile-setup.sh @@ -1,26 +1,25 @@ -#!/bin/bash - -RC='\e[0m' -RED='\e[31m' -YELLOW='\e[33m' -GREEN='\e[32m' +#!/bin/sh +RC='\033[0m' +RED='\033[31m' +YELLOW='\033[33m' +GREEN='\033[32m' # Check if the home directory and linuxtoolbox folder exist, create them if they don't LINUXTOOLBOXDIR="$HOME/linuxtoolbox" -if [[ ! -d "$LINUXTOOLBOXDIR" ]]; then - echo -e "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}" +if [ ! -d "$LINUXTOOLBOXDIR" ]; then + echo "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}" mkdir -p "$LINUXTOOLBOXDIR" - echo -e "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}" + echo "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}" fi -if [[ ! -d "$LINUXTOOLBOXDIR/linux-setup" ]]; then - echo -e "${YELLOW}Cloning linux-setup repository into: $LINUXTOOLBOXDIR/linux-setup${RC}" +if [ ! -d "$LINUXTOOLBOXDIR/linux-setup" ]; then + echo "${YELLOW}Cloning linux-setup repository into: $LINUXTOOLBOXDIR/linux-setup${RC}" git clone https://github.com/ChrisTitusTech/linux-setup "$LINUXTOOLBOXDIR/linux-setup" - if [[ $? -eq 0 ]]; then - echo -e "${GREEN}Successfully cloned linux-setup repository${RC}" + if [ $? -eq 0 ]; then + echo "${GREEN}Successfully cloned linux-setup repository${RC}" else - echo -e "${RED}Failed to clone linux-setup repository${RC}" + echo "${RED}Failed to clone linux-setup repository${RC}" exit 1 fi fi @@ -28,72 +27,75 @@ fi cd "$LINUXTOOLBOXDIR/linux-setup" || exit command_exists() { - command -v $1 >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } checkEnv() { ## Check for requirements. REQUIREMENTS='curl groups sudo' - if ! command_exists ${REQUIREMENTS}; then - echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" - exit 1 - fi - - ## 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}" + for req in $REQUIREMENTS; do + if ! command_exists "$req"; then + echo "${RED}To run me, you need: $REQUIREMENTS${RC}" + exit 1 fi done - if [ -z "${PACKAGER}" ]; then - echo -e "${RED}Can't find a supported package manager" + ## Check 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 fi ## Check if the current directory is writable. GITPATH="$(dirname "$(realpath "$0")")" - if [[ ! -w ${GITPATH} ]]; then - echo -e "${RED}Can't write to ${GITPATH}${RC}" + if [ ! -w "$GITPATH" ]; then + echo "${RED}Can't write to $GITPATH${RC}" exit 1 fi ## Check SuperUser Group SUPERUSERGROUP='wheel sudo root' - for sug in ${SUPERUSERGROUP}; do - if groups | grep ${sug}; then - SUGROUP=${sug} - echo -e "Super user group ${SUGROUP}" + for sug in $SUPERUSERGROUP; do + if groups | grep -q "$sug"; then + SUGROUP="$sug" + echo "Super user group $SUGROUP" + break fi done ## Check if member of the sudo group. - if ! groups | grep ${SUGROUP} >/dev/null; then - echo -e "${RED}You need to be a member of the sudo group to run me!" + if ! groups | grep -q "$SUGROUP"; then + echo "${RED}You need to be a member of the sudo group to run me!${RC}" exit 1 fi - } installDepend() { ## Check for dependencies. 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 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 - sudo ${PACKAGER} -Sy + sudo "$PACKAGER" -Sy else echo "Multilib is already enabled." fi if ! command_exists yay && ! command_exists paru; then echo "Installing yay as AUR helper..." - 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 + 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 yay-git && makepkg --noconfirm -si else echo "Aur helper already installed" @@ -106,30 +108,30 @@ installDepend() { echo "No AUR helper found. Please install yay or paru." exit 1 fi - ${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} + "$AUR_HELPER" --noconfirm -S $DEPENDENCIES ;; apt) COMPILEDEPS='build-essential' - sudo ${PACKAGER} update + sudo "$PACKAGER" update sudo dpkg --add-architecture i386 - sudo ${PACKAGER} update - sudo ${PACKAGER} install -y ${DEPENDENCIES} ${COMPILEDEPS} + sudo "$PACKAGER" update + sudo "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS ;; dnf) COMPILEDEPS='@development-tools' - 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 + 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 ;; zypper) COMPILEDEPS='patterns-devel-base-devel_basis' - 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 libgcc_s1-gcc7-32bit glibc-devel-32bit # non-interactive is the equivalent of -y for opensuse + sudo "$PACKAGER" refresh + sudo "$PACKAGER" --non-interactive install $DEPENDENCIES $COMPILEDEPS + sudo "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit ;; *) - sudo ${PACKAGER} install -y ${DEPENDENCIES} + sudo "$PACKAGER" install -y $DEPENDENCIES ;; esac } @@ -137,19 +139,19 @@ installDepend() { install_additional_dependencies() { case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in *apt) - + # Add additional dependencies for apt if needed ;; *zypper) - + # Add additional dependencies for zypper if needed ;; *dnf) - + # Add additional dependencies for dnf if needed ;; *pacman) - + # Add additional dependencies for pacman if needed ;; *) - + # Add additional dependencies for other package managers if needed ;; esac } diff --git a/src/list.rs b/src/list.rs index 2aac4c2b..6f983b5d 100644 --- a/src/list.rs +++ b/src/list.rs @@ -35,10 +35,6 @@ impl CustomList { name: "root", command: "" } => { - ListNode { - name: "Full bash", - command: "bash" - }, ListNode { name: "Full System Update", command: "bash -c \"sudo pacman -Syu\""