scale-catalog/functions/self_update.sh

34 lines
1.0 KiB
Bash
Raw Normal View History

2022-07-25 02:29:58 +00:00
#!/bin/bash
args=("$@")
self_update() {
2022-08-23 18:37:16 +00:00
latest_ver=$(git describe --tags "$(git rev-list --tags --max-count=1)")
2022-08-23 18:53:19 +00:00
git fetch --tags &> /dev/null
2022-07-30 23:10:59 +00:00
echo "🅂 🄴 🄻 🄵"
echo "🅄 🄿 🄳 🄰 🅃 🄴"
2022-08-23 18:37:16 +00:00
if [[ "$hs_version" != "$latest_ver" ]] ; then
2022-07-25 02:29:58 +00:00
echo "Found a new version of HeavyScript, updating myself..."
2022-08-23 18:56:01 +00:00
git checkout "$latest_ver"
2022-07-25 02:29:58 +00:00
count=0
for i in "${args[@]}"
do
[[ "$i" == "--self-update" ]] && unset "args[$count]" && break
((count++))
done
2022-08-23 18:10:53 +00:00
echo "Updating from:"
echo "$hs_version"
echo "Updating To:"
2022-08-23 18:02:41 +00:00
curl --silent "https://api.github.com/repos/HeavyBullets8/heavy_script/releases/latest" | jq -r .tag_name,.body
2022-07-31 18:56:50 +00:00
[[ -z ${args[*]} ]] && echo -e "No more arguments, exiting..\n\n" && exit
echo -e "Running the new version...\n\n"
2022-07-25 02:29:58 +00:00
sleep 5
exec bash "$script_name" "${args[@]}"
# Now exit this old instance
exit
else
2022-08-23 18:10:53 +00:00
echo "HeavyScript is already the latest version:"
echo -e "$hs_version\n\n"
2022-07-25 02:29:58 +00:00
fi
}
2022-08-23 18:51:33 +00:00
export -f self_update