lots of shit
This commit is contained in:
@@ -1,29 +1,38 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
source ~/dotfiles/bin/helpers/functions.sh
|
||||
source ~/dotfiles/bin/lists/cargo.sh
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
ensure_cargo_packages_installed() {
|
||||
# Check if cargo_packages array contains duplicates
|
||||
if [ $(echo $cargo_packages | tr ' ' '\n' | sort | uniq -d | wc -l) -ne 0 ]; then
|
||||
printfe "%s\n" "red" "The cargo_packages array contains duplicates"
|
||||
printfe "%s\n" "yellow" "Duplicates:"
|
||||
printfe "%s\n" "blue" $(echo $cargo_packages | tr ' ' '\n' | sort | uniq -d)
|
||||
exit 1
|
||||
fi
|
||||
cargo_packages=($(cat $DOTFILES_CONFIG | shyaml keys config.packages.cargo))
|
||||
for package in "${cargo_packages[@]}"; do
|
||||
printfe "%s" "cyan" " - Checking $package..."
|
||||
echo -en '\r'
|
||||
|
||||
for package in $cargo_packages; do
|
||||
# Some entries have a git_url and binary, we need to load these in if they exist
|
||||
pkg_status=$(cargo install --list | grep -E "^${package}\sv[0-9.]+:$")
|
||||
package_url=$(cat $DOTFILES_CONFIG | shyaml get-value config.packages.cargo.$package.git_url 2>/dev/null)
|
||||
binary=$(cat $DOTFILES_CONFIG | shyaml get-value config.packages.cargo.$package.binary 2>/dev/null)
|
||||
|
||||
# If pkg_status is `installed` then we don't need to install the package, otherwise if it's empty then the package is not installed
|
||||
if [ -z $pkg_status ]; then
|
||||
ensure_sudo_privileges "In order to install cargo_packages, please provide your password:"
|
||||
printfe "%s" "yellow" " - Installing $package..."
|
||||
ensure_sudo_privileges "In order to install $package, please provide your password:"
|
||||
printfe "%s" "yellow" " - Compiling/Installing $package... (This may take a while)"
|
||||
clear_line
|
||||
result=$(cargo install $package 2>&1)
|
||||
|
||||
# If package_url is defined we should install via git
|
||||
if [ -n "$package_url" ]; then
|
||||
command="cargo install --git $package_url $binary"
|
||||
else
|
||||
command="cargo install $package"
|
||||
fi
|
||||
|
||||
# Execute the command
|
||||
result=$(eval $command 2>&1)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to install $package"
|
||||
printfe "%s\n" "red" " Command: $command"
|
||||
printfe "%s\n" "red" " Output: $result"
|
||||
exit 1
|
||||
fi
|
||||
printfe "%s\n" "green" " - Installed $package"
|
||||
@@ -37,6 +46,7 @@ print_cargo_status() {
|
||||
printfe "%s" "cyan" "Checking Cargo packages..."
|
||||
clear_line
|
||||
|
||||
cargo_packages=($(cat $DOTFILES_CONFIG | shyaml keys config.packages.cargo))
|
||||
count=$(echo $cargo_packages | wc -w)
|
||||
installed=0
|
||||
|
||||
|
Reference in New Issue
Block a user