|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
FLAG_NAME=$1 |
|
|
|
|
|
FLAG_NULL=$2 |
|
|
|
|
|
FLAG_KEY=$3 |
|
|
|
if [ -z "$FLAG_NAME" ] || [ "$FLAG_NAME" = " " ]; then |
|
FLAG_NAME="null" |
|
fi |
|
if [ -z "$FLAG_NULL" ]; then |
|
FLAG_NULL="null" |
|
fi |
|
if [ -z "$FLAG_KEY" ]; then |
|
FLAG_KEY="null" |
|
fi |
|
|
|
cd /workspace |
|
cd * |
|
|
|
R_PATH="$(pwd)" |
|
|
|
if [ ! -d "$R_PATH/SD" ]; then |
|
echo "SD folder not found." |
|
exit 101 |
|
fi |
|
|
|
MUID="" |
|
|
|
if [ -f "$R_PATH/SD/MUID.txt" ]; then |
|
MUID=$(<./SD/MUID.txt) |
|
MUID=${MUID%%+( )} |
|
MUID=${MUID%%+(\n)} |
|
|
|
|
|
else |
|
RANDOM_STR1="$(head -c 128 /dev/urandom | tr -dc 'A-Z')ZZ" |
|
RANDOM_STR2="$(head -c 384 /dev/urandom | tr -dc 'A-Z0-9')ZZZZZZZZZZZZZZ" |
|
MUID="${RANDOM_STR1::1}${RANDOM_STR2::14}${RANDOM_STR1:1:1}" |
|
echo -e "$MUID" >> ./SD/MUID.txt |
|
fi |
|
|
|
if [ ! -f "$R_PATH/SD/autoUpload_Log.txt" ]; then |
|
touch ./SD/autoUpload_Log.txt |
|
fi |
|
|
|
if [ ! -f "$R_PATH/SD/autoUpload_UploadQueueIng.txt" ]; then |
|
touch ./SD/autoUpload_UploadQueueIng.txt |
|
fi |
|
|
|
if [ ! -f "$R_PATH/SD/autoUpload_UploadQueueDone.txt" ]; then |
|
touch ./SD/autoUpload_UploadQueueDone.txt |
|
fi |
|
|
|
OUPUT_PATH="" |
|
|
|
if [ -d "$R_PATH/output" ]; then |
|
OUPUT_PATH="output" |
|
elif [ -d "$R_PATH/SD/output" ]; then |
|
OUPUT_PATH="SD/output" |
|
elif [ -d "$R_PATH/CU/output" ]; then |
|
OUPUT_PATH="CU/output" |
|
else |
|
echo "output folder not found." |
|
exit 102 |
|
fi |
|
|
|
|
|
|
|
if [ "$FLAG_KEY" = "null" ]; then |
|
|
|
apt-get install -y inotify-tools |
|
apt-get install -y zip |
|
pip3 install pcloud |
|
CURRNET_PID=$$ |
|
|
|
kill -9 $(ps -ef | grep 'autoUpload' | grep -v 'grep' | awk -v pid=$CURRNET_PID '$2 != pid {print $2}') |
|
FLAG_KEY="startDaemon" |
|
bash -c ". $R_PATH/autoUpload.sh $FLAG_NAME $FLAG_NULL $FLAG_KEY" |
|
elif [ "$FLAG_KEY" = "startDaemon" ]; then |
|
cd /workspace |
|
cd * |
|
FLAG_KEY="runningDaemon" |
|
chmod 755 autoUpload.sh |
|
nohup ./autoUpload.sh $FLAG_NAME $FLAG_NULL $FLAG_KEY 2>&1 & |
|
elif [ "$FLAG_KEY" = "runningDaemon" ]; then |
|
cd /workspace |
|
cd * |
|
while : |
|
do |
|
bash -c ". $R_PATH/out.sh 1 $FLAG_NAME" |
|
sleep 288s |
|
for item in $(find . -name "output_${FLAG_NAME}*.zip"); do |
|
rm -rf $item |
|
done |
|
sleep 10s |
|
done |
|
elif [ "$FLAG_KEY" = "clean" ]; then |
|
rm -rf "$R_PATH/SD/autoUpload_UploadQueueIng.txt" |
|
rm -rf "$R_PATH/SD/autoUpload_UploadQueueDone.txt" |
|
elif [ "$FLAG_KEY" = "kill" ]; then |
|
kill -15 $(ps -ef | grep 'autoUpload.sh' | grep -v 'grep' | awk '{print $2}') |
|
else |
|
: |
|
fi |
|
|