Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created August 21, 2017 19:58
Show Gist options
  • Save ChatchaiJ/f1c955cef0a59ca1ca93fa057412707f to your computer and use it in GitHub Desktop.
Save ChatchaiJ/f1c955cef0a59ca1ca93fa057412707f to your computer and use it in GitHub Desktop.
#!/bin/bash
CONF="${HOME}/.getcmd.conf"
[ ! -f "$CONF" ] && echo "No config file ${CONF}" && exit
source $CONF
[ -z "CMDSVR" ] && echo "CMDSVR is not defined" && exit
[ -z "CMDPATH" ] && echo "CMDPATH is not defined" && exit
[ -z "DONE" ] && echo "DONE is not defined" && exit
HOSTPATH=`hostname -f | md5sum | cut -f1 -d' '`
TOPURL="https://${CMDSVR}/${CMDPATH}/${HOSTPATH}"
CMDINDEX="$TOPURL/index.txt"
[ ! -f "$DONE" ] && touch $DONE
[ ! -w "$DONE" ] && echo "Can't log to '$DONE'." && exit
LIST=`curl --silent --fail $CMDINDEX`
for CMD in $LIST; do
ISDONE=`grep "^$CMD$" $DONE`
if [ -z "$ISDONE" ]; then
curl --silent --fail -o ${CMD} ${TOPURL}/${CMD}
[ -f "$CMD" ] && echo "$CMD" >> $DONE
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment