Skip to content

Commit

Permalink
[BUGFIX] install.sh: Fix gsync not updating to latest when using branch
Browse files Browse the repository at this point in the history
* improve _get_files_and_commits logic
  • Loading branch information
Akianonymus committed May 10, 2021
1 parent 6e6d02f commit 346e118
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,24 @@ _get_files_and_commits() {
# shellcheck disable=SC2086
html_get_files_and_commits="$(curl -s --compressed "https://github.com/${repo_get_files_and_commits}/file-list/${type_value_get_files_and_commits}/${path_get_files_and_commits}")" ||
{ _print_center "normal" "Error: Cannot fetch" " update details" "=" 1>&2 && exit 1; }
# just grep the commit/ strings from html, then remove extra info with sed
commits_get_files_and_commits="$(printf "%s\n" "${html_get_files_and_commits}" | grep -o "commit/.*\"" | sed -e 's/commit\///g' -e 's/\"//g' -e 's/>.*//g')"
# only grep blob because we just want files
# shellcheck disable=SC2001
files_get_files_and_commits="$(printf "%s\n" "${html_get_files_and_commits}" | grep -oE '(blob|tree)/'"${type_value_get_files_and_commits}"'.*\"' | sed -e 's/\"//g' -e 's/>.*//g')"
files_get_files_and_commits="$(printf "%s\n" "${html_get_files_and_commits}" | grep -oE 'blob/'"${type_value_get_files_and_commits}"'.*\"' | sed -e 's/\"//g' -e 's/>.*//g')"

total_files="$(($(printf "%s\n" "${files_get_files_and_commits}" | wc -l)))"
total_commits="$(($(printf "%s\n" "${commits_get_files_and_commits}" | wc -l)))"
if [ "$((total_files - 2))" -eq "${total_commits}" ]; then
files_get_files_and_commits="$(printf "%s\n" "${files_get_files_and_commits}" | sed 1,2d)"
elif [ "${total_files}" -gt "${total_commits}" ]; then
files_get_files_and_commits="$(printf "%s\n" "${files_get_files_and_commits}" | sed 1d)"

# exit right out in case wasn't able to grab commits or files
if [ "${total_commits}" -eq "0" ] || [ "${total_files}" -eq "0" ]; then
_print_center "normal" "Error: Cannot fetch" " update details" "=" 1>&2 && exit 1
fi

# this is gonna trigger in case of non-release commit sha
if [ "${total_commits}" -gt "${total_files}" ]; then
# delete alternate lines ( sed '{N;P;d}' ), because duplicate for every commit
commits_get_files_and_commits="$(printf "%s\n" "${commits_get_files_and_commits}" | sed -e 'N;P;d')"
fi

exec 4<< EOF
Expand All @@ -213,7 +221,7 @@ $(printf "%s\n" "${commits_get_files_and_commits}")
EOF
while read -r file <&4 && read -r commit <&5; do
printf "%s\n" "${file##blob\/${type_value_get_files_and_commits}\/}__.__${commit}"
done | grep -v tree || :
done
exec 4<&- && exec 5<&-

return 0
Expand Down

0 comments on commit 346e118

Please sign in to comment.