Add project-tools #142

Merged
Francesco Siddi merged 26 commits from ZedDB/blender-studio-pipeline:project-helper-tools into main 2023-08-31 20:33:04 +02:00
Showing only changes of commit 4b961998ff - Show all commits

View File

@ -12,7 +12,7 @@ DOWNLOAD_DIR=../../shared/artifacts/blender
mkdir -p $DOWNLOAD_DIR
# Switch to the download directory
pushd $DOWNLOAD_DIR
cd $DOWNLOAD_DIR
# .zip == Windows
# .dmg == Mac
@ -27,43 +27,63 @@ latest_urls=$(wget --quiet -O - "$HOMEPAGE" | \
sed -e 's/^<a href=["'"'"']//i' -e 's/["'"'"']$//i' | \
grep +$BLENDER_BRANCH)
for os in windows darwin.arm64 linux
# Create a snapshot of the existing files
mkdir -p previous/current_snapshot
# Backup the old files, if there are any
cp * previous/current_snapshot || true
updated_downloads=false
downloaded_files=false
for os in windows darwin.x86_64 darwin.arm64 linux
do
file_extention="${extensions[$os]}"
latest=$(echo "$latest_urls" | grep $os | grep $file_extention$ )
# Strip carridge returns from teh sha sum as the windows ones has it
# Strip carridge returns from the sha sum as the windows ones has it
shasum=$(curl -s "$latest".sha256 | tr -d '\r')
echo sum: "$shasum" *"$file_extention"
current_os_file=*$os*$file_extention
# Check if we need to download the file by looking at the shasum of the currently downloaded file (if any)
if [ ! -f *$file_extention ]; then
# Make sure that we don't have any lingering sha files
rm *$file_extention* || true # "|| true" is here to ensure that we catch the case were there are no files to remove for "set -e"
else
if [ -f $current_os_file ]; then
# Skip downloading if shasum matches the current file on disk
echo $shasum *$file_extention | sha256sum --check - && echo $os: already at latest version && continue
echo $shasum $current_os_file | sha256sum --check - && echo $os: already at latest version && continue
mkdir -p previous
mv *$file_extention* previous/
pushd previous
# Remove older backups if there are more than 10
num_old_files=$(ls -1 *$file_extention | wc -l)
if [ "$num_old_files" -ge 10 ]; then
files_to_remove=$(ls -t *$file_extention | tail $((10-$num_old_files)))
# Add the shasums as well
shasums_to_remove=$(echo $files_to_remove | sed -e 's/$/.sha256')
rm $files_to_remove $shasums_to_remove
fi
popd
updated_downloads=true
fi
# Make sure that we don't have any lingering files from this os
rm $current_os_file* || true # "|| true" is here to ensure that we catch the case were there are no files to remove for "set -e"
wget -c "$latest"
wget -c "$latest".sha256
echo $shasum *$file_extention | sha256sum --check - || (echo Downloaded file does not match its shasum, exiting! && exit 1)
echo $shasum *$os*$file_extention | sha256sum --check - || (echo Downloaded file does not match its shasum, exiting! && exit 1)
downloaded_files=true
done
if [ "$downloaded_files" = true ] ; then
# Save download date for use in the rollback script
date -R > download_date
fi
if [ "$updated_downloads" = true ] ; then
pushd previous
# Put the current backup first in the directory listing
mv current_snapshot 00
# Bump all folder names
# Assign a number to each file, reverse the processing order to not overwrite any files.
ls -v | cat -n | tac | while read n f; do mv -n "$f" "$(printf "%02d" $n)"; done
# Remove older backup folders if there are more than 10
num_old_files=$(ls -1 | wc -l)
if [ "$num_old_files" -ge 10 ]; then
files_to_remove=$(ls | tail $((10-$num_old_files)))
rm -fr $files_to_remove
fi
popd
else
rm -fr previous/current_snapshot
fi