Skip to content

Instantly share code, notes, and snippets.

@John-Gee
Created September 5, 2017 11:44
Show Gist options
  • Save John-Gee/6b2256b2e68342c1fa70eedde0b1b627 to your computer and use it in GitHub Desktop.
Save John-Gee/6b2256b2e68342c1fa70eedde0b1b627 to your computer and use it in GitHub Desktop.
Added threading
#!/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