Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
560bb5e13b
|
|||
|
64264174b4
|
|||
|
6b4dfb2abb
|
|||
|
1d2a6b5e3b
|
|||
|
f337e0c62b
|
|||
|
3e88dc59df
|
|||
|
e6fb194868
|
@@ -3,37 +3,51 @@
|
|||||||
# Homebrew plugin for KYMSU
|
# Homebrew plugin for KYMSU
|
||||||
# https://github.com/welcoMattic/kymsu
|
# https://github.com/welcoMattic/kymsu
|
||||||
|
|
||||||
# Error: Cask 'onyx' definition is invalid: invalid 'depends_on macos' value: :snow_leopard
|
|
||||||
# Supprimer manuellement onyx de /Applications
|
|
||||||
# rm -rvf "$(brew --prefix)/Caskroom/onyx"
|
|
||||||
# ou
|
|
||||||
# /usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' -print0 | /usr/bin/xargs -0 /usr/bin/perl -i -0pe 's/depends_on macos: \[.*?\]//gsm;s/depends_on macos: .*//g'
|
|
||||||
|
|
||||||
###############################################################################################
|
###############################################################################################
|
||||||
#
|
#
|
||||||
# Settings:
|
# Settings:
|
||||||
|
|
||||||
# Display info on updated pakages
|
# Display info on updated pakages / casks
|
||||||
display_info=true
|
display_info=true
|
||||||
|
|
||||||
# Casks don't have pinned cask. So add Cask to the do_not_update array for prevent to update.
|
# Casks don't have pinned cask. So add Cask to the do_not_update array for prevent to update.
|
||||||
# Also add package for prevent to update whitout pin it.
|
# Also add package for prevent to update whitout pin it.
|
||||||
# declare -a do_not_update=("xnconvert" "yate")
|
# declare -a do_not_update=("xnconvert" "yate")
|
||||||
declare -a do_not_update=()
|
declare -a cask_to_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
|
||||||
|
|
||||||
latest=false
|
# Some Casks have auto_updates true or version :latest. Homebrew Cask cannot track versions of those apps.
|
||||||
|
# 'latest=true' force Homebrew to update those apps.
|
||||||
|
latest=true
|
||||||
#
|
#
|
||||||
###############################################################################################
|
###############################################################################################
|
||||||
#
|
#
|
||||||
# Recommended software (brew install):
|
# Require software (brew install):
|
||||||
# -jq (Lightweight and flexible command-line JSON processor)
|
# -jq (Lightweight and flexible command-line JSON processor)
|
||||||
|
#
|
||||||
|
# Recommended software (brew install):
|
||||||
# -terminal-notifier (Send macOS User Notifications from the command-line)
|
# -terminal-notifier (Send macOS User Notifications from the command-line)
|
||||||
#
|
#
|
||||||
###############################################################################################
|
###############################################################################################
|
||||||
|
|
||||||
|
: <<'END_COMMENT'
|
||||||
|
blabla
|
||||||
|
END_COMMENT
|
||||||
|
|
||||||
|
italic="\033[3m"
|
||||||
|
underline="\033[4m"
|
||||||
|
ita_under="\033[3;4m"
|
||||||
|
bgd="\033[1;4;31m"
|
||||||
|
red="\033[1;31m"
|
||||||
|
bold="\033[1m"
|
||||||
|
box="\033[1;41m"
|
||||||
|
reset="\033[0m"
|
||||||
|
|
||||||
|
command -v terminal-notifier >/dev/null 2>&1 || { echo -e "You shoud intall ${bold}terminal-notifier${reset} for notification ${italic}(brew install terminal-notifier)${reset}.\n"; }
|
||||||
|
command -v jq >/dev/null 2>&1 || { echo -e "${bold}kymsu2${reset} require ${bold}jq${reset} but it's not installed.\nRun ${italic}(brew install jq)${reset}\nAborting..." >&2; exit 1; }
|
||||||
|
|
||||||
notification() {
|
notification() {
|
||||||
sound="Basso"
|
sound="Basso"
|
||||||
title="Homebrew"
|
title="Homebrew"
|
||||||
@@ -46,279 +60,185 @@ notification() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [[ $1 == "--nodistract" ]]; then no_distract=true; fi
|
||||||
|
if [[ $1 == "--latest" ]]; then latest=true; fi
|
||||||
|
|
||||||
if [[ $1 == "--nodistract" ]]; then
|
get_info_cask() {
|
||||||
no_distract=true
|
info="$1"
|
||||||
|
app="$2"
|
||||||
|
l1=""
|
||||||
|
|
||||||
|
token=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.token)')
|
||||||
|
name=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.name)' | jq -r '.[0]')
|
||||||
|
homepage=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.homepage)')
|
||||||
|
url=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.url)')
|
||||||
|
desc=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.desc)')
|
||||||
|
version=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.version)')
|
||||||
|
#auto_updates=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.auto_updates)')
|
||||||
|
#caveats=$(echo "$info" | jq -r '.[] | select(.token == "'${app}'") | (.caveats)')
|
||||||
|
|
||||||
|
installed_versions=$(echo "$upd_cask" | jq -r '.[] | select(.name == "'${app}'") | (.installed_versions)')
|
||||||
|
current_version=$(echo "$upd_cask" | jq -r '.[] | select(.name == "'${app}'") | (.current_version)')
|
||||||
|
|
||||||
|
[[ "$desc" = "null" ]] && desc="${italic}No description${reset}"
|
||||||
|
|
||||||
|
if [[ ! " ${casks_not_pinned} " =~ " ${token} " ]] && [[ ! " ${casks_latest_not_pinned} " =~ " ${token} " ]]; then
|
||||||
|
l1+="${red}$name ($token): installed: $installed_versions current: $current_version [Do not update]${reset}\n"
|
||||||
|
else
|
||||||
|
l1+="${bold}$name ($token): installed: $installed_versions current: $current_version${reset}\n"
|
||||||
fi
|
fi
|
||||||
|
l1+="$desc\n"
|
||||||
|
l1+="$homepage"
|
||||||
|
|
||||||
if [[ $1 == "--latest" ]]; then
|
echo -e "$l1\n"
|
||||||
latest=true
|
}
|
||||||
|
|
||||||
|
get_info_pkg() {
|
||||||
|
info="$1"
|
||||||
|
pkg="$2"
|
||||||
|
l1=""
|
||||||
|
|
||||||
|
name=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.name)')
|
||||||
|
full_name=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.full_name)')
|
||||||
|
desc=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.desc)')
|
||||||
|
homepage=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.homepage)')
|
||||||
|
|
||||||
|
#urls=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.urls)' | jq -r '.stable | .url')
|
||||||
|
keg_only=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.keg_only)')
|
||||||
|
caveats=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.caveats)')
|
||||||
|
stable=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.versions)' | jq -r '.stable')
|
||||||
|
installed=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.installed)' | jq -r '.[].version')
|
||||||
|
pinned=$(echo "$info" | jq -r '.[] | select(.name == "'${pkg}'") | (.pinned)')
|
||||||
|
|
||||||
|
if [ "$pinned" = "true" ]; then
|
||||||
|
pinned_v=$(echo "$upd_package" | jq -r '.[] | select(.name == "'${pkg}'") | (.pinned_version)')
|
||||||
|
|
||||||
|
l1+="${red}$name: installed: $installed stable: $stable [pinned at $pinned_v]"
|
||||||
|
[ "$keg_only" = true ] && l1+=" [keg-only]"
|
||||||
|
l1+="${reset}\n"
|
||||||
|
else
|
||||||
|
l1+="${bold}$name: installed: $installed stable: $stable"
|
||||||
|
[ "$keg_only" = true ] && l1+=" [keg-only]"
|
||||||
|
l1+="${reset}\n"
|
||||||
fi
|
fi
|
||||||
|
if [ "$desc" != "null" ]; then l1+="$desc\n"; fi;
|
||||||
|
l1+="$homepage"
|
||||||
|
|
||||||
echo -e "\033[1m🍺 Homebrew \033[0m"
|
echo -e "$l1\n"
|
||||||
echo ""
|
}
|
||||||
|
|
||||||
|
echo -e "${bold}🍺 Homebrew ${reset}"
|
||||||
|
|
||||||
|
echo -e "\n🍺 ${underline}Updating brew...${reset}\n"
|
||||||
brew update
|
brew update
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Search for packages update..."
|
brew_outdated=$(brew outdated --greedy --json=v2)
|
||||||
echo ""
|
|
||||||
|
|
||||||
declare -A array_info # bash 5
|
#echo "\nSearch for brew update...\n"
|
||||||
declare -A array_info_cask
|
upd_json=$(echo "$brew_outdated")
|
||||||
|
|
||||||
if [ -x "$(command -v jq)" ]; then
|
################
|
||||||
|
### Packages ###
|
||||||
|
################
|
||||||
|
|
||||||
### Recherche des mises-à-jour ###
|
# Packages update:
|
||||||
|
echo -e "\n🍺 ${underline}Search for packages update...${reset}\n"
|
||||||
|
upd_package=$(echo "$brew_outdated" | jq '{formulae} | .[]')
|
||||||
|
|
||||||
brew_outdated2=$(brew outdated --greedy --json=v2)
|
for row in $(jq -c '.[]' <<< "$upd_package");
|
||||||
upd_json=$(echo "$brew_outdated2")
|
|
||||||
|
|
||||||
upd_package=$(echo "$upd_json" | jq '{formulae} | .[]')
|
|
||||||
|
|
||||||
upd_cask=$(echo "$upd_json" | jq '{casks} | .[]')
|
|
||||||
|
|
||||||
|
|
||||||
### Liste des mises-à-jour (paquets et casks) ###
|
|
||||||
|
|
||||||
for row in $(jq -c '{formulae} | .[] | .[]' <<< "$upd_json");
|
|
||||||
do
|
do
|
||||||
name=$(echo "$row" | jq -j '.name')
|
name=$(echo "$row" | jq -j '.name')
|
||||||
|
installed_versions=$(echo "$row" | jq -j '.installed_versions' | jq -r '.[]')
|
||||||
|
current_version=$(echo "$row" | jq -j '.current_version')
|
||||||
pinned=$(echo "$row" | jq -j '.pinned')
|
pinned=$(echo "$row" | jq -j '.pinned')
|
||||||
|
#pinned_version=$(echo "$row" | jq -j '.pinned_version')
|
||||||
|
|
||||||
upd_pkg+="$name "
|
upd_pkgs+="$name "
|
||||||
if [ "$pinned" = true ]; then
|
if [ "$pinned" = true ]; then
|
||||||
upd_pkg_pinned+="$name "
|
upd_pkg_pinned+="$name "
|
||||||
|
elif [ "$pinned" = false ]; then
|
||||||
|
upd_pkg_notpinned+="$name "
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
upd_pkg=$(echo "$upd_pkg" | sed 's/.$//')
|
upd_pkgs=$(echo "$upd_pkgs" | sed 's/.$//')
|
||||||
upd_pkg_pinned=$(echo "$upd_pkg_pinned" | sed 's/.$//')
|
upd_pkg_pinned=$(echo "$upd_pkg_pinned" | sed 's/.$//')
|
||||||
|
upd_pkg_notpinned=$(echo "$upd_pkg_notpinned" | sed 's/.$//')
|
||||||
|
|
||||||
#pkg_pinned=$(brew list --pinned | xargs)
|
# Find infos about updated packages
|
||||||
pkg_pinned=$(brew list --formulae --pinned | xargs)
|
nb_pkg_upd=$(echo "$upd_pkgs" | wc -w | xargs)
|
||||||
|
if [ "$nb_pkg_upd" -gt 0 ]; then
|
||||||
|
a="available package update"
|
||||||
### Recherche des infos sur les paquets ###
|
array=($a)
|
||||||
|
if [ "$display_info" = true ]; then
|
||||||
if [ -n "$upd_pkg" ]; then
|
[ "$nb_pkg_upd" -gt 1 ] && echo -e "${box} $nb_pkg_upd ${reset} ${array[@]/%/s}:\n" || echo -e "${box} $nb_pkg_upd ${reset} ${array[@]}:\n"
|
||||||
# Only 1 request 'brew info' for all updated packages
|
upd_pkgs_info=$(brew info --json=v2 $upd_pkgs | jq '{formulae} | .[]')
|
||||||
info=$(brew info --json=v1 $upd_pkg)
|
for row in $upd_pkgs;
|
||||||
|
|
||||||
i=0
|
|
||||||
for row in $(echo "${info}" | jq -r '.[] | @base64');
|
|
||||||
do
|
do
|
||||||
_jq() {
|
get_info_pkg "$upd_pkgs_info" "$row"
|
||||||
echo ${row} | base64 --decode | jq -r ${1}
|
|
||||||
}
|
|
||||||
|
|
||||||
name=$(_jq '.name')
|
|
||||||
homepage=$(_jq '.homepage')
|
|
||||||
# encoding to base64 to prevent errors with some characters (')
|
|
||||||
desc=$(_jq '.desc' | base64 --break=0) # BSD: break=0 GNU: wrap=0
|
|
||||||
pinned=$(_jq '.pinned')
|
|
||||||
installed_v=$(_jq '.installed[].version')
|
|
||||||
stable=$(_jq '.versions.stable')
|
|
||||||
|
|
||||||
eval "declare -a array_info$i=($name $homepage $desc $pinned $installed_v $stable)"
|
|
||||||
((i++))
|
|
||||||
done
|
done
|
||||||
nb_upd_pkg=$i
|
|
||||||
i=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
else
|
||||||
brew_outdated=$(brew outdated)
|
[ "$nb_pkg_upd" -gt 1 ] && echo -e "${box} $nb_pkg_upd ${reset} ${array[@]/%/s}: ${bold}$upd_pkgs${reset}" || echo -e "${box} $nb_pkg_upd ${reset} ${array[@]}: ${bold}$upd_pkgs${reset}"
|
||||||
upd_pkg=$(echo "$brew_outdated" | awk '{print $1}')
|
|
||||||
|
|
||||||
if [ -n "$upd_pkg" ]; then
|
|
||||||
info=$(brew info $upd_pkg)
|
|
||||||
for i in $upd_pkg
|
|
||||||
do
|
|
||||||
a=$(grep -A 3 "$i: stable" <<< "$info")
|
|
||||||
array_info["$i"]="$a"
|
|
||||||
done
|
|
||||||
nb_upd_pkg=${#array_info[@]}
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Pinned packages
|
||||||
### Display pinned packages ##
|
pkg_pinned=$(brew list --pinned | xargs)
|
||||||
|
|
||||||
if [ -n "$pkg_pinned" ]; then
|
if [ -n "$pkg_pinned" ]; then
|
||||||
|
|
||||||
nbp=$(echo "$pkg_pinned" | wc -w | xargs)
|
nbp=$(echo "$pkg_pinned" | wc -w | xargs)
|
||||||
|
|
||||||
echo -e "\033[4mList of\033[0m \033[1;41m $nbp \033[0m \033[4mpinned packages:\033[0m"
|
echo -e "\n${underline}List of${reset} ${box} $nbp ${reset} ${underline}pinned packages:${reset}"
|
||||||
echo -e "\033[1;31m$pkg_pinned\033[0m"
|
echo -e "${red}$pkg_pinned${reset}"
|
||||||
echo "To update a pinned package, you need to un-pin it manually (brew unpin <formula>)"
|
echo "To update a pinned package, you need to un-pin it manually (brew unpin <formula>)"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
### Display infos for all updated packages ##
|
|
||||||
|
|
||||||
if [ -n "$upd_pkg" ]; then
|
|
||||||
|
|
||||||
# Display info on outdated packages
|
|
||||||
|
|
||||||
if [ "$display_info" = true ]; then
|
|
||||||
echo -e "\033[4mInfo on\033[0m \033[1;41m $nb_upd_pkg \033[0m \033[4mupdated packages:\033[0m"
|
|
||||||
|
|
||||||
if [ -x "$(command -v jq)" ]; then
|
|
||||||
# ok avec jq installé
|
|
||||||
|
|
||||||
i=0
|
|
||||||
for row in $(jq -c '.[]' <<< "$upd_package");
|
|
||||||
do
|
|
||||||
name=$(echo "$row" | jq -j '.name, "\n"');
|
|
||||||
pinned=$(echo "$row" | jq -j '.pinned, "\n"');
|
|
||||||
pinned_v=$(echo "$row" | jq -j '.pinned_version, "\n"');
|
|
||||||
iv=$(echo "$row" | jq -j '.installed_versions, "\n"');
|
|
||||||
installed_v=$(echo "$iv" | jq -j '.[]');
|
|
||||||
current_v=$(echo "$row" | jq -j '.current_version, "\n"');
|
|
||||||
|
|
||||||
#n="array_info$i[0]"
|
|
||||||
#name=$(echo ${!n})
|
|
||||||
h="array_info$i[1]"
|
|
||||||
homepage=$(echo ${!h})
|
|
||||||
|
|
||||||
d="array_info$i[2]"
|
|
||||||
desc=$(echo ${!d} | base64 --decode)
|
|
||||||
|
|
||||||
#echo "$name - $homepage - $desc"
|
|
||||||
|
|
||||||
#info_pkg=$(brew info --json=v1 "$name")
|
|
||||||
#homepage=$(echo "$info_pkg" | jq -r .[].homepage)
|
|
||||||
#desc=$(echo "$info_pkg" | jq -r .[].desc)
|
|
||||||
#current=$(echo "$info_pkg" | jq -r .[].installed[].version | tail -n 1 | awk '{print $1}')
|
|
||||||
#stable=$(echo "$info_pkg" | jq -r .[].versions.stable)
|
|
||||||
#pined=$(echo "$info_pkg" | jq -r .[].pinned)
|
|
||||||
|
|
||||||
if [ "$pinned" = "true" ]; then
|
|
||||||
l1+="\033[1;31m$name: installed: $installed_v stable: $current_v [pinned at $pinned_v]\033[0m\n";
|
|
||||||
else
|
|
||||||
l1+="\033[1;37m$name: installed: $installed_v stable: $current_v\033[0m\n";
|
|
||||||
fi
|
|
||||||
if [ "$desc" != "null" ]; then l1+="$desc\n"; fi;
|
|
||||||
l1+="\033[4m$homepage\033[0m\n"
|
|
||||||
l1+="\n"
|
|
||||||
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "$l1"
|
|
||||||
else
|
|
||||||
# ok sans jq
|
|
||||||
|
|
||||||
for pkg in $upd_pkg
|
|
||||||
do
|
|
||||||
info_pkg="${array_info[$pkg]}"
|
|
||||||
ligne1=$(echo "$info_pkg" | head -n 1)
|
|
||||||
desc=$(echo "$info_pkg"| sed '1d')
|
|
||||||
|
|
||||||
if [[ $ligne1 =~ "pinned" ]]; then # same as if [[ $ligne1 == *"pinned"* ]]; then
|
|
||||||
echo -e "\033[1;31m$ligne1\033[0m"
|
|
||||||
else
|
|
||||||
echo -e "\033[1m$ligne1\033[0m"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$desc"
|
|
||||||
echo ""
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
### Usefull for notify recent modification of apache/mysql/php conf files. ###
|
### Usefull for notify recent modification of apache/mysql/php conf files. ###
|
||||||
touch /tmp/checkpoint
|
touch /tmp/checkpoint
|
||||||
|
|
||||||
|
# Updating packages
|
||||||
|
echo -e "\n🍺 ${underline}Updating packages...${reset}\n"
|
||||||
|
[ -n "$upd_pkg_notpinned" ] && echo -e "${red}Pinned: $upd_pkg_pinned . It won't be updated!'${reset}\n"
|
||||||
|
|
||||||
### Remove pinned packages from outdated packages list ###
|
if [ -n "$upd_pkg_notpinned" ]; then
|
||||||
|
|
||||||
not_pinned=""
|
|
||||||
for i in $upd_pkg
|
|
||||||
do
|
|
||||||
if [[ ! " ${upd_pkg_pinned[@]} " =~ " ${i} " ]]; then
|
|
||||||
# whatever you want to do when array doesn't contain value
|
|
||||||
not_pinned+="$i "
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
not_pinned=$(echo "$not_pinned" | sed 's/.$//')
|
|
||||||
|
|
||||||
|
|
||||||
### Update outdated packages ###
|
|
||||||
|
|
||||||
if [ "$no_distract" = false ]; then
|
if [ "$no_distract" = false ]; then
|
||||||
|
a=$(echo -e "Do you wanna run \033[1mbrew upgrade "$upd_pkg_notpinned"\033[0m ? (y/n/a) ")
|
||||||
if [ -n "$not_pinned" ]; then
|
|
||||||
|
|
||||||
a=$(echo -e "Do you wanna run \033[1mbrew upgrade "$not_pinned"\033[0m ? (y/n/a)")
|
|
||||||
# yes/no/all
|
# yes/no/all
|
||||||
read -p "$a" choice
|
read -p "$a" choice
|
||||||
|
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ] || [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ] || [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
||||||
|
for i in $upd_pkg_notpinned;
|
||||||
for i in $not_pinned
|
|
||||||
do
|
do
|
||||||
FOUND=`echo ${do_not_update[*]} | grep "$i"`
|
|
||||||
if [ "${FOUND}" = "" ]; then
|
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
||||||
echo "$i" | awk '{print $1}' | xargs -p -n 1 brew upgrade --formula
|
echo "$i" | xargs -p -n 1 brew upgrade
|
||||||
echo ""
|
|
||||||
elif [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
elif [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
||||||
echo "$i" | awk '{print $1}' | xargs -n 1 brew upgrade --formula
|
echo "$i" | xargs -n 1 brew upgrade
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Ok, let's continue"
|
echo -e "OK, let's continue..."
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
#echo "No distract"
|
||||||
|
echo -e "Running ${bold}brew upgrade $upd_pkg_notpinned${reset}..."
|
||||||
|
echo "$upd_pkg_notpinned" | xargs -n 1 brew upgrade
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else # no distract = true
|
|
||||||
|
|
||||||
if [ -n "$not_pinned" ]; then
|
|
||||||
echo "$not_pinned" | awk '{print $1}' | xargs -n 1 brew upgrade --formula
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
else
|
else
|
||||||
echo -e "\033[4mNo package to update.\033[0m"
|
echo -e "\n${italic}No update package available...${reset}\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
#############
|
||||||
|
### Casks ###
|
||||||
|
#############
|
||||||
|
|
||||||
#################
|
#Casks update
|
||||||
##### CASKS #####
|
echo -e "\n🍺 ${underline}Casks...${reset}\n"
|
||||||
#################
|
upd_cask=$(echo "$brew_outdated" | jq '{casks} | .[]')
|
||||||
|
|
||||||
echo -e "\033[1m🍺 Casks upgrade \033[0m"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
if (( ${#do_not_update[@]} )); then
|
|
||||||
|
|
||||||
nbp=${#do_not_update[*]}
|
|
||||||
|
|
||||||
echo -e "\033[4mList of\033[0m \033[1;41m $nbp \033[0m \033[4m'do not update' packages:\033[0m"
|
|
||||||
echo -e "\033[1;31m${do_not_update[*]}\033[0m"
|
|
||||||
echo "To remove package from this list, you need to edit the do_not_update array."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Search for Casks update..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
i=0
|
|
||||||
for row in $(jq -c '.[]' <<< "$upd_cask");
|
for row in $(jq -c '.[]' <<< "$upd_cask");
|
||||||
do
|
do
|
||||||
name=$(echo "$row" | jq -j '.name')
|
name=$(echo "$row" | jq -j '.name')
|
||||||
@@ -327,199 +247,163 @@ do
|
|||||||
|
|
||||||
if [ "$current_version" != "latest" ]; then
|
if [ "$current_version" != "latest" ]; then
|
||||||
upd_casks+="$name "
|
upd_casks+="$name "
|
||||||
|
|
||||||
eval "declare -a array_info_cask$i=($name $installed_versions $current_version)"
|
|
||||||
((i++))
|
|
||||||
|
|
||||||
elif [ "$current_version" == "latest" ]; then
|
elif [ "$current_version" == "latest" ]; then
|
||||||
upd_casks_latest+="$name "
|
upd_casks_latest+="$name "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
upd_casks=$(echo "$upd_casks" | sed 's/.$//')
|
upd_casks=$(echo "$upd_casks" | sed 's/.$//')
|
||||||
upd_casks_latest=$(echo "$upd_casks_latest" | sed 's/.$//')
|
upd_casks_latest=$(echo "$upd_casks_latest" | sed 's/.$//')
|
||||||
|
|
||||||
nb_upd_casks=$(echo "$upd_casks" | wc -w | xargs)
|
# Do not update casks
|
||||||
nb_upd_casks_latest=$(echo "$upd_casks_latest" | wc -w | xargs)
|
if (( ${#cask_to_not_update[@]} )); then
|
||||||
|
|
||||||
|
# cask_to_not_update contient 1 cask ET/OU 1 latest
|
||||||
|
|
||||||
if [ -z "$upd_casks" ] && [ -z "$upd_casks_latest" ]; then
|
nbp=${#cask_to_not_update[*]}
|
||||||
|
|
||||||
echo -e "\033[4mNo availables Cask updates.\033[0m"
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
if [ -n "$upd_casks" ]; then
|
|
||||||
|
|
||||||
echo -e "\033[1;41m $nb_upd_casks \033[0m \033[4mAvailables Casks updates:\033[0m"
|
|
||||||
|
|
||||||
# Display info on outdated packages
|
|
||||||
|
|
||||||
if [ "$display_info" = true ]; then
|
|
||||||
|
|
||||||
#info_cask=$(brew cask info $upd_casks)
|
|
||||||
info_cask=$(brew info --cask $upd_casks)
|
|
||||||
|
|
||||||
for i in $upd_casks
|
|
||||||
do
|
|
||||||
b=$(grep -A 1 "$i:" <<< "$info_cask")
|
|
||||||
bb=$(echo "$b" | tail -n 1)
|
|
||||||
array_info_cask["$i"]="$bb"
|
|
||||||
done
|
|
||||||
|
|
||||||
l1=""
|
|
||||||
for row in $(jq -c '.[]' <<< "$upd_cask");
|
|
||||||
do
|
|
||||||
installed_versions=$(echo "$row" | jq -j '.installed_versions')
|
|
||||||
if [ "$installed_versions" != "latest" ]; then
|
|
||||||
name=$(echo "$row" | jq -j '.name')
|
|
||||||
current_version=$(echo "$row" | jq -j '.current_version')
|
|
||||||
url=${array_info_cask[$name]}
|
|
||||||
|
|
||||||
if [[ ! " ${do_not_update[@]} " =~ " ${name} " ]]; then
|
|
||||||
l1+="\033[1;37m$name: installed: $installed_versions current: $current_version\033[0m\n"
|
|
||||||
else
|
|
||||||
l1+="\033[1;31m$name: installed: $installed_versions current: $current_version [Do not update]\033[0m\n"
|
|
||||||
fi
|
|
||||||
l1+="$url\n\n"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "$l1"
|
|
||||||
#echo -e "$l1" | sed ':a;N;$!ba;s/\n//g' # supprimer les sauts de ligne
|
|
||||||
#echo -e "$l1" | tr -d '\n' # supprimer les sauts de ligne
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
echo -e "${underline}List of${reset} ${box} $nbp ${reset} ${underline}'do not update' packages:${reset}"
|
||||||
|
echo -e "${red}${cask_to_not_update[*]}${reset}"
|
||||||
|
echo -e "To remove package from this list, you need to edit the ${italic}do_not_update${reset} array."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
#brew cask info betterzip
|
casks_not_pinned=""
|
||||||
|
for i in $upd_casks
|
||||||
|
do
|
||||||
|
if [[ ! " ${cask_to_not_update[@]} " =~ " ${i} " ]]; then
|
||||||
|
casks_not_pinned+="$i "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
casks_not_pinned=$(echo "$casks_not_pinned" | sed 's/.$//')
|
||||||
|
|
||||||
|
casks_latest_not_pinned=""
|
||||||
|
for i in $upd_casks_latest
|
||||||
|
do
|
||||||
|
if [[ ! " ${cask_to_not_update[@]} " =~ " ${i} " ]]; then
|
||||||
|
casks_latest_not_pinned+="$i "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
casks_latest_not_pinned=$(echo "$casks_latest_not_pinned" | sed 's/.$//')
|
||||||
|
|
||||||
|
else
|
||||||
|
casks_not_pinned=$upd_casks
|
||||||
|
casks_latest_not_pinned=$upd_casks_latest
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Casks update
|
||||||
|
echo -e "🍺 ${underline}Search for casks update...${reset}\n"
|
||||||
|
|
||||||
|
# Find infos about updated casks
|
||||||
|
nb_casks_upd=$(echo "$upd_casks" | wc -w | xargs)
|
||||||
|
if [ "$nb_casks_upd" -gt 0 ]; then
|
||||||
|
a="available cask update"
|
||||||
|
array=($a)
|
||||||
|
if [ "$display_info" = true ]; then
|
||||||
|
[ "$nb_casks_upd" -gt 1 ] && echo -e "${box} $nb_casks_upd ${reset} ${array[@]/%/s}:\n" || echo -e "${box} $nb_casks_upd ${reset} ${array[@]}:\n"
|
||||||
|
upd_casks_info=$(brew info --json=v2 $upd_casks | jq '{casks} | .[]')
|
||||||
|
for row in $upd_casks;
|
||||||
|
do
|
||||||
|
get_info_cask "$upd_casks_info" "$row"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
[ "$nb_casks_upd" -gt 1 ] && echo -e "${box} $nb_casks_upd ${reset} ${array[@]/%/s}: ${bold}$upd_casks${reset}" || echo -e "${box} $nb_casks_upd ${reset} ${array[@]}: ${bold}$upd_casks${reset}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Updating casks
|
||||||
|
echo -e "\n🍺 ${underline}Updating casks...${reset}\n"
|
||||||
|
[ -n "$casks_not_pinned" ] && echo -e "${red}Do not update: ${cask_to_not_update[@]} . It won't be updated!'${reset}\n"
|
||||||
|
[ -n "$casks_latest_not_pinned" ] && echo -e "Some Casks have ${italic}auto_updates true${reset} or ${italic}version :latest${reset}. Homebrew Cask cannot track versions of those apps."
|
||||||
|
[ -n "$casks_latest_not_pinned" ] && echo -e "Edit this script and change the setting ${italic}latest=false${reset} to ${italic}true${reset}\n"
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "$casks_not_pinned" ]; then
|
||||||
|
|
||||||
##########
|
|
||||||
if [ "$no_distract" = false ]; then
|
if [ "$no_distract" = false ]; then
|
||||||
|
a=$(echo -e "Do you wanna run ${bold}brew upgrade $casks_not_pinned${reset} ? (y/n/a) ")
|
||||||
a=$(echo -e "Do you wanna run \033[1;37mbrew upgrade $upd_casks\033[0m ? (y/n/a)")
|
|
||||||
# yes/no/all
|
# yes/no/all
|
||||||
read -p "$a" choice
|
read -p "$a" choice
|
||||||
|
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ] || [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ] || [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
||||||
|
for i in $casks_not_pinned;
|
||||||
# boucle for: don't stop multiples updates if one block (bad checksum, not compatible with OS version (Onyx))
|
|
||||||
|
|
||||||
for i in $upd_casks
|
|
||||||
do
|
do
|
||||||
FOUND=`echo ${do_not_update[*]} | grep "$i"`
|
|
||||||
|
|
||||||
if [ "${FOUND}" == "" ]; then
|
|
||||||
#echo "$i" | xargs brew cask reinstall
|
|
||||||
#echo "$i" | xargs -p -n 1 brew reinstall
|
|
||||||
#echo "$i" | xargs -p -n 1 brew upgrade --cask
|
|
||||||
|
|
||||||
#b=$(echo -e "Do you wanna run \033[1;37mbrew upgrade homebrew/cask/$i\033[0m ? (y/n)")
|
|
||||||
#read -p "$b" choice
|
|
||||||
|
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
||||||
#echo "$i" | awk '{print $1}' | xargs -p -n 1 brew upgrade homebrew/cask/$i
|
echo "$i" | xargs -p -n 1 brew upgrade
|
||||||
echo "$i" | awk '{print $1}' | xargs -p -n 1 brew upgrade --cask
|
|
||||||
|
|
||||||
retCode=$?
|
|
||||||
echo "code retour: $retCode"
|
|
||||||
echo ""
|
echo ""
|
||||||
elif [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
elif [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
||||||
#brew upgrade homebrew/cask/$i
|
echo "$i" | xargs -n 1 brew upgrade --dry-run
|
||||||
brew upgrade --cask $i
|
|
||||||
retCode=$?
|
|
||||||
echo "code retour: $retCode"
|
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Ok, let's continue"
|
echo -e "OK, let's continue..."
|
||||||
fi
|
fi
|
||||||
else # no distract = true
|
else
|
||||||
echo "no distract"
|
echo "$casks_not_pinned" | xargs -n 1 brew upgrade --dry-run
|
||||||
|
|
||||||
fi
|
|
||||||
#########
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
else
|
||||||
|
echo -e "\n${italic}No update cask available...${reset}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$upd_casks_latest" ] && [ "$latest" == true ]; then
|
|
||||||
|
|
||||||
echo -e "\033[1;41m $nb_upd_casks_latest \033[0m \033[4mCasks (latest) updates:\033[0m"
|
# Updating casks latest
|
||||||
|
if [ -n "$casks_latest_not_pinned" ] && [ "$latest" == true ]; then
|
||||||
# Display info on outdated packages
|
echo -e "\n🍺 ${underline}Updating casks with 'latest' as version...${reset}\n"
|
||||||
|
#echo -e "Some Casks have ${italic}auto_updates true${reset} or ${italic}version :latest${reset}. Homebrew Cask cannot track versions of those apps."
|
||||||
|
#echo -e "Here you can force Homebrew to upgrade those apps.\n"
|
||||||
|
|
||||||
|
# Find infos about updated casks
|
||||||
|
nb_casks_latest_upd=$(echo "$upd_casks_latest" | wc -w | xargs)
|
||||||
|
if [ "$nb_casks_latest_upd" -gt 0 ]; then
|
||||||
|
a="available cask update"
|
||||||
|
array=($a)
|
||||||
if [ "$display_info" = true ]; then
|
if [ "$display_info" = true ]; then
|
||||||
|
[ "$nb_casks_latest_upd" -gt 1 ] && echo -e "${box} $nb_casks_latest_upd ${reset} ${array[@]/%/s}:\n" || echo -e "${box} $nb_casks_latest_upd ${reset} ${array[@]}:\n"
|
||||||
|
|
||||||
#info_cask_latest=$(brew cask info $upd_casks_latest)
|
upd_casks_latest_info=$(brew info --json=v2 $upd_casks_latest | jq '{casks} | .[]')
|
||||||
info_cask_latest=$(brew info --cask $upd_casks_latest)
|
for row in $upd_casks_latest;
|
||||||
|
|
||||||
for i in $upd_casks_latest
|
|
||||||
do
|
do
|
||||||
c=$(grep -A 1 "$i:" <<< "$info_cask_latest")
|
get_info_cask "$upd_casks_latest_info" "$row"
|
||||||
cc=$(echo "$c" | tail -n 1)
|
|
||||||
array_info_cask["$i"]="$cc"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
l2=""
|
|
||||||
for row in $(jq -c '.[]' <<< "$upd_cask");
|
|
||||||
do
|
|
||||||
installed_versions=$(echo "$row" | jq -j '.installed_versions')
|
|
||||||
if [ "$installed_versions" = "latest" ]; then
|
|
||||||
name=$(echo "$row" | jq -j '.name')
|
|
||||||
current_version=$(echo "$row" | jq -j '.current_version')
|
|
||||||
url=${array_info_cask[$name]}
|
|
||||||
|
|
||||||
if [[ ! " ${do_not_update[@]} " =~ " ${name} " ]]; then
|
|
||||||
l2+="\033[1;37m$name: installed: $installed_versions current: $current_version\033[0m\n"
|
|
||||||
else
|
else
|
||||||
l2+="\033[1;31m$name: installed: $installed_versions current: $current_version [Do not update]\033[0m\n"
|
[ "$nb_casks_latest_upd" -gt 1 ] && echo -e "${box} $nb_casks_latest_upd ${reset} ${array[@]/%/s}: ${bold}$upd_casks_latest${reset}" || echo -e "${box} $nb_casks_upd ${reset} ${array[@]}: ${bold}$upd_casks_latest${reset}"
|
||||||
fi
|
fi
|
||||||
l2+="$url\n\n"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "$l2" | sed ':a;N;$!ba;s/\n//g'
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
if [ "$no_distract" = false ]; then
|
||||||
|
q=$(echo -e "Do you wanna run ${bold}brew upgrade $casks_latest_not_pinned${reset} ? (y/n/a) ")
|
||||||
q=$(echo -e "Do you wanna run \033[1;37mbrew upgrade --cask --greedy <cask>\033[0m ? (y/n/a)")
|
|
||||||
read -p "$q" choice
|
read -p "$q" choice
|
||||||
|
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ] || [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ] || [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
||||||
for i in $upd_casks_latest
|
|
||||||
|
for i in $casks_latest_not_pinned
|
||||||
do
|
do
|
||||||
FOUND=`echo ${do_not_update[*]} | grep "$i"`
|
|
||||||
|
|
||||||
if [ "${FOUND}" == "" ]; then
|
|
||||||
|
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
||||||
echo "$i" | xargs -p -n 1 brew upgrade --cask --greedy
|
echo "\n$i" | xargs -p -n 1 brew upgrade
|
||||||
echo ""
|
echo ""
|
||||||
elif [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
elif [ "$choice" == "a" ] || [ "$choice" == "A" ]; then
|
||||||
echo "$i" | xargs -n 1 brew upgrade --cask --greedy
|
echo "\n$i" | xargs -n 1 brew upgrade
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Ok, let's continue..."
|
echo -e "OK, let's continue..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo -e "Running ${bold}brew upgrade $casks_latest_not_pinned${reset}..."
|
||||||
|
echo "$casks_latest_not_pinned" | xargs -n 1 brew upgrade
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
###############################################################
|
||||||
|
### Test if Apache conf file has been modified by Homebrew ###
|
||||||
|
### (Apache, PHP or Python updates) ###
|
||||||
### Test if Apache conf file has been modified by Homebrew (Apache, PHP or Python updates) ###
|
###############################################################
|
||||||
|
|
||||||
v_apa=$(httpd -V | grep 'SERVER_CONFIG_FILE')
|
v_apa=$(httpd -V | grep 'SERVER_CONFIG_FILE')
|
||||||
conf_apa=$(echo "$v_apa" | awk -F "\"" '{print $2}')
|
conf_apa=$(echo "$v_apa" | awk -F "\"" '{print $2}')
|
||||||
@@ -542,7 +426,6 @@ do
|
|||||||
if [ -n "$upd_pkg" ]; then
|
if [ -n "$upd_pkg" ]; then
|
||||||
|
|
||||||
# file modified since it was last read
|
# file modified since it was last read
|
||||||
|
|
||||||
php_modified=$(find /usr/local/etc/php/$php/ -name php.ini -newer /tmp/checkpoint)
|
php_modified=$(find /usr/local/etc/php/$php/ -name php.ini -newer /tmp/checkpoint)
|
||||||
php_ini=/usr/local/etc/php/$php/php.ini
|
php_ini=/usr/local/etc/php/$php/php.ini
|
||||||
notif2="$php_ini has been modified"
|
notif2="$php_ini has been modified"
|
||||||
@@ -553,7 +436,6 @@ do
|
|||||||
[ ! -z $php_modified ] && notification "$notif2"
|
[ ! -z $php_modified ] && notification "$notif2"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
@@ -562,8 +444,7 @@ echo ""
|
|||||||
### Doctor ###
|
### Doctor ###
|
||||||
##############
|
##############
|
||||||
|
|
||||||
echo "🍺 ️The Doc is checking that everything is ok."
|
echo -e "\n🍺 ${underline}The Doc is checking that everything is ok...${reset}\n"
|
||||||
echo ""
|
|
||||||
|
|
||||||
brew doctor
|
brew doctor
|
||||||
|
|
||||||
@@ -575,7 +456,7 @@ echo ""
|
|||||||
# Homebrew 2.0.0+ run a cleanup every 30 days
|
# Homebrew 2.0.0+ run a cleanup every 30 days
|
||||||
|
|
||||||
if [[ $1 == "--cleanup" ]]; then
|
if [[ $1 == "--cleanup" ]]; then
|
||||||
echo "🍺 Cleaning brewery"
|
echo -e "🍺 Cleaning brewery..."
|
||||||
|
|
||||||
#HOMEBREW_NO_INSTALL_CLEANUP
|
#HOMEBREW_NO_INSTALL_CLEANUP
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user