fetch-profile-code 902 Bytes
Newer Older
1 2 3 4
#!/bin/sh

BASEURL="https://www.cloudlab.us/profile-source.php"

5 6 7 8 9 10 11 12 13 14 15
if [ $# -eq 2 ]; then
    PROJECT=$1
    PROFILE=$2
elif [ $# -eq 1 ]; then
    SHORTSTRING=`echo $1 | sed s_code-samples/profile/__`
    PROJECT=`echo $SHORTSTRING | sed s_/.*__`
    PROFILE=`echo $SHORTSTRING | sed s_.*/__ | sed s_\.py__`
else
    echo "Usage: $0 <project> <profile>"
    exit 1
fi
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

URL="$BASEURL?project=$PROJECT&profile=$PROFILE"
DIR="code-samples/profile/$PROJECT"
FILE="$DIR/$PROFILE.py"
TMPFILE="$FILE.tmp"

mkdir -p $DIR
wget -q -O $TMPFILE $URL

if [ ! -f $FILE ] ; then
    echo "########## $PROJECT/$PROFILE is new!"
    mv $TMPFILE $FILE
else
    cmp -s $TMPFILE $FILE;
    if [ $? -eq 0 ] ; then
        echo "********** $PROJECT/$PROFILE is unchanged!"
        rm $TMPFILE
    else
        echo "########## $PROJECT/$PROFILE has changed!"
        diff -u $FILE $TMPFILE
        mv $TMPFILE $FILE
    fi
fi