Homebrew - Pinned package support

This commit is contained in:
2019-12-02 08:21:18 +01:00
parent f354d0b699
commit e8a6b02a95

View File

@@ -16,13 +16,19 @@
# Display info on updated pakages # Display info on updated pakages
display_info=true display_info=true
#add module to do_not_update array #add Cask to do_not_update array
declare -a do_not_update=('') declare -a do_not_update=('')
# No distract mode (no user interaction)(Casks with 'latest' version number won't be updated) # No distract mode (no user interaction)(Casks with 'latest' version number won't be updated)
no_distract=false no_distract=false
# #
######################################### #########################################
#
# Recommended software (brew install):
# -jq
# -terminal-notifier
#
#########################################
notification() { notification() {
sound="Basso" sound="Basso"
@@ -43,15 +49,45 @@ fi
echo -e "\033[1m🍺 Homebrew \033[0m" echo -e "\033[1m🍺 Homebrew \033[0m"
brew update #brew update
echo "" echo ""
# pinned
brew_pinned=$(brew list --pinned)
if [ -n "$brew_pinned" ]; then
echo -e "\033[4mList of pinned packages:\033[0m"
pinned=$(echo "$brew_pinned" | tr '\n' ' ')
echo -e "\033[1;31m$pinned\033[0m"
echo "To update a pinned package, you need to un-pin it manually (brew unpin <formula>)"
echo ""
# Remove pinned package from the update packages list
k=""
upd4=$(echo "$upd3" | tr -d '\n')
for j in $brew_pinned
do
upd4=${upd4/$j/$k}
done
# If no update package
upd4=$(echo "$upd4" | tr -s ' ')
else
upd4="$upd3"
fi
# Un paquet pinned est dans 'brew outdated'
brew_outdated=$(brew outdated) brew_outdated=$(brew outdated)
upd3=$(echo "$brew_outdated" | awk '{print $1}') upd3=$(echo "$brew_outdated" | awk '{print $1}')
#nb=$(echo $upd3 | wc -w)
if [ -n "$upd3" ]; then if [ -n "$upd3" ]; then
if [ "$display_info" = true ]; then if [ "$display_info" = true ]; then
@@ -59,6 +95,10 @@ if [ -n "$upd3" ]; then
for pkg in $upd3 for pkg in $upd3
do do
#if [[ "$pkg" == *"$brew_pinned"* ]]; then
# echo "PINNED"
#fi
# if jq (https://stedolan.github.io/jq/) is installed # if jq (https://stedolan.github.io/jq/) is installed
if [ -x "$(command -v jq)" ]; then if [ -x "$(command -v jq)" ]; then
info_pkg=$(brew info --json=v1 "$pkg") info_pkg=$(brew info --json=v1 "$pkg")
@@ -66,8 +106,15 @@ if [ -n "$upd3" ]; then
stable=$(echo "$info_pkg" | jq -r .[].versions.stable) stable=$(echo "$info_pkg" | jq -r .[].versions.stable)
homepage=$(echo "$info_pkg" | jq -r .[].homepage) homepage=$(echo "$info_pkg" | jq -r .[].homepage)
desc=$(echo "$info_pkg" | jq -r .[].desc) desc=$(echo "$info_pkg" | jq -r .[].desc)
# "linked_keg":"7.3.12","pinned":true
# "installed":[{"version":"7.3.12",
pined=$(echo "$info_pkg" | jq -r .[].pinned)
#pined=false
echo -e "\033[1m$pkg:\033[0m current: $current last: $stable" #if [[ "$pkg" == *"$brew_pinned"* ]]; then echo -e "\033[1;31m$pkg:\033[0;31m current: $current last: $stable pinned\033[0m";
if [ "$pined" = "true" ]; then echo -e "\033[1;31m$pkg:\033[0;31m current: $current last: $stable ! pinned !\033[0m";
else echo -e "\033[31m$pkg:\033[0;31m current: $current last: $stable\033[0m";
fi
echo "$desc" echo "$desc"
echo "$homepage" echo "$homepage"
@@ -75,7 +122,9 @@ if [ -n "$upd3" ]; then
info=$(brew info $pkg | head -n 4) info=$(brew info $pkg | head -n 4)
ligne1=$(echo "$info" | head -n 1) ligne1=$(echo "$info" | head -n 1)
echo -e "\033[1m$ligne1\033[0m" if [[ "$pkg" == *"$brew_pinned"* ]]; then echo -e "\033[1;31m$ligne1\033[0m"
else echo -e "\033[1m$ligne1\033[0m"
fi
echo "$info" | sed -n -e '2,3p' echo "$info" | sed -n -e '2,3p'
fi fi
@@ -88,36 +137,53 @@ if [ -n "$upd3" ]; then
if [ "$no_distract" = false ]; then if [ "$no_distract" = false ]; then
a=$(echo -e "Do you wanna run \033[1mbrew upgrade "$upd3"\033[0m? (y/n)") if [ -n "$upd4" ]; then
read -p "$a" choice
#case "$choice" in
# y|Y ) echo "$brew_outdated" | awk '{print $1}' | xargs -p -n 1 brew upgrade ;;
# n|N ) echo "Ok, let's continue";;
# * ) echo "invalid";;
#esac
if [ "$choice" == "y" ]; then a=$(echo -e "Do you wanna run \033[1mbrew upgrade "$upd4"\033[0m? (y/n)")
read -p "$a" choice
#case "$choice" in
# y|Y ) echo "$brew_outdated" | awk '{print $1}' | xargs -p -n 1 brew upgrade ;;
# n|N ) echo "Ok, let's continue";;
# * ) echo "invalid";;
#esac
for i in $upd3 if [ "$choice" == "y" ]; then
do
FOUND=`echo ${do_not_update[*]} | grep "$i"` for i in $upd4
if [ "${FOUND}" = "" ]; then do
echo "$i" | awk '{print $1}' | xargs -p -n 1 brew upgrade FOUND=`echo ${do_not_update[*]} | grep "$i"`
fi #if [ "${FOUND}" = "" ]; then
done if [ "${FOUND}" = "" ]; then
#if [[ "$i" != *"$brew_pinned"* ]]; then
echo "$i" | awk '{print $1}' | xargs -p -n 1 brew upgrade
#fi
fi
done
else
echo "Ok, let's continue"
fi
else else
echo "Ok, let's continue" echo "No package to update"
fi fi
else else # no distract
echo "$brew_outdated" | awk '{print $1}' | xargs -n 1 brew upgrade echo "$upd4"
#if [[ "$i" != *"$brew_pinned"* ]]; then
if [ -n "$upd4" ]; then
echo "$upd4" | awk '{print $1}' | xargs -n 1 brew upgrade
else
echo "No package to update"
fi
fi fi
echo "" echo ""
fi fi
# Casks
echo "🍺 Casks upgrade." echo "🍺 Casks upgrade."
cask_outdated=$(brew cask outdated --greedy --verbose) cask_outdated=$(brew cask outdated --greedy --verbose)