runonce: Fix a basename oversight

This fixes an issue where we were accidentally concatenating two full absolute
paths together for storing the script content hash to disk. Additionally, this
ensures the script run status is flushed to disk after each successful run.

Change-Id: Idd1d8670dc576e3fc6a72d5b4072a981e116274c
diff --git a/usr/sbin/runonce b/usr/sbin/runonce
index bd1c0ae..2eb59b0 100755
--- a/usr/sbin/runonce
+++ b/usr/sbin/runonce
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Expansions of unset variables cause an error
+set -u
+
 # Given a script and it's content SHA-1, determine if it should run based upon
 # whether its content has changed.
 #
@@ -8,9 +11,10 @@
 function should-run-script {
     local script="$1"; shift
     local script_sha1="$1"; shift
+    local script_basename=$(basename "${script}")
     
-    if [[ -f /var/cache/runonce/$fname ]]; then
-        previous_sha1=$(cat /var/cache/runonce/$fname)
+    if [[ -f /var/cache/runonce/$script_basename ]]; then
+        previous_sha1=$(cat /var/cache/runonce/$script_basename)
 
         if [[ $script_sha1 == $previous_sha1 ]]; then
             return 1
@@ -33,8 +37,9 @@
         $script
 
         if [[ $? == 0 ]]; then
-            local fname=$(basename $script)
-            echo $script_sha1 > /var/cache/runonce/$fname
+            local script_basename=$(basename $script)
+            echo $script_sha1 > /var/cache/runonce/$script_basename
+            sync /var/cache/runonce/$script_basename
         fi
     done
 }