Skip to content

Instantly share code, notes, and snippets.

@chihchun
Last active March 21, 2020 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihchun/d458c7a48cad67a9bb42faefbb09cb45 to your computer and use it in GitHub Desktop.
Save chihchun/d458c7a48cad67a9bb42faefbb09cb45 to your computer and use it in GitHub Desktop.
#!/bin/bash
# set -x
if [ -z $1 ] ; then
echo "Usage: $0 url_of_zsync"
exit -1
fi
cd $(dirname $0)
# Find the folder.
DIR=$(dirname $1 | cut -b 8-)
# Find the reference ISO image.
ISO=$(find $(dirname ${DIR}) -type f -exec stat -c '%Y %n' {} \; | sort -nr | awk 'NR==1 {print $2}')
BASENAME=$(basename $1 .zsync)
mkdir -p ${DIR}
if [ -f ${DIR}/${BASENAME} ] ; then
echo "${DIR}/${BASENAME} exist"
exit -1
fi
if [ -z ${ISO} ] ; then
zsync $1 -o ${DIR}/${BASENAME}
else
zsync $1 -i ${ISO} -o ${DIR}/${BASENAME}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment