#!/bin/sh

CUR_USER=`whoami`

echo "Do you want to clean up default working directories used by Microsoft R Server, including"
echo "      all files under /var/RevoShare/${CUR_USER} on this local host and"
echo "      all files under /user/RevoShare/${CUR_USER} on HDFS"
echo "This step cannot be undone. Please enter yes if you want to continue."

read input

if [ "$input" = "yes" ]; then

    rm -rf /var/RevoShare/${CUR_USER}/*

    if [ $? -ne 0 ]; then
        echo "Failed to clean up /var/RevoShare/${CUR_USER} on local host. Please contact your administrator for permission."
    fi
    
    hadoop fs -rm -r -f /user/RevoShare/${CUR_USER}/*
    
    if [ $? -ne 0 ]; then
        echo "Failed to clean up /user/RevoShare/${CUR_USER} on HDFS. Please contact your administrator for permission."
    fi
else
    echo "Invalid input $input. Abort!"
fi


