Last active
October 25, 2022 14:08
-
-
Save eallion/aaecaec8107912755c4a22681687da30 to your computer and use it in GitHub Desktop.
hugo.sh for coding-download-center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
get_latest_release() { | |
curl --silent "https://api.github.com/repos/gohugoio/hugo/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/;s/v//g' | |
} | |
version=$(get_latest_release) | |
sha256sums() { | |
curl -fsSL "https://github.com/gohugoio/hugo/releases/download/v${version}/hugo_${version}_checksums.txt" | grep "hugo_${version}_linux-amd64.deb" | cut -d " " -f 1 | |
} | |
sha256sums_extended() { | |
curl -fsSL "https://github.com/gohugoio/hugo/releases/download/v${version}/hugo_${version}_checksums.txt" | grep "hugo_extended_${version}_linux-amd64.deb" | cut -d " " -f 1 | |
} | |
sha256sums1=$(sha256sums) | |
sha256sums2=$(sha256sums_extended) | |
current_version () { | |
cat index.md | grep "hugo-linux-amd64.deb" | cut -d " " -f 3 | |
} | |
current_sha256sums1 () { | |
cat index.md | grep "hugo-linux-amd64.deb" | cut -d " " -f 7 | |
} | |
current_sha256sums2 () { | |
cat index.md | grep "hugo-extended-linux-amd64.deb" | cut -d " " -f 7 | |
} | |
current_version=$(current_version) | |
current_sha256sums1=$(current_sha256sums1) | |
current_sha256sums2=$(current_sha256sums2) | |
# 替换 Hugo 信息 | |
sed -i "s/${current_version}/${version}/g" index.md | |
sed -i "s/${current_sha256sums1}/${sha256sums1}/g" index.md | |
sed -i "s/${current_sha256sums2}/${sha256sums2}/g" index.md | |
## 删除包含 hugo 的行 | |
#sed -i '/hugo/d' index.md | |
## 删除前 2 行 | |
#sed -i '1,2d' index.md | |
## 添加新的 hugo 信息 | |
#echo "hugo-linux-amd64.deb | ${version} | https://github.com/gohugoio/hugo/releases/download/v${version}/hugo_${version}_linux-amd64.deb | ${sha256sums1}" >> index.md | |
#echo "hugo-extended-linux-amd64.deb | ${version} | https://github.com/gohugoio/hugo/releases/download/v${version}/hugo_extended_${version}_linux-amd64.deb | ${sha256sums2}" >> index.md | |
## 排序 | |
#sort -u index.md -o index.md | |
## 重新添加表格头 | |
#sed -i '1i\--------\|---------\|-----\|-------' index.md | |
#sed -i '1i\package \| version \| uri \| sha256' index.md | |
# commit | |
git status | |
git add index.md | |
git commit -m "docs: hugo version bump to ${version}" | |
# git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment