gh-39: use constants instead of file paths

pull/49/head
Javi Fontan 9 years ago
parent d1b3f4e9bb
commit 52580e751f

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
LOCK_FILE="/var/run/one-context.lock"
CONTEXT_FILE="/tmp/context.sh"
CONTEXT_NEW="${CONTEXT_FILE}.new"
END_CONTEXT="/tmp/context.end"
function export_rc_vars function export_rc_vars
{ {
if [ -f $1 ] ; then if [ -f $1 ] ; then
@ -41,21 +46,21 @@ function get_new_context {
if [ -e "$CONTEXT_DEV" ]; then if [ -e "$CONTEXT_DEV" ]; then
mount -t iso9660 -L CONTEXT -o ro /mnt mount -t iso9660 -L CONTEXT -o ro /mnt
if [ -f /mnt/context.sh ]; then if [ -f /mnt/context.sh ]; then
cp /mnt/context.sh /tmp/context.sh.new cp /mnt/context.sh ${CONTEXT_NEW}
fi fi
echo "umount /mnt" > /tmp/end_context echo "umount /mnt" > ${END_CONTEXT}
elif curl -o /tmp/context.sh.new http://169.254.169.254/latest/user-data ; then elif curl -o ${CONTEXT_NEW} http://169.254.169.254/latest/user-data ; then
echo -n "" echo -n ""
elif type vmtoolsd ; then elif type vmtoolsd ; then
vmtoolsd --cmd 'info-get guestinfo.opennebula.context' | \ vmtoolsd --cmd 'info-get guestinfo.opennebula.context' | \
openssl base64 -d > /tmp/context.sh.new openssl base64 -d > ${CONTEXT_NEW}
fi fi
} }
function check_context { function check_context {
if [ -s "/tmp/context.sh.new" ]; then if [ -s "${CONTEXT_NEW}" ]; then
diff /tmp/context.sh /tmp/context.sh.new && return 1 diff ${CONTEXT_FILE} ${CONTEXT_NEW} && return 1
return 0 return 0
else else
return 1 return 1
@ -63,30 +68,30 @@ function check_context {
} }
function run_context { function run_context {
cp /tmp/context.sh.new /tmp/context.sh cp ${CONTEXT_NEW} ${CONTEXT_FILE}
export_rc_vars /tmp/context.sh export_rc_vars ${CONTEXT_FILE}
execute_scripts "$1" execute_scripts "$1"
} }
function end_context { function end_context {
if [ -e "/tmp/end_context" ]; then if [ -e "${END_CONTEXT}" ]; then
sh "/tmp/end_context" sh "${END_CONTEXT}"
rm "/tmp/end_context" rm "${END_CONTEXT}"
fi fi
[ -e "/tmp/context.sh.new" ] && rm "/tmp/context.sh.new" [ -e "${CONTEXT_NEW}" ] && rm "${CONTEXT_NEW}"
} }
function adquire_lock { function adquire_lock {
while [ -e "/var/run/one-context.lock" ]; do while [ -e "${LOCK_FILE}" ]; do
sleep 1 sleep 1
done done
touch "/var/run/one-context.lock" touch "${LOCK_FILE}"
} }
function release_lock { function release_lock {
rm -f "/var/run/one-context.lock" rm -f "${LOCK_FILE}"
} }
COMMAND="$1" COMMAND="$1"

Loading…
Cancel
Save