-
-
Save SwedishGojira/942985237ef63761208e1818905b2f40 to your computer and use it in GitHub Desktop.
Added threading
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
#!/usr/bin/env bash | |
# github.com/cpinkus | |
update_core() | |
{ | |
path="$1" | |
corename="$(basename $path)" | |
timestamp_old="$(grep $corename $cores_path/.timestamps.old)" | |
timestamp_new="$(grep $corename $cores_path/.timestamps.new)" | |
if [[ "$timestamp_new" == "$timestamp_old" ]] | |
then | |
echo "Core $corename already up-to-date" | |
return | |
fi | |
curl -s -o "$cores_path/$corename.zip" "$cores_url/$corename.zip" | |
unzip -q -o -d "$cores_path" "$cores_path/$corename.zip" | |
rm "$cores_path/$corename.zip" | |
echo "Core $corename updated" | |
} | |
### URL to download cores from | |
cores_url=http://buildbot.libretro.com/nightly/linux/x86_64/latest | |
### Location of your retroarch cores | |
cores_path="$HOME"/.config/retroarch/cores | |
# Get timestamps from URL | |
touch "$cores_path"/.timestamps.old | |
touch "$cores_path"/.timestamps.new | |
mv "$cores_path"/.timestamps.new "$cores_path"/.timestamps.old | |
curl -s "$cores_url"/ | sed 's/<[^>]\+>/\'$'\n/g' | grep -A3 "_libretro.so.zip" \ | |
| tr '\n' ' ' | sed 's/ -- /\'$'\n/g' > "$cores_path"/.timestamps.new | |
# Get the number of cores | |
threads=`grep -c ^processor /proc/cpuinfo` | |
# Download and replace cores | |
for i in "$cores_path"/*_libretro.so | |
do | |
while [ `jobs | wc -l` -ge $threads ] | |
do | |
sleep 1 | |
done | |
update_core "$i" & | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment