From eed993baa09e609193c1ea4530c71b0dd1dbab6c Mon Sep 17 00:00:00 2001 From: Josh Ashton Date: Mon, 12 Feb 2024 17:46:10 -0700 Subject: [PATCH] modified dependency script to allow for git repos --- check-dependency | 132 +++++++++++++++++++++++++++++------------------ install => inst | 25 ++++----- test | 4 -- 3 files changed, 94 insertions(+), 67 deletions(-) rename install => inst (91%) delete mode 100755 test diff --git a/check-dependency b/check-dependency index 3226a77..1cf0100 100755 --- a/check-dependency +++ b/check-dependency @@ -1,15 +1,5 @@ #!/bin/zsh -if [[ $# -ne 2 ]]; then - echo "Usage: $0 " - echo "Checks if a command is installed and if not, installs the package." - echo "Supported package managers: apt, pacman, dnf, yum, brew, port" - exit 1 -fi - -COMMAND=$1 -PACKAGE=$2 - error() { echo "Your package manager is not supported." echo "$COMMAND could not be installed automatically." @@ -17,53 +7,93 @@ error() { exit 1 } -if ! command -v $COMMAND &> /dev/null -then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - echo "$COMMAND not found. Installing $PACKAGE..." +install() { + COMMAND=$1 + PACKAGE=$2 - DISTRO=$(cat /etc/os-release | grep -oP '(?<=^ID=).+' | tr -d '"') + if ! command -v $COMMAND &> /dev/null + then + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "$COMMAND not found. Installing $PACKAGE..." - if [[ $DISTRO == "arch" ]]; then - sudo pacman -S $PACKAGE - exit 0 - elif [[ $DISTRO == "archarm" ]]; then - sudo pacman -S $PACKAGE - exit 0 - elif [[ $DISTRO == "ubuntu" ]]; then - sudo apt-get install $PACKAGE - exit 0 - elif [[ $DISTRO == "fedora" ]]; then - sudo dnf install $PACKAGE - exit 0 - elif [[ $DISTRO == "centos" ]]; then - sudo yum install $PACKAGE - exit 0 - elif [[ $DISTRO == "debian" ]]; then - sudo apt install $PACKAGE - exit 0 + DISTRO=$(cat /etc/os-release | grep -oP '(?<=^ID=).+' | tr -d '"') + + if [[ $DISTRO == "arch" ]]; then + sudo pacman -S $PACKAGE + exit 0 + elif [[ $DISTRO == "archarm" ]]; then + sudo pacman -S $PACKAGE + exit 0 + elif [[ $DISTRO == "ubuntu" ]]; then + sudo apt-get install $PACKAGE + exit 0 + elif [[ $DISTRO == "fedora" ]]; then + sudo dnf install $PACKAGE + exit 0 + elif [[ $DISTRO == "centos" ]]; then + sudo yum install $PACKAGE + exit 0 + elif [[ $DISTRO == "debian" ]]; then + sudo apt install $PACKAGE + exit 0 + else + error + fi + + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "$COMMAND not found. Installing $PACKAGE..." + + if command -v "brew" &> /dev/null + then + brew install $PACKAGE + + elif command -v "port" &> /dev/null + then + sudo port install $PACKAGE + + else + echo "Homebrew or MacPorts not found. Please install one of them before running this script." + exit 1 + fi else error fi - - elif [[ "$OSTYPE" == "darwin"* ]]; then - echo "Command not found. Installing $COMMAND..." - - if command -v "brew" &> /dev/null - then - brew install $PACKAGE - - elif command -v "port" &> /dev/null - then - sudo port install $PACKAGE - - else - echo "Homebrew or MacPorts not found. Please install one of them before running this script." - exit 1 - fi else - error + echo "Package $PACKAGE which provides the command $COMMAND, is already installed." + fi +} + +# If the number of arguments is not 2, print the usage +if [[ $# -ne 2 ]]; then + echo "Usage: check-dependency " + echo " check-dependency <--git> " + echo "Checks if a command is installed and if not, installs the package." + echo "If --git is specified, it will check if the git repository is executable." + echo "Supported package managers: apt, pacman, dnf, yum, brew, port" + exit 1 +fi + +COMMAND=$1 +PACKAGE=$2 + +# If the command is git, we will clone the repository and install it +if $COMMAND == "--git"; then + USER=$(echo $PACKAGE | cut -d'/' -f1) + REPO=$(echo $PACKAGE | cut -d'/' -f2) + + # If the repository is not installed, we will clone it and install it + if ! command -v $REPO &> /dev/null + then + cd /tmp + git clone https://github.com/$USER/$REPO + cd $REPO + inst + exit 0 + + else + echo "Repository $PACKAGE is already installed." + exit 0 fi else - echo "Package $PACKAGE which provides the command $COMMAND, is already installed." + install $COMMAND $PACKAGE fi diff --git a/install b/inst similarity index 91% rename from install rename to inst index b563b18..91735f2 100755 --- a/install +++ b/inst @@ -94,9 +94,9 @@ install_python() { # Create the executable sudo echo "#!/bin/zsh" > /usr/local/bin/$EXECUTABLE - sudo echo "\nsource $ENV" >> /usr/local/bin/$EXECUTABLE + sudo echo "source $ENV" >> /usr/local/bin/$EXECUTABLE sudo echo "$COMMAND" >> /usr/local/bin/$EXECUTABLE - sudo echo "\n# Auto-generated by the install script" >> /usr/local/bin/$NAME + sudo echo "# Auto-generated by the install script" >> /usr/local/bin/$EXECUTABLE sudo chmod +x /usr/local/bin/$EXECUTABLE success "$NAME" "$EXECUTABLE" @@ -185,33 +185,34 @@ check_sudo() { } check_theme() { - if ! -d ~/.config + USER=$SUDO_USER + if [ ! -d /home/$USER/.config ]; then echo "Creating the ~/.config directory..." - su $SUDO_USER -c "mkdir ~/.config" + su $USER -c "mkdir /home/$USER/.config" fi - if ! -d ~/.config/theme + if [ ! -d /home/$USER/.config/theme ]; then - echo "Creating the ~/.config/theme directory..." - su $SUDO_USER -c "mkdir ~/.config/theme" + echo "Creating the /home/$USER/.config/theme directory..." + su $USER -c "mkdir /home/$USER/.config/theme" fi - THEME_DIR=~/.config/theme + THEME_DIR=/home/$USER/.config/theme - if ! -f ~/.config/theme/active.theme + if [ ! -f $THEME_DIR/active.theme ]; then - su $SUDO_USER -c "touch $THEME_DIR/light.theme" + su $USER -c "touch $THEME_DIR/light.theme" echo "base=#C6CAED" > $THEME_DIR/light.theme echo "accent=#4D5382" >> $THEME_DIR/light.theme echo "hover=#262940" >> $THEME_DIR/light.theme - su $SUDO_USER -c "touch $THEME_DIR/dark.theme" + su $USER -c "touch $THEME_DIR/dark.theme" echo "base=#262940" > $THEME_DIR/dark.theme echo "accent=#4D5382" >> $THEME_DIR/dark.theme echo "hover=#C6CAED" >> $THEME_DIR/dark.theme - su $SUDO_USER -c "ln -s $THEME_DIR/dark.theme $THEME_DIR/active.theme" + su $USER -c "ln -s $THEME_DIR/dark.theme $THEME_DIR/active.theme" fi } diff --git a/test b/test deleted file mode 100755 index c245896..0000000 --- a/test +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/zsh - -su $SUDO_USER -c "mkdir src" -mkdir build