From 005d168d9ae14f861133019a893b1a0fbc5fcd5f Mon Sep 17 00:00:00 2001 From: Ved Prakash <87353286+vedxp@users.noreply.github.com> Date: Sat, 25 Mar 2023 10:47:33 +0530 Subject: [PATCH 1/2] Update setup.sh - Use the `hash` command instead of `command -v` to check if a command exists. - Use an array to store the packages to make the code more readable and maintainable. - Use elif instead of else if for consistency. - Add comments to the package installation commands. --- setup.sh | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 9 deletions(-) diff --git a/setup.sh b/setup.sh index 19a5dff..4c3ff89 100755 --- a/setup.sh +++ b/setup.sh @@ -1,26 +1,109 @@ #!/bin/bash # Determine which command to use for privilege escalation -if command -v sudo > /dev/null 2>&1; then +if hash sudo 2>/dev/null; then sudo_cmd="sudo" -elif command -v doas > /dev/null 2>&1; then +elif hash doas 2>/dev/null; then sudo_cmd="doas" else echo "Neither sudo nor doas found. Please install one of them." exit 1 fi +# Install packages depending on the operating system if [[ "$OSTYPE" == "linux-gnu" ]]; then - if [[ "$(command -v apt)" != "" ]]; then - $sudo_cmd apt install unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeview mpack arj cabextract device-tree-compiler liblzma-dev python3-pip brotli liblz4-tool axel gawk aria2 detox cpio rename liblz4-dev curl -y - elif [[ "$(command -v dnf)" != "" ]]; then - $sudo_cmd dnf install -y unace unrar zip unzip sharutils uudeview arj cabextract file-roller dtc python3-pip brotli axel aria2 detox cpio lz4 python3-devel xz-devel p7zip p7zip-plugins - elif [[ "$(command -v pacman)" != "" ]]; then - $sudo_cmd pacman -Sy --noconfirm --needed unace unrar zip unzip p7zip sharutils uudeview arj cabextract file-roller dtc python-pip brotli axel gawk aria2 detox cpio lz4 + if hash apt 2>/dev/null; then + packages=( + unace + unrar + zip + unzip + p7zip-full + p7zip-rar + sharutils + rar + uudeview + mpack + arj + cabextract + device-tree-compiler + liblzma-dev + python3-pip + brotli + liblz4-tool + axel + gawk + aria2 + detox + cpio + rename + liblz4-dev + curl + ) + $sudo_cmd apt install "${packages[@]}" -y + elif hash dnf 2>/dev/null; then + packages=( + unace + unrar + zip + unzip + sharutils + uudeview + arj + cabextract + file-roller + dtc + python3-pip + brotli + axel + aria2 + detox + cpio + lz4 + python3-devel + xz-devel + p7zip + p7zip-plugins + ) + $sudo_cmd dnf install "${packages[@]}" -y + elif hash pacman 2>/dev/null; then + packages=( + unace + unrar + zip + unzip + p7zip + sharutils + uudeview + arj + cabextract + file-roller + dtc + python-pip + brotli + axel + gawk + aria2 + detox + cpio + lz4 + ) + $sudo_cmd pacman -Sy --noconfirm --needed "${packages[@]}" fi PIP=pip3 elif [[ "$OSTYPE" == "darwin"* ]]; then - brew install protobuf xz brotli lz4 aria2 detox coreutils p7zip gawk + packages=( + protobuf + xz + brotli + lz4 + aria2 + detox + coreutils + p7zip + gawk + ) + brew install "${packages[@]}" PIP=pip fi From dd3440593d0d48bba63f7b3f3dcabe7d4f67c4db Mon Sep 17 00:00:00 2001 From: Ved Prakash <87353286+vedxp@users.noreply.github.com> Date: Sat, 25 Mar 2023 12:05:59 +0530 Subject: [PATCH 2/2] Update setup.sh --- setup.sh | 110 +++++++++++-------------------------------------------- 1 file changed, 21 insertions(+), 89 deletions(-) diff --git a/setup.sh b/setup.sh index 4c3ff89..e29c2c7 100755 --- a/setup.sh +++ b/setup.sh @@ -10,100 +10,32 @@ else exit 1 fi +# Define package lists for different operating systems +declare -A package_lists=( + ["linux-gnu"]="unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeview mpack arj cabextract device-tree-compiler liblzma-dev python3-pip brotli liblz4-tool axel gawk aria2 detox cpio rename liblz4-dev curl" + ["darwin"]="protobuf xz brotli lz4 aria2 detox coreutils p7zip gawk" +) + # Install packages depending on the operating system -if [[ "$OSTYPE" == "linux-gnu" ]]; then - if hash apt 2>/dev/null; then - packages=( - unace - unrar - zip - unzip - p7zip-full - p7zip-rar - sharutils - rar - uudeview - mpack - arj - cabextract - device-tree-compiler - liblzma-dev - python3-pip - brotli - liblz4-tool - axel - gawk - aria2 - detox - cpio - rename - liblz4-dev - curl - ) - $sudo_cmd apt install "${packages[@]}" -y +if [[ "${package_lists[$OSTYPE]+exists}" ]]; then + packages="${package_lists[$OSTYPE]}" + if hash apt-get 2>/dev/null; then + $sudo_cmd apt-get update + $sudo_cmd apt-get install -y "${packages}" elif hash dnf 2>/dev/null; then - packages=( - unace - unrar - zip - unzip - sharutils - uudeview - arj - cabextract - file-roller - dtc - python3-pip - brotli - axel - aria2 - detox - cpio - lz4 - python3-devel - xz-devel - p7zip - p7zip-plugins - ) - $sudo_cmd dnf install "${packages[@]}" -y + $sudo_cmd dnf install -y "${packages}" elif hash pacman 2>/dev/null; then - packages=( - unace - unrar - zip - unzip - p7zip - sharutils - uudeview - arj - cabextract - file-roller - dtc - python-pip - brotli - axel - gawk - aria2 - detox - cpio - lz4 - ) - $sudo_cmd pacman -Sy --noconfirm --needed "${packages[@]}" + $sudo_cmd pacman -Sy --noconfirm --needed "${packages}" fi +else + echo "Unsupported operating system." + exit 1 +fi + +# Determine pip version +if hash pip3 2>/dev/null; then PIP=pip3 -elif [[ "$OSTYPE" == "darwin"* ]]; then - packages=( - protobuf - xz - brotli - lz4 - aria2 - detox - coreutils - p7zip - gawk - ) - brew install "${packages[@]}" +else PIP=pip fi