bin/install_module in sfpagent-0.2.3 vs bin/install_module in sfpagent-0.2.4
- old
+ new
@@ -22,20 +22,24 @@
fi
# set a template command for sending the modules
cmd="curl -s -i -X PUT $address:$port/modules"
+# setup directory for temporary files
+dir="/tmp/"$(date +%s%N)"$RANDOM"
+mkdir -p $dir
+
# for every module in the arguments:
# - archive the module's files to a temporary file
# - update the sending command by adding the module
# if the module is not exist then the program will
# set missing_module flag and then break from the loop
missing_module=0
for module in "$@" ; do
if [[ -d "$module" ]]; then
- tar cvzhf /tmp/$module.tgz $module 1>/dev/null
- cmd="$cmd -F $module=@/tmp/$module.tgz"
+ tar cvzhf $dir/$module.tgz $module 1>/dev/null
+ cmd="$cmd -F $module=@$dir/$module.tgz"
else
echo "Module $module is not exist!"
missing_module=`expr $missing_module + 1`
fi
done
@@ -47,13 +51,11 @@
if ! [[ $result =~ $re ]]; then
missing_module=`expr $missing_module + 1`
fi
fi
-# delete temporary archive files
-for module in "$@"; do
- rm -f /tmp/$module.tgz
-done
+# delete directory that holds temporary files
+rm -rf $dir
if [[ $missing_module == 0 ]]; then
echo "status: ok"
else
echo "status: failed"