Make platform check before downloading restic

This commit is contained in:
deajan 2024-09-07 18:48:47 +02:00
parent 368f857723
commit cbe34c4819

View file

@ -8,38 +8,46 @@ LATEST_VERSION=$(curl -s https://api.github.com/repos/${ORG}/${REPO}/releases/la
echo Latest restic version ${LATEST_VERSION} echo Latest restic version ${LATEST_VERSION}
errors=false errors=false
for platform in "windows_386" "windows_amd64" "linux_arm" "linux_arm64" "linux_amd64" "darwin_amd64" "freebsd_amd64"; do
restic_filename="restic_${LATEST_VERSION//v}_${platform}" if [[ $(uname -s) == *"CYGWIN"* ]]; then
if [ ! -f "${restic_filename}" ]; then platforms=(windows_amd64 windows_386)
echo "Moving earlier version to archive" else
[ -d ARCHIVES ] || mkdir ARCHIVES platforms=(linux_arm linux_arm64 linux_amd64 darwin_amd64 freebsd_amd64)
mv -f restic_*_${platform} ARCHIVES/ > /dev/null 2>&1 fi
mv -f restic_*_${platform}.exe ARCHIVES/ > /dev/null 2>&1
echo "Downloading ${restic_filename}" for platform in "${platforms[@]}"; do
if [ "${platform:0:7}" == "windows" ]; then echo "Checking for ${platform}"
ext=zip restic_filename="restic_${LATEST_VERSION//v}_${platform}"
else if [ ! -f "${restic_filename}" ]; then
ext=bz2 echo "Moving earlier version to archive"
fi [ -d ARCHIVES ] || mkdir ARCHIVES
curl -OL https://github.com/restic/restic/releases/download/${LATEST_VERSION}/restic_${LATEST_VERSION//v}_{$platform}.${ext} mv -f restic_*_${platform} ARCHIVES/ > /dev/null 2>&1
if [ $? -ne 0 ]; then mv -f restic_*_${platform}.exe ARCHIVES/ > /dev/null 2>&1
echo "Failed to download ${restic_filename}" echo "Downloading ${restic_filename}"
errors=true if [ "${platform:0:7}" == "windows" ]; then
else ext=zip
if [ -f "${restic_filename}.bz2" ]; then else
bzip2 -d "${restic_filename}.bz2" && chmod +x "${restic_filename}" ext=bz2
elif [ -f "${restic_filename}.zip" ]; then fi
unzip "${restic_filename}.zip" curl -OL https://github.com/restic/restic/releases/download/${LATEST_VERSION}/restic_${LATEST_VERSION//v}_{$platform}.${ext}
else if [ $? -ne 0 ]; then
echo "Archive ${restic_filename} not found" echo "Failed to download ${restic_filename}"
errors=true errors=true
else
if [ -f "${restic_filename}.bz2" ]; then
bzip2 -d "${restic_filename}.bz2" && chmod +x "${restic_filename}"
elif [ -f "${restic_filename}.zip" ]; then
unzip "${restic_filename}.zip"
else
echo "Archive ${restic_filename} not found"
errors=true
fi
if [ $? -ne 0 ]; then
echo "Failed to decompress ${restic_filename}.bz2"
errors=true
fi fi
if [ $? -ne 0 ]; then [ -f "${restic_filename}.zip" ] && rm -f "${restic_filename}.zip"
echo "Failed to decompress ${restic_filename}.bz2" fi
errors=true
fi
[ -f "${restic_filename}.zip" ] && rm -f "${restic_filename}.zip"
fi
fi fi
done done