1
0
Fork 0
mirror of synced 2024-06-16 13:51:10 -04:00
zimfw/modules/utility/functions/module_update

86 lines
2.5 KiB
Plaintext
Raw Normal View History

2018-04-16 20:39:48 -04:00
local currentdir=$(pwd)
local updated=0
local failed=0
local module
local mlocation
2018-04-16 22:45:52 -04:00
local nfailed
2018-04-16 20:52:31 -04:00
local ncolors red green yelllow blue bold normal
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then
2018-04-16 22:45:52 -04:00
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
bold="$(tput bold)"
normal="$(tput sgr0)"
2018-04-16 20:52:31 -04:00
else
red=""
green=""
yellow=""
blue=""
bold=""
normal=""
fi
2018-04-16 20:39:48 -04:00
for module in $umodules; do
2018-04-16 22:45:52 -04:00
nfailed=0
2018-04-16 20:39:48 -04:00
if [ -d ${ZIM_HOME}/modules/${module} ]; then
mlocation=${ZIM_HOME}/modules/${module}
elif [ -d ${ZIM_HOME}/modules/prompt/external-themes/${module} ]; then
mlocation=${ZIM_HOME}/modules/prompt/external-themes/${module}
else
2018-04-16 20:52:31 -04:00
echo "${red}Cant find $module module...$normal"
2018-04-16 20:39:48 -04:00
break
fi
2018-04-16 20:52:31 -04:00
echo -ne "${blue}Updating $module... $normal"\\r
2018-04-16 20:39:48 -04:00
output=$(cd $mlocation && git remote update -p && git merge --ff-only @\{u\})
if [ $? -ne 0 ]; then
2018-04-16 20:52:31 -04:00
echo -ne "${red}Failed to update $module...\n $output $normal"\\r
2018-04-16 20:39:48 -04:00
failed=$((failed+1))
2018-04-16 22:45:52 -04:00
nfailed=1
2018-04-16 20:39:48 -04:00
fi
2018-04-16 22:45:52 -04:00
if ! [ ${nfailed} = "1" ]; then
2018-04-16 20:39:48 -04:00
if echo "$output" | grep -i "up to date" > /dev/null; then
2018-04-16 20:52:31 -04:00
echo -ne "${blue}$module at latest version. $normal"\\r
2018-04-16 20:39:48 -04:00
else
2018-04-16 20:52:31 -04:00
echo -ne "${green}Updated $module! $normal"\\r
2018-04-16 20:39:48 -04:00
updated=$((updated+1))
fi
2018-04-16 22:45:52 -04:00
fi
2018-04-16 20:39:48 -04:00
printf '\n'
done
for pmodule in $pmodules; do
2018-04-16 20:52:31 -04:00
echo -ne "${blue}Updating $pmodule... $normal"\\r
2018-04-16 20:39:48 -04:00
output=$(cd ${ZIM_HOME}/modules/prompt/external-themes/$pmodule && git remote update -p && git merge --ff-only @\{u\})
if [ $? -ne 0 ]; then
2018-04-16 20:52:31 -04:00
echo -ne "${red}Failed to update $pmodule...\n $output $normal"\\r
2018-04-16 20:39:48 -04:00
failed=$((failed+1))
fi
if echo "$output" | grep -i "up to date" > /dev/null; then
2018-04-16 20:52:31 -04:00
echo -ne "${blue}$pmodule at latest version. $normal"\\r
2018-04-16 20:39:48 -04:00
else
2018-04-16 20:52:31 -04:00
echo -ne "${green}Updated $pmodule! $normal"\\r
2018-04-16 20:39:48 -04:00
updated=$((updated+1))
fi
printf '\n'
done
if [ $updated -gt 0 ]; then
if [ $failed -eq 0 ]; then
2018-04-16 20:52:31 -04:00
echo "${green}${bold}Sucessfully updated $updated modules!$normal"
2018-04-16 20:39:48 -04:00
fi
else
if [ $failed -eq 0 ]; then
2018-04-16 20:52:31 -04:00
echo "${blue}${bold}No module updates avaliable.$normal"
2018-04-16 20:39:48 -04:00
fi
fi
if [ $failed -gt 0 ]; then
if [ $updated -gt 0 ]; then
2018-04-16 20:52:31 -04:00
echo "${blue}${bold}Sucessfully updated $updated modules and failed to update $failed modules.$normal"
2018-04-16 20:39:48 -04:00
else
2018-04-16 20:52:31 -04:00
echo "${red}${bold}Failed to update $failed modules, no module updates available.$normal"
2018-04-16 20:39:48 -04:00
fi
fi
2018-04-16 20:42:34 -04:00
cd $currentdir