From efbbc019d0a417a984595efda0713addf56be1b0 Mon Sep 17 00:00:00 2001 From: Michel Date: Wed, 19 Jun 2024 18:26:45 +0200 Subject: [PATCH] feat: update versions_check with APT & archives --- bin/versions_check | 152 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 122 insertions(+), 30 deletions(-) diff --git a/bin/versions_check b/bin/versions_check index f73ca5e..36dfb6e 100755 --- a/bin/versions_check +++ b/bin/versions_check @@ -1,6 +1,18 @@ #!/bin/zsh # +# zsh colors +# +autoload colors && colors + +# Proxy +# +proxy=$(systemctl list-sockets --quiet "*proxy*" | head -1 | cut -d' ' -f1) +if [ -n "${proxy}" ]; then + echo "${bg[yellow]}${fg[black]} Using proxy ${fg_bold[black]}${proxy} \n" + export ALL_PROXY="${proxy}" +fi + # asdf, direnv, python & lastversion # # - https://github.com/dvershinin/lastversion @@ -8,51 +20,131 @@ cd $(dirname $0) eval $(asdf exec direnv export zsh) -# zsh colors +# Debian Package # -autoload colors && colors - - -machine=amd64 - function debian { program=$1 repository=$2 + apt_name=${3:-$1} + current_version="0.0.0" - echo -n "${bg[green]}${fg[black]}\n>>>> ${program}${reset_color}\n\n" - - # TODO debian package - + echo "\n${bg[red]}${fg[black]}>>>> ${program} ${reset_color}" + + # Already installed + # if (( ${+commands[$program]} )); then + echo "\n${bg[cyan]} Installed ${reset_color}" - ${program} --version + prog_out=$(${program} --version) + + # Extract version from program's output + current_version=$(lastversion format "${prog_out}") + + # Highlight program's version + echo ${prog_out} | grep --colour=always -F "${current_version}" \ls -lh =${program} - - current_version=$(lastversion format "$(${program} --version)") - last_version=$(lastversion ${repository} --newer-than ${current_version}) - - if [[ $? -eq 0 ]]; then - echo -n ${repository}/releases - echo "${fg[cyan]}" - lastversion ${repository} --filter="${machine}\.deb" --assets - - else - echo "\n${fg[green]}up to date." - fi - - else - echo "${fg[yellow]}...not found.\n" - - echo -n "${fg[cyan]}" - lastversion ${repository} --filter="${machine}\.deb" --assets fi + # Repository + # + echo "\n${bg[cyan]} ${repository} ${reset_color}" + + # Retrieve latest repository version + repo_version=$(lastversion ${repository} --newer-than ${current_version}) + + # Check last result code + if [ $? -eq 0 ]; then + echo "${fg[red]}${repo_version}${fg[cyan]} > ${current_version}${reset_color}\n" + + echo -n ${repository}/releases + echo "${fg[cyan]}" + lastversion ${repository} --filter="${filter}" --assets + + else + echo "${fg[green]}${repo_version}" + fi echo -n ${reset_color} + + + # Debian Package + apt_list=$(apt list ${apt_name} 2>/dev/null) + deb_version=$(lastversion format "${apt_list}" 2>/dev/null) + + if [ $? -eq 0 ]; then + echo "\n${bg[cyan]} Debian package ${reset_color}" + + deb_version=$(lastversion "${deb_version}" --newer-than ${current_version}) + if [ $? -eq 0 ]; then + echo "${fg[red]}${deb_version} ${fg[cyan]} > ${current_version}${reset_color}\n" + else + echo "${fg[green]}${deb_version}" + fi + echo -n ${reset_color} + fi + + echo +} + +# Archive +# +function archive +{ + program=$1 + repository=$2 + current_version="0.0.0" + + echo "\n${bg[red]}${fg[black]}>>>> ${program} ${reset_color}" + + # Already installed + # + if (( ${+commands[$program]} )); then + echo "\n${bg[cyan]} Installed ${reset_color}" + + prog_out=$(${program} --version) + + # Extract version from program's output + current_version=$(lastversion format "${prog_out} | head -1 )" 2>/dev/null) + if [ -e ${current_version} ]; then + current_version=$(lastversion format "${prog_out} | grep -o "version=[0-9.]\+")") + fi + + # Highlight program's version + echo ${prog_out} | grep --colour=always -F "${current_version}" + \ls -lh =${program} + fi + + # Repository + # + echo "\n${bg[cyan]} ${repository} ${reset_color}" + + # Retrieve latest repository version + repo_version=$(lastversion ${repository} --newer-than ${current_version}) + + # Check last result code + if [ $? -eq 0 ]; then + echo "${fg[red]}${repo_version}${fg[cyan]} > ${current_version}${reset_color}\n" + + echo -n ${repository}/releases + echo "${fg[cyan]}" + lastversion ${repository} --filter="${filter}" --assets + + else + echo "${fg[green]}${repo_version}" + fi + + echo ${reset_color} } ### +filter=amd64\\.deb + debian bat "https://github.com/sharkdp/bat" -debian delta "https://github.com/dandavison/delta" +debian delta "https://github.com/dandavison/delta" git-delta debian lsd "https://github.com/lsd-rs/lsd" + +filter=Linux_x86_64 + +archive lazygit https://github.com/jesseduffield/lazygit +archive nvim https://github.com/neovim/neovim