2021-07-02 20:35:46 +03:00
#!/bin/bash
exit_code = 0
color_red = $( echo -ne "\033[1;31m" )
color_green = $( echo -ne "\033[1;32m" )
2021-07-03 22:06:55 +03:00
color_yellow = $( echo -ne "\033[1;33m" )
2021-07-02 22:30:46 +03:00
color_blue = $( echo -ne "\033[1;34m" )
2021-07-02 20:35:46 +03:00
color_reset = $( echo -ne "\033[0m" )
for package in packages/* ; do
echo -e " \n=> dependency age for ${ package } \n "
while read -r dependency actual_version ; do
2021-07-03 22:06:55 +03:00
last_version = $( curl --head " https://docs.rs/ ${ dependency } " 2>& 1 | grep --ignore-case "location:" | cut --delimiter "/" --field 5 | grep --extended-regexp " ^[0-9].*.[0-9].*.[0-9] $" )
2021-07-02 20:35:46 +03:00
if [ -z " ${ last_version } " ] ; then
echo " ${ color_red } runtime error ${ color_reset } , i could not get last version from https://docs.rs/ ${ dependency } "
exit 1
fi
echo -n " ${ dependency } ${ actual_version } : "
2021-07-03 22:06:55 +03:00
newest_version = $( echo -e " ${ last_version } \n ${ actual_version } " | sort --version-sort | tail -1)
2021-07-02 20:35:46 +03:00
if [ " ${ newest_version } " = = " ${ actual_version } " ] ; then
2021-07-03 22:06:55 +03:00
if [ " $1 " = "--update" ] ; then
echo " ${ color_green } newest, nothing to update ${ color_reset } "
else
echo " ${ color_green } newest ${ color_reset } "
fi
2021-07-02 20:35:46 +03:00
else
2021-07-03 22:06:55 +03:00
if [ " $1 " = "--update" ] ; then
sed --in-place " s/ ${ dependency } .*=.*\" ${ actual_version } \"/ ${ dependency } = \" ${ last_version } \"/g " " ${ package } /Cargo.toml "
grep --silent " ${ dependency } = \" ${ last_version } \" " " ${ package } /Cargo.toml " && \
echo " ${ color_blue } old, updated to ${ last_version } ${ color_reset } " || \
echo " ${ color_red } error, update to ${ last_version } fails, please check ${ package } /Cargo.toml format and syntax ${ color_reset } "
else
2021-07-02 22:30:46 +03:00
echo " ${ color_red } old, please update to latest ${ last_version } ${ color_reset } "
fi
2021-07-03 22:06:55 +03:00
( ( exit_code++) )
2021-07-02 20:35:46 +03:00
fi
2021-07-03 22:06:55 +03:00
done < <( sed --silent " /dependencies\]/,/^ $/p " " ${ package } /Cargo.toml " | grep --extended-regexp --invert-match " \[|path|^ $" | tr --delete '" ' | tr '=' ' ' )
2021-07-02 20:35:46 +03:00
done
2021-07-03 22:06:55 +03:00
if [ " $1 " != "--update" ] && [ " ${ exit_code } " -gt 0 ] ; then
echo -e " \n ${ color_yellow } ...Consider executing \"dependency_age.sh --update\" to automatically update ${ exit_code } old dependencies on your Cargo.toml files ${ color_reset } "
fi
2021-07-02 20:35:46 +03:00
exit $exit_code