modified dependency script to allow for git repos

This commit is contained in:
Josh Ashton
2024-02-12 17:46:10 -07:00
parent 434e484ad0
commit eed993baa0
3 changed files with 94 additions and 67 deletions
+81 -51
View File
@@ -1,15 +1,5 @@
#!/bin/zsh #!/bin/zsh
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <command> <package>"
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() { error() {
echo "Your package manager is not supported." echo "Your package manager is not supported."
echo "$COMMAND could not be installed automatically." echo "$COMMAND could not be installed automatically."
@@ -17,53 +7,93 @@ error() {
exit 1 exit 1
} }
if ! command -v $COMMAND &> /dev/null install() {
then COMMAND=$1
if [[ "$OSTYPE" == "linux-gnu"* ]]; then PACKAGE=$2
echo "$COMMAND not found. Installing $PACKAGE..."
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 DISTRO=$(cat /etc/os-release | grep -oP '(?<=^ID=).+' | tr -d '"')
sudo pacman -S $PACKAGE
exit 0 if [[ $DISTRO == "arch" ]]; then
elif [[ $DISTRO == "archarm" ]]; then sudo pacman -S $PACKAGE
sudo pacman -S $PACKAGE exit 0
exit 0 elif [[ $DISTRO == "archarm" ]]; then
elif [[ $DISTRO == "ubuntu" ]]; then sudo pacman -S $PACKAGE
sudo apt-get install $PACKAGE exit 0
exit 0 elif [[ $DISTRO == "ubuntu" ]]; then
elif [[ $DISTRO == "fedora" ]]; then sudo apt-get install $PACKAGE
sudo dnf install $PACKAGE exit 0
exit 0 elif [[ $DISTRO == "fedora" ]]; then
elif [[ $DISTRO == "centos" ]]; then sudo dnf install $PACKAGE
sudo yum install $PACKAGE exit 0
exit 0 elif [[ $DISTRO == "centos" ]]; then
elif [[ $DISTRO == "debian" ]]; then sudo yum install $PACKAGE
sudo apt install $PACKAGE exit 0
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 else
error error
fi 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 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 <command> <package>"
echo " check-dependency <--git> <user/repo>"
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 fi
else else
echo "Package $PACKAGE which provides the command $COMMAND, is already installed." install $COMMAND $PACKAGE
fi fi
+13 -12
View File
@@ -94,9 +94,9 @@ install_python() {
# Create the executable # Create the executable
sudo echo "#!/bin/zsh" > /usr/local/bin/$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 "$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 sudo chmod +x /usr/local/bin/$EXECUTABLE
success "$NAME" "$EXECUTABLE" success "$NAME" "$EXECUTABLE"
@@ -185,33 +185,34 @@ check_sudo() {
} }
check_theme() { check_theme() {
if ! -d ~/.config USER=$SUDO_USER
if [ ! -d /home/$USER/.config ];
then then
echo "Creating the ~/.config directory..." echo "Creating the ~/.config directory..."
su $SUDO_USER -c "mkdir ~/.config" su $USER -c "mkdir /home/$USER/.config"
fi fi
if ! -d ~/.config/theme if [ ! -d /home/$USER/.config/theme ];
then then
echo "Creating the ~/.config/theme directory..." echo "Creating the /home/$USER/.config/theme directory..."
su $SUDO_USER -c "mkdir ~/.config/theme" su $USER -c "mkdir /home/$USER/.config/theme"
fi fi
THEME_DIR=~/.config/theme THEME_DIR=/home/$USER/.config/theme
if ! -f ~/.config/theme/active.theme if [ ! -f $THEME_DIR/active.theme ];
then 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 "base=#C6CAED" > $THEME_DIR/light.theme
echo "accent=#4D5382" >> $THEME_DIR/light.theme echo "accent=#4D5382" >> $THEME_DIR/light.theme
echo "hover=#262940" >> $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 "base=#262940" > $THEME_DIR/dark.theme
echo "accent=#4D5382" >> $THEME_DIR/dark.theme echo "accent=#4D5382" >> $THEME_DIR/dark.theme
echo "hover=#C6CAED" >> $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 fi
} }
-4
View File
@@ -1,4 +0,0 @@
#!/bin/zsh
su $SUDO_USER -c "mkdir src"
mkdir build