Skip to content

Instantly share code, notes, and snippets.

@yangon99
Last active December 29, 2020 15:49
Show Gist options
  • Save yangon99/3b3531f4fd5c5628e5fcac008d5bf1a5 to your computer and use it in GitHub Desktop.
Save yangon99/3b3531f4fd5c5628e5fcac008d5bf1a5 to your computer and use it in GitHub Desktop.
auto update clash-premium-bin PKGBUILD
#!/usr/bin/bash
config_root="$HOME/.local/etc/AUR_update/"
config_path="$config_root/${0##*/}"
if [ ! -d $config_root ]; then mkdir "$config_root" -p; fi
repo_root="$HOME/repo"
repo_path="$HOME/repo/${0##*/}"
function check_update() {
pre_version=$(<$config_path)
curr_version=`\
curl -s \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/Dreamacro/clash/releases/tags/premium \
|grep -E "Premium .{10}"|awk -F\" '{print $4}'`
echo $curr_version > $config_path
echo pre=$pre_version
if [ "$pre_version" == "$curr_version" ]; then echo Nothing to do; exit; fi
echo New version $curr_version
}
function update_pkgbuild() {
arches=("i686" "x86_64" "arm" "armv6h" "armv7h" "aarch64")
arches_git=("386" "amd64" "armv5" "armv6" "armv7" "armv8")
none_fix_url="https://github.com/Dreamacro/clash/releases/download/premium/clash-linux"
pkgver=${curr_version#Premium }
index=0
echo $pre_version
echo update to $pkgver
sed -ine "s/'/\"/g" "$repo_path/PKGBUILD"
sed -ine "s/pkgver=${pre_version#Premium }/pkgver=${curr_version#Premium }/g" "$repo_path/PKGBUILD"
while((index<${#arches[*]}))
do
curl -sL "${none_fix_url}-${arches_git[$index]}-${pkgver}.gz" -o "/tmp/${arches_git[$index]}-${pkgver}.gz"
ret=`sha512sum "/tmp/${arches_git[$index]}-${pkgver}.gz"|awk '{print $1}'`
echo "${none_fix_url}-${arches_git[$index]}-${pkgver}.gz"
echo $ret ${arches_git[$index]}
#echo "sha512sums_${arches[${index}]}=('${ret}')" >> sha512sum.${pkgver}
sed -ine "s/sha512sums_${arches[$index]}=(\"\w*\")/sha512sums_${arches[$index]}=(\"${ret}\")/g" \
"$repo_path/PKGBUILD"
index=$(($index+1))
done
#cat sha512sum.${pkgver}
#echo pkgver=$pkgver
}
echo
date
echo Checking upgrade for ${0##*/}
check_update
update_pkgbuild
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment